Convert some reshare-related Cucumber features into specs. Introduce SpecDoc.
This commit is contained in:
parent
efdf597c0d
commit
0a1e649b2b
4 changed files with 146 additions and 55 deletions
|
|
@ -9,59 +9,10 @@ Feature: public repost
|
||||||
And a user named "Alice Smith" with email "alice@alice.alice"
|
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"
|
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
|
Scenario: I don't see the reshare button on other people's private 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
|
|
||||||
Given "bob@bob.bob" has a non public post with text "don't reshare this."
|
Given "bob@bob.bob" has a non public post with text "don't reshare this."
|
||||||
And I sign in as "alice@alice.alice"
|
And I sign in as "alice@alice.alice"
|
||||||
Then I should not see "Reshare"
|
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"
|
|
||||||
|
|
||||||
Scenario: When I reshare, it shows up on my profile page
|
Scenario: When I reshare, it shows up on my profile page
|
||||||
Given "bob@bob.bob" has a public post with text "reshare this!"
|
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
|
And I wait for 2 seconds
|
||||||
|
|
||||||
When I am on "alice@alice.alice"'s page
|
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"
|
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
|
Scenario: When I reshare, it shows up in my stream
|
||||||
Given "bob@bob.bob" has a public post with text "reshare this!"
|
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 "reshare this!"
|
||||||
And I should see "Bob"
|
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!"
|
Given "bob@bob.bob" has a public post with text "reshare this!"
|
||||||
And I sign in as "alice@alice.alice"
|
And I sign in as "alice@alice.alice"
|
||||||
And I preemptively confirm the alert
|
And I preemptively confirm the alert
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ describe PostsController do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
get :show, "id" => @message.id
|
get :show, "id" => @message.id
|
||||||
response.should be_success
|
response.should be_success
|
||||||
|
doc.should have_link('Like')
|
||||||
|
doc.should have_link('Comment')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'succeeds on mobile' do
|
it 'succeeds on mobile' do
|
||||||
|
|
@ -30,7 +32,6 @@ describe PostsController do
|
||||||
response.should be_success
|
response.should be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
it 'succeeds on mobile with a reshare' do
|
it 'succeeds on mobile with a reshare' do
|
||||||
get :show, "id" => Factory(:reshare, :author => alice.person).id, :format => :mobile
|
get :show, "id" => Factory(:reshare, :author => alice.person).id, :format => :mobile
|
||||||
response.should be_success
|
response.should be_success
|
||||||
|
|
@ -133,6 +134,120 @@ describe PostsController do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '#destroy' do
|
describe '#destroy' do
|
||||||
|
|
|
||||||
24
spec/spec-doc.rb
Normal file
24
spec/spec-doc.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
ENV["RAILS_ENV"] ||= 'test'
|
ENV["RAILS_ENV"] ||= 'test'
|
||||||
require File.join(File.dirname(__FILE__), '..', 'config', 'environment') unless defined?(Rails)
|
require File.join(File.dirname(__FILE__), '..', 'config', 'environment') unless defined?(Rails)
|
||||||
require 'helper_methods'
|
require 'helper_methods'
|
||||||
|
require 'spec-doc'
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
require 'webmock/rspec'
|
require 'webmock/rspec'
|
||||||
require 'factory_girl'
|
require 'factory_girl'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue