From 2b6070d3252705692e5496f161c10ea191fa43fd Mon Sep 17 00:00:00 2001 From: Michael Nutt Date: Sun, 6 Mar 2011 22:41:21 -0500 Subject: [PATCH] features for comments --- features/comments.feature | 48 +++++++++++++++++++ features/step_definitions/comment_steps.rb | 3 ++ features/step_definitions/custom_web_steps.rb | 22 +++++++-- features/step_definitions/posts_steps.rb | 1 + features/step_definitions/user_steps.rb | 33 +++++++++++-- features/support/paths.rb | 2 + 6 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 features/comments.feature create mode 100644 features/step_definitions/comment_steps.rb diff --git a/features/comments.feature b/features/comments.feature new file mode 100644 index 000000000..cd0f40bf1 --- /dev/null +++ b/features/comments.feature @@ -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" diff --git a/features/step_definitions/comment_steps.rb b/features/step_definitions/comment_steps.rb new file mode 100644 index 000000000..05727152a --- /dev/null +++ b/features/step_definitions/comment_steps.rb @@ -0,0 +1,3 @@ +When /^I focus the comment field$/ do + find("a.focus_comment_textarea").click +end diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 4d41b52c5..f86a1d29f 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -45,12 +45,12 @@ When /^I press the first "([^"]*)"(?: within "([^"]*)")?$/ do |link_selector, wi 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 find(:css, link_selector+":nth-child(#{number})").click 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 page.has_css?(selector).should be_true end @@ -69,9 +69,25 @@ When /^I have turned off jQuery effects$/ do evaluate_script("$.fx.off = true") 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 evaluate_script <<-JS - window.confirm = function() { return true; }; + window.confirm = function() { return true; }; JS end diff --git a/features/step_definitions/posts_steps.rb b/features/step_definitions/posts_steps.rb index 2e10a5552..4036f7524 100644 --- a/features/step_definitions/posts_steps.rb +++ b/features/step_definitions/posts_steps.rb @@ -1,3 +1,4 @@ When /^I click share across aspects$/ do find("#expand_publisher").click end + diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 04a82a811..7c92b9797 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -11,7 +11,17 @@ end Given /^a user with email "([^\"]*)"$/ do |email| user = Factory(:user, :email => email, :password => 'password', - :password_confirmation => 'password', :getting_started => false) + :password_confirmation => 'password', :getting_started => false) + user.aspects.create(:name => "Besties") + user.aspects.create(:name => "Unicorns") +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 @@ -30,7 +40,7 @@ When /^I click on my name$/ do click_link("#{@me.first_name} #{@me.last_name}") 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.reload end @@ -52,21 +62,21 @@ Then /^I should see (\d+) contact request(?:s)?$/ do |request_count| 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) number_of_contacts = evaluate_script( "$('ul.dropzone.ui-droppable[data-aspect_id=\"#{aspect.id}\"]').children('li.person').length") number_of_contacts.should == contact_count.to_i 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) number_of_contacts = evaluate_script( "$('ul.dropzone.ui-droppable[data-aspect_id=\"#{aspect.id}\"]').children('li.person').length") number_of_contacts.should == 0 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" aspect = @me.reload.aspects.find_by_name(aspect_name) 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) 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 diff --git a/features/support/paths.rb b/features/support/paths.rb index d36004a33..b458d4e66 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -23,6 +23,8 @@ module NavigationHelpers person_path(User.find_by_email($1).person) when /^my account settings page$/ edit_user_path(@me) + when /^the photo page for "([^\"]*)"'s post "([^\"]*)"$/ + photo_path(User.find_by_email($1).posts.find_by_message($2)) when /^"(\/.*)"/ $1 else