diff --git a/features/reshare.feature b/features/reshare.feature index 5f709c5a1435f1f03f5ebf5558be2aed9e996d8e..7b606be8c7303053bfe69355cae2161c21132f0f 100644 --- a/features/reshare.feature +++ b/features/reshare.feature @@ -9,59 +9,10 @@ Feature: public repost And a user named "Alice Smith" with email "alice@alice.alice" And a user with email "bob@bob.bob" is connected with "alice@alice.alice" - Scenario: I don't see the reshare button on my own posts - Given "bob@bob.bob" has a public post with text "reshare this!" - And "bob@bob.bob" has a non public post with text "but don't reshare this." - And I sign in as "bob@bob.bob" - Then I should not see "Reshare" - - Scenario: I don't see the reshare button on other people's private pots + Scenario: I don't see the reshare button on other people's private posts Given "bob@bob.bob" has a non public post with text "don't reshare this." And I sign in as "alice@alice.alice" - Then I should not see "Reshare" - - Scenario: I see the reshare button on my contact's public posts - Given "bob@bob.bob" has a public post with text "reshare this!" - And I sign in as "alice@alice.alice" - Then I should see "Reshare" - - Scenario: I don't see the reshare button on other people's reshare of my post - Given "bob@bob.bob" has a public post with text "reshare this!" - And I sign in as "alice@alice.alice" - And I preemptively confirm the alert - And I follow "Reshare" - And I wait for the ajax to finish - - And I go to the home page - Then I should see a ".reshare" - And I should see "reshare this!" - And I should see "Bob" - - When I go to the destroy user session page - And I sign in as "bob@bob.bob" - - # NOTE(why do we need this to make this work?) - And I wait for 2 seconds - And I go to the home page - - Then I should see "reshare this!" - And I should not see "Reshare original" - - Scenario: I don't see the reshare button on my reshare post - Given "bob@bob.bob" has a public post with text "reshare this!" - And I sign in as "alice@alice.alice" - And I preemptively confirm the alert - And I follow "Reshare" - And I wait for the ajax to finish - - # NOTE(why do we need this to make this work?) - And I wait for 2 seconds - And I go to the home page - - Then I should see a ".reshare" - And I should see "reshare this!" - And I should see "Bob" - And I should not see "Reshare original" + Then I should not see "Reshare" Scenario: When I reshare, it shows up on my profile page Given "bob@bob.bob" has a public post with text "reshare this!" @@ -73,9 +24,9 @@ Feature: public repost And I wait for 2 seconds When I am on "alice@alice.alice"'s page - Then I should see "reshare this!" + Then I should see "reshare this!" Then I should see a ".reshare" - And I should see "Bob" + And I should see "Bob" Scenario: When I reshare, it shows up in my stream Given "bob@bob.bob" has a public post with text "reshare this!" @@ -93,7 +44,7 @@ Feature: public repost And I should see "reshare this!" And I should see "Bob" - Scenario: I can delete a post that has been reshared + Scenario: I can delete a post that has been reshared Given "bob@bob.bob" has a public post with text "reshare this!" And I sign in as "alice@alice.alice" And I preemptively confirm the alert diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 1db8282e88d3d86a9fdc3e4cb1415188229b7a27..b5b9de19e835cf0032998dc79cd37c61b9a304a0 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -23,6 +23,8 @@ describe PostsController do it 'succeeds' do get :show, "id" => @message.id response.should be_success + doc.should have_link('Like') + doc.should have_link('Comment') end it 'succeeds on mobile' do @@ -30,7 +32,6 @@ describe PostsController do response.should be_success end - it 'succeeds on mobile with a reshare' do get :show, "id" => Factory(:reshare, :author => alice.person).id, :format => :mobile response.should be_success @@ -133,6 +134,120 @@ describe PostsController do end end end + + context 'when a post is public' do + before do + @post = alice.post( :status_message, :public => true, :to => alice.aspects, :text => 'abc 123' ) + end + + context 'and visitor is not signed in' do + it 'does not show social links' do + get :show, 'id' => @post.id + + doc.should have_content('abc 123') + doc.should_not have_link('Like') + doc.should_not have_link('Comment') + doc.should_not have_link('Reshare') + end + end + + context 'and signed in as poster' do + before do + sign_in alice + end + + it 'does not show a reshare link' do + get :show, 'id' => @post.id + + doc.should have_content('abc 123') + doc.should have_link('Like') + doc.should have_link('Comment') + doc.should_not have_link('Reshare') + end + + context 'a reshare of the post' do + before do + @reshare = bob.post( :reshare, :public => true, :root_guid => @post.guid, :to => bob.aspects ) + end + + it 'does not show a reshare link' do + get :show, 'id' => @reshare.id + + doc.should have_content('abc 123') + doc.should have_link('Like') + doc.should have_link('Comment') + doc.should_not have_link('Reshare') + doc.should_not have_link('Reshare original') + doc.should_not have_link('1 reshare') + end + end + end + + context 'and signed in as someone other than the poster' do + before do + sign_in bob + end + + it 'shows reshare link' do + get :show, 'id' => @post.id + + doc.should have_content('abc 123') + doc.should have_link('Like') + doc.should have_link('Comment') + doc.should have_link('Reshare') + end + end + + context 'and signed in as the resharer of the post' do + context 'a reshare of the post' do + before do + @reshare = bob.post( :reshare, :public => true, :root_guid => @post.guid, :to => bob.aspects ) + # Don't know why this is needed, but this spec fails without it + sign_in bob + end + + it 'does not show any reshare link' do + get :show, 'id' => @reshare.id + + doc.should have_content('abc 123') + doc.should have_link('Like') + doc.should have_link('Comment') + doc.should_not have_link('1 reshare') + doc.should_not have_link('Reshare') + end + end + end + + context 'and signed in as neither the poster nor the resharer of the post' do + before do + sign_in eve + end + + it 'shows reshare link' do + get :show, 'id' => @post.id + + doc.should have_content('abc 123') + doc.should have_link('Like') + doc.should have_link('Comment') + doc.should have_link('Reshare') + end + + context 'a reshare of the post' do + before do + @reshare = bob.post( :reshare, :public => true, :root_guid => @post.guid, :to => bob.aspects ) + end + + it 'shows a reshare link' do + get :show, 'id' => @reshare.id + + doc.should have_content('abc 123') + doc.should have_link('Like') + doc.should have_link('Comment') + doc.should have_link('Reshare original') + end + end + end + end end describe '#destroy' do diff --git a/spec/spec-doc.rb b/spec/spec-doc.rb new file mode 100644 index 0000000000000000000000000000000000000000..2ec9ee5df1eed77fcf98bf6ba454650864d8cf76 --- /dev/null +++ b/spec/spec-doc.rb @@ -0,0 +1,24 @@ +class SpecDoc + def initialize(response) + @html = Nokogiri::HTML(response.body) + end + + def method_missing(method, *args) + @html.send method, *args + end + + def has_content?(string) + @html.xpath("//*[contains(text(), '#{string}')]").any? + end + def has_no_content?(string) + ! has_content?(string) + end + + def has_link?(text) + @html.xpath("//a[text()='#{text}']").any? + end +end + +def doc + SpecDoc.new response +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 61bf200a8a1242a581381e929ac7ce3d7a91c157..fb133f107a984b424a15c1fa984d7f6f748403af 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,7 @@ ENV["RAILS_ENV"] ||= 'test' require File.join(File.dirname(__FILE__), '..', 'config', 'environment') unless defined?(Rails) require 'helper_methods' +require 'spec-doc' require 'rspec/rails' require 'webmock/rspec' require 'factory_girl'