features for comments

This commit is contained in:
Michael Nutt 2011-03-06 22:41:21 -05:00
parent 8837632dd9
commit 2b6070d325
6 changed files with 101 additions and 8 deletions

48
features/comments.feature Normal file
View file

@ -0,0 +1,48 @@
@javascript
Feature: commenting
In order to tell alice how great the picture of her dog is
As alice's friend
I want to comment on her post
Background:
Given a user named "Bob Jones" with email "bob@bob.bob"
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"
When I sign in as "alice@alice.alice"
And I am on the home page
And I expand the publisher
And I fill in "status_message_fake_message" with "Look at this dog"
And I attach the file "spec/fixtures/button.png" to hidden element "file" within "#file-upload"
And I press "Share"
And I follow "Home"
Then I should see "Look at this dog" within ".stream_element"
Then I should see a "img" within ".stream_element div.photo_attachments"
And I log out
Scenario: comment on a post from within a user's stream
When I sign in as "bob@bob.bob"
And I am on "alice@alice.alice"'s page
Then I should see "Look at this dog"
When I focus the comment field
And I fill in "Comment" with "is that a poodle?"
And I press "Comment"
Then I should see "is that a poodle?" within "li.comment div.content"
And I should see "less than a minute ago" within "li.comment span.time"
Scenario: comment on a photo from the photo page
When I sign in as "bob@bob.bob"
And I am on the photo page for "alice@alice.alice"'s post "Look at this dog"
And I focus the comment field
And I fill in "Comment" with "hahahah"
And I press "Comment"
Then I should see "hahaha" within "li.comment div.content"
And I should see "less than a minute ago" within "li.comment span.time"
Scenario: comment on your own photo from the photo page
When I sign in as "alice@alice.alice"
And I am on the photo page for "alice@alice.alice"'s post "Look at this dog"
And I focus the comment field
And I fill in "Comment" with "hahahah"
And I press "Comment"
Then I should see "hahaha" within "li.comment div.content"
And I should see "less than a minute ago" within "li.comment span.time"

View file

@ -0,0 +1,3 @@
When /^I focus the comment field$/ do
find("a.focus_comment_textarea").click
end

View file

@ -45,12 +45,12 @@ When /^I press the first "([^"]*)"(?: within "([^"]*)")?$/ do |link_selector, wi
end end
end end
When /^I press the ([\d])(nd|rd|st|th) "([^"]*)"(?: within "([^"]*)")?$/ do |number,rd, link_selector, within_selector| When /^I press the ([\d])(nd|rd|st|th) "([^\"]*)"(?: within "([^\"]*)")?$/ do |number,rd, link_selector, within_selector|
with_scope(within_selector) do with_scope(within_selector) do
find(:css, link_selector+":nth-child(#{number})").click find(:css, link_selector+":nth-child(#{number})").click
end end
end end
Then /^(?:|I )should see a "([^"]*)"(?: within "([^"]*)")?$/ do |selector, scope_selector| Then /^(?:|I )should see a "([^\"]*)"(?: within "([^\"]*)")?$/ do |selector, scope_selector|
with_scope(scope_selector) do with_scope(scope_selector) do
page.has_css?(selector).should be_true page.has_css?(selector).should be_true
end end
@ -69,6 +69,22 @@ When /^I have turned off jQuery effects$/ do
evaluate_script("$.fx.off = true") evaluate_script("$.fx.off = true")
end end
When /^I attach the file "([^\"]*)" to hidden element "([^\"]*)"(?: within "([^\"]*)")?$/ do |path, field, selector|
page.execute_script <<-JS
$("#{selector || 'body'}").find("input[name=#{field}]").css({opacity: 1});
JS
if selector
When "I attach the file \"#{Rails.root.join(path).to_s}\" to \"#{field}\" within \"#{selector}\""
else
When "I attach the file \"#{Rails.root.join(path).to_s}\" to \"#{field}\""
end
page.execute_script <<-JS
$("#{selector || 'body'}").find("input[name=#{field}]").css({opacity: 0});
JS
end
When /^I click ok in the confirm dialog to appear next$/ do When /^I click ok in the confirm dialog to appear next$/ do
evaluate_script <<-JS evaluate_script <<-JS
window.confirm = function() { return true; }; window.confirm = function() { return true; };

View file

@ -1,3 +1,4 @@
When /^I click share across aspects$/ do When /^I click share across aspects$/ do
find("#expand_publisher").click find("#expand_publisher").click
end end

View file

@ -16,6 +16,16 @@ Given /^a user with email "([^\"]*)"$/ do |email|
user.aspects.create(:name => "Unicorns") user.aspects.create(:name => "Unicorns")
end end
Given /^a user named "([^\"]*)" with email "([^\"]*)"$/ do |name, email|
first, last = name.split
username = "#{first}_#{last}" if first
user = Factory(:user, :email => email, :password => 'password', :username => "#{first}_#{last}",
:password_confirmation => 'password', :getting_started => false)
user.profile.update_attributes(:first_name => first, :last_name => last) if first
user.aspects.create(:name => "Besties")
user.aspects.create(:name => "Unicorns")
end
Given /^I have been invited by an admin$/ do Given /^I have been invited by an admin$/ do
@me = Invitation.create_invitee(:service => 'email', :identifier => "new_invitee@example.com") @me = Invitation.create_invitee(:service => 'email', :identifier => "new_invitee@example.com")
end end
@ -30,7 +40,7 @@ When /^I click on my name$/ do
click_link("#{@me.first_name} #{@me.last_name}") click_link("#{@me.first_name} #{@me.last_name}")
end end
Given /^I have an aspect called "([^"]*)"$/ do |aspect_name| Given /^I have an aspect called "([^\"]*)"$/ do |aspect_name|
@me.aspects.create!(:name => aspect_name) @me.aspects.create!(:name => aspect_name)
@me.reload @me.reload
end end
@ -52,21 +62,21 @@ Then /^I should see (\d+) contact request(?:s)?$/ do |request_count|
end end
end end
Then /^I should see (\d+) contact(?:s)? in "([^"]*)"$/ do |contact_count, aspect_name| Then /^I should see (\d+) contact(?:s)? in "([^\"]*)"$/ do |contact_count, aspect_name|
aspect = @me.reload.aspects.find_by_name(aspect_name) aspect = @me.reload.aspects.find_by_name(aspect_name)
number_of_contacts = evaluate_script( number_of_contacts = evaluate_script(
"$('ul.dropzone.ui-droppable[data-aspect_id=\"#{aspect.id}\"]').children('li.person').length") "$('ul.dropzone.ui-droppable[data-aspect_id=\"#{aspect.id}\"]').children('li.person').length")
number_of_contacts.should == contact_count.to_i number_of_contacts.should == contact_count.to_i
end end
Then /^I should see no contact(?:s)? in "([^"]*)"$/ do |aspect_name| Then /^I should see no contact(?:s)? in "([^\"]*)"$/ do |aspect_name|
aspect = @me.reload.aspects.find_by_name(aspect_name) aspect = @me.reload.aspects.find_by_name(aspect_name)
number_of_contacts = evaluate_script( number_of_contacts = evaluate_script(
"$('ul.dropzone.ui-droppable[data-aspect_id=\"#{aspect.id}\"]').children('li.person').length") "$('ul.dropzone.ui-droppable[data-aspect_id=\"#{aspect.id}\"]').children('li.person').length")
number_of_contacts.should == 0 number_of_contacts.should == 0
end end
When /^I drag the contact request to the "([^"]*)" aspect$/ do |aspect_name| When /^I drag the contact request to the "([^\"]*)" aspect$/ do |aspect_name|
Given "I have turned off jQuery effects" Given "I have turned off jQuery effects"
aspect = @me.reload.aspects.find_by_name(aspect_name) aspect = @me.reload.aspects.find_by_name(aspect_name)
aspect_div = find("ul.dropzone[data-aspect_id='#{aspect.id}']") aspect_div = find("ul.dropzone[data-aspect_id='#{aspect.id}']")
@ -105,4 +115,17 @@ Given /^a user with email "([^"]*)" is connected with "([^"]*)"$/ do |arg1, arg2
connect_users(user1, user1.aspects.first, user2, user2.aspects.first) connect_users(user1, user1.aspects.first, user2, user2.aspects.first)
end end
Given /^a user with email "([^\"]*)" has posted a status message "([^\"]*)" in all aspects$/ do |arg1, arg2|
user = User.where(:email => arg1).first
status_message = user.build_post(:status_message, :message => arg2)
def status_message.socket_to_user(a1, a2); end
user.add_to_streams(status_message, user.aspects)
status_message.save!
bob = User.where(:email => "bob@bob.bob").first
raise bob.visible_posts.inspect
end
When /^I log out$/ do
When "I click on my name in the header"
When "I follow \"logout\""
end

View file

@ -23,6 +23,8 @@ module NavigationHelpers
person_path(User.find_by_email($1).person) person_path(User.find_by_email($1).person)
when /^my account settings page$/ when /^my account settings page$/
edit_user_path(@me) edit_user_path(@me)
when /^the photo page for "([^\"]*)"'s post "([^\"]*)"$/
photo_path(User.find_by_email($1).posts.find_by_message($2))
when /^"(\/.*)"/ when /^"(\/.*)"/
$1 $1
else else