From 79d53f2f599b2cb9e5b97a710eda94bbe03e8fec Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sat, 5 Mar 2016 20:33:22 +0100 Subject: [PATCH 1/2] Refactor invitation cukes --- features/desktop/accepts_invitation.feature | 45 ------------------ features/desktop/invitations.feature | 51 +++++++++++++++++++-- features/mobile/invitations.feature | 9 +++- features/step_definitions/user_steps.rb | 16 ++----- 4 files changed, 58 insertions(+), 63 deletions(-) delete mode 100644 features/desktop/accepts_invitation.feature diff --git a/features/desktop/accepts_invitation.feature b/features/desktop/accepts_invitation.feature deleted file mode 100644 index a4fb95108..000000000 --- a/features/desktop/accepts_invitation.feature +++ /dev/null @@ -1,45 +0,0 @@ -@javascript -Feature: invitation acceptance - Scenario: accept invitation from admin - Given I have been invited by an admin - And I am on my acceptance form page - And I fill in the new user form - And I press "Sign up" - Then I should be on the getting started page - And I should see "Well, hello there!" - And I fill in the following: - | profile_first_name | O | - - And I follow "awesome_button" - And I confirm the alert - Then I should be on the stream page - And I close the publisher - - Scenario: accept invitation from user - Given I have been invited by bob - And I am on my acceptance form page - And I fill in the new user form - And I press "Sign up" - Then I should be on the getting started page - And I should see "Well, hello there!" - And I fill in the following: - | profile_first_name | O | - - And I follow "awesome_button" - And I confirm the alert - Then I should be on the stream page - And I close the publisher - And I log out - And I sign in as "bob@bob.bob" - And I click on selector "#invitations-button" - Then I should see one less invite - - Scenario: sends an invitation - Given a user with email "bob@bob.bob" - When I sign in as "bob@bob.bob" - And I click on selector "#invitations-button" - And I fill in the following: - | email_inviter_emails | alex@example.com | - And I press "Send an invitation" - Then I should have 1 Devise email delivery - And I should not see "change your notification settings" in the last sent email diff --git a/features/desktop/invitations.feature b/features/desktop/invitations.feature index e1d857d79..74ce102fc 100644 --- a/features/desktop/invitations.feature +++ b/features/desktop/invitations.feature @@ -1,9 +1,50 @@ @javascript Feature: Invitations + Background: + Given following users exist: + | username | email | + | Alice Smith | alice@alice.alice | - Scenario: Accepting an invitation - When I visit alice's invitation code url - When I fill in the new user form + Scenario: accept invitation from admin + Given I have been invited by an admin + And I am on my acceptance form page + And I fill in the new user form And I press "Sign up" - Then I should see the "welcome to diaspora" message - And I should be able to friend Alice + Then I should be on the getting started page + And I should see "Well, hello there!" + And I fill in the following: + | profile_first_name | O | + + And I follow "awesome_button" + And I confirm the alert + Then I should be on the stream page + And I close the publisher + + Scenario: accept invitation from user + Given I have been invited by "alice@alice.alice" + And I am on my acceptance form page + And I fill in the new user form + And I press "Sign up" + Then I should be on the getting started page + And I should see "Well, hello there!" + And I should be able to friend "alice@alice.alice" + And I fill in the following: + | profile_first_name | O | + + And I follow "awesome_button" + And I confirm the alert + Then I should be on the stream page + And I close the publisher + And I log out + And I sign in as "alice@alice.alice" + And I click on selector "#invitations-button" + Then I should see one less invite + + Scenario: sends an invitation + When I sign in as "alice@alice.alice" + And I click on selector "#invitations-button" + And I fill in the following: + | email_inviter_emails | alex@example.com | + And I press "Send an invitation" + Then I should have 1 Devise email delivery + And I should not see "change your notification settings" in the last sent email diff --git a/features/mobile/invitations.feature b/features/mobile/invitations.feature index a81c19eaf..2291d7fea 100644 --- a/features/mobile/invitations.feature +++ b/features/mobile/invitations.feature @@ -1,9 +1,14 @@ @javascript @mobile Feature: Invitations + Background: + Given following users exist: + | username | email | + | Alice Smith | alice@alice.alice | Scenario: Accepting an invitation - When I visit alice's invitation code url + Given I have been invited by "alice@alice.alice" + And I am on my acceptance form page When I fill in the new user form And I press "Create my account!" Then I should see the "welcome to diaspora" message - And I should be able to friend Alice + And I should be able to friend "alice@alice.alice" diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 7442c926e..e2d5ee9cb 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -46,8 +46,8 @@ Given /^I have been invited by an admin$/ do i.send! end -Given /^I have been invited by bob$/ do - @inviter = FactoryGirl.create(:user, :email => 'bob@bob.bob') +Given /^I have been invited by "([^\"]+)"$/ do |email| + @inviter = User.find_by_email(email) @inviter_invite_count = @inviter.invitation_code.count i = EmailInviter.new("new_invitee@example.com", @inviter) i.send! @@ -200,20 +200,14 @@ When /^I view "([^\"]*)"'s first post$/ do |email| visit post_path(post) end -Given /^I visit alice's invitation code url$/ do - @alice ||= FactoryGirl.create(:user, :username => 'alice', :getting_started => false) - invite_code = InvitationCode.find_or_create_by(user_id: @alice.id) - visit invite_code_path(invite_code) -end - When /^I fill in the new user form/ do fill_in_new_user_form end -And /^I should be able to friend Alice$/ do - alice = User.find_by_username 'alice' +And /^I should be able to friend "([^\"]*)"$/ do |email| + user = User.find_by_email(email) step 'I should see "Add contact"' - step "I should see \"#{alice.name}\"" + step "I should see \"#{user.name}\"" end When /^I click the sign in button$/ do From e4f8023b91ce584b9697de110f496e786d29737d Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sat, 5 Mar 2016 20:34:40 +0100 Subject: [PATCH 2/2] Add rspec test for public stream --- features/desktop/public_stream.feature | 22 +++------------------- spec/lib/diaspora/shareable_spec.rb | 21 +++++++++++++++++++++ spec/lib/stream/public_spec.rb | 7 +++++++ 3 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 spec/lib/diaspora/shareable_spec.rb diff --git a/features/desktop/public_stream.feature b/features/desktop/public_stream.feature index 7d9c27f5d..02449b93c 100644 --- a/features/desktop/public_stream.feature +++ b/features/desktop/public_stream.feature @@ -5,26 +5,10 @@ Feature: The public stream | username | email | | Alice Smith | alice@alice.alice | | Bob Jones | bob@bob.bob | - | Eve Doe | eve@eve.eve | - And a user with email "alice@alice.alice" is connected with "bob@bob.bob" + And "bob@bob.bob" has a public post with text "Bob’s public post" - And "bob@bob.bob" has a non public post with text "Bob’s private post" - And "eve@eve.eve" has a public post with text "Eve’s public post" - - Scenario: seeing public posts of someone you don't follow - When I sign in as "alice@alice.alice" - Then I should not see "Eve’s public post" - When I am on the public stream page - Then I should see "Eve’s public post" - Scenario: seeing public posts of someone you follow + Scenario: seeing public posts When I sign in as "alice@alice.alice" + And I am on the public stream page Then I should see "Bob’s public post" - When I am on the public stream page - Then I should see "Bob’s public post" - - Scenario: not seeing private posts of someone you follow - When I sign in as "alice@alice.alice" - Then I should see "Bob’s private post" - When I am on the public stream page - Then I should not see "Bob’s private post" diff --git a/spec/lib/diaspora/shareable_spec.rb b/spec/lib/diaspora/shareable_spec.rb new file mode 100644 index 000000000..da3916524 --- /dev/null +++ b/spec/lib/diaspora/shareable_spec.rb @@ -0,0 +1,21 @@ +require "spec_helper" + +describe Diaspora::Shareable do + describe "scopes" do + describe ".all_public" do + it "includes all public posts" do + post1 = FactoryGirl.create(:status_message, author: alice.person, public: true) + post2 = FactoryGirl.create(:status_message, author: bob.person, public: true) + post3 = FactoryGirl.create(:status_message, author: eve.person, public: true) + expect(Post.all_public.map(&:id)).to eq([post1.id, post2.id, post3.id]) + end + + it "doesn't include any private posts" do + FactoryGirl.create(:status_message, author: alice.person, public: false) + FactoryGirl.create(:status_message, author: bob.person, public: false) + FactoryGirl.create(:status_message, author: eve.person, public: false) + expect(Post.all_public.map(&:id)).to eq([]) + end + end + end +end diff --git a/spec/lib/stream/public_spec.rb b/spec/lib/stream/public_spec.rb index 976a9439b..a17348cef 100644 --- a/spec/lib/stream/public_spec.rb +++ b/spec/lib/stream/public_spec.rb @@ -9,4 +9,11 @@ describe Stream::Public do describe 'shared behaviors' do it_should_behave_like 'it is a stream' end + + describe "#posts" do + it "calls Post#all_public" do + expect(Post).to receive(:all_public) + @stream.posts + end + end end