From 4382d45e821814ce953b911812bd7012c4a8d74a Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Mon, 6 Feb 2012 12:25:02 -0800 Subject: [PATCH 1/3] almost failing cuke --- features/posts_from_main_page.feature | 5 ++++ features/step_definitions/factory_steps.rb | 4 +++ features/step_definitions/message_steps.rb | 18 +++++++++++++ features/step_definitions/posts_steps.rb | 12 +++++++++ features/support/publishing_cuke_helpers.rb | 29 +++++++++++++++++++++ 5 files changed, 68 insertions(+) create mode 100644 features/step_definitions/message_steps.rb create mode 100644 features/support/publishing_cuke_helpers.rb diff --git a/features/posts_from_main_page.feature b/features/posts_from_main_page.feature index fffe3073c..9b45e5aaf 100644 --- a/features/posts_from_main_page.feature +++ b/features/posts_from_main_page.feature @@ -24,6 +24,11 @@ Feature: posting from the main page And I go to the aspects page Then I should see "I am eating a yogurt" within ".stream_element" + Scenario: posting a message appends it to the top of the stream + Given I have a prexisting post + And I post "hey there" + Then I should see "hello there" as the first post in my stream + Scenario: post a text-only message to just one aspect When I select only "PostingTo" aspect And I expand the publisher diff --git a/features/step_definitions/factory_steps.rb b/features/step_definitions/factory_steps.rb index 15e406e78..91032b057 100644 --- a/features/step_definitions/factory_steps.rb +++ b/features/step_definitions/factory_steps.rb @@ -32,6 +32,10 @@ end World(FactoryMethods) +Given /I have a prexisting post/ do + Factory(:status_message, :author => @me.person, :public => true) +end + Given %r{^I have a (.+)$} do |model_name| create_from_table(model_name, {}, 'user' => @me) end diff --git a/features/step_definitions/message_steps.rb b/features/step_definitions/message_steps.rb new file mode 100644 index 000000000..ded072ac1 --- /dev/null +++ b/features/step_definitions/message_steps.rb @@ -0,0 +1,18 @@ +Then /^I should see the "(.*)" message$/ do |message| + text = case message + when "alice is excited" + @alice ||= Factory(:user, :username => "Alice") + I18n.translate('invitation_codes.excited', :name => @alice.name) + when "welcome to diaspora" + I18n.translate('users.getting_started.well_hello_there') + when 'you are safe for work' + I18n.translate('profiles.edit.you_are_safe_for_work') + when 'you are nsfw' + I18n.translate('profiles.edit.you_are_nsfw') + when 'hello' + "well hello there man" + else + raise "muriel, you don't have that message key, add one here" + end + page.should have_content(text) +end \ No newline at end of file diff --git a/features/step_definitions/posts_steps.rb b/features/step_definitions/posts_steps.rb index 2401c89d5..e454eb5e4 100644 --- a/features/step_definitions/posts_steps.rb +++ b/features/step_definitions/posts_steps.rb @@ -34,3 +34,15 @@ end When /^I click on the first block button/ do find(".block_user").click end + + + +Then /^"I should see "([^"]*)" as the first post in my stream$/ do |text| + first_post_text.should include(text) +end + +Given /^"I post "([^"]*)"$/ do |text| + make_post(text) +end + + diff --git a/features/support/publishing_cuke_helpers.rb b/features/support/publishing_cuke_helpers.rb new file mode 100644 index 000000000..4bcb3b61e --- /dev/null +++ b/features/support/publishing_cuke_helpers.rb @@ -0,0 +1,29 @@ +module PublishingCukeHelpers + def make_post(text) + click_publisher + fill_in 'status_message_fake_text', :with => text + click_button :submit + end + + def click_publisher + page.execute_script(' + $("#publisher").removeClass("closed"); + $("#publisher").find("textarea").focus(); + ') + end + + def first_post_text + find('.stream_element:first .post-content').text() + end + + def find_post_by_text(text) + find(".stream_element:contains('#{text}')") + end + + def assert_nsfw(text) + post = find_post_by_text(text) + post.find(".shield").should be_present + end +end + +World(PublishingCukeHelpers) \ No newline at end of file From 578e8ef269a2f974bc439333a4c4727574da1730 Mon Sep 17 00:00:00 2001 From: Dennis Collinson Date: Mon, 6 Feb 2012 14:55:14 -0800 Subject: [PATCH 2/3] broken --- features/posts_from_main_page.feature | 4 ++-- features/step_definitions/custom_web_steps.rb | 2 +- features/step_definitions/factory_steps.rb | 4 ---- features/step_definitions/posts_steps.rb | 11 ++++++----- features/step_definitions/stream_steps.rb | 3 +++ features/support/publishing_cuke_helpers.rb | 15 ++++++++++++--- public/javascripts/app/collections/posts.js | 5 +++++ 7 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 features/step_definitions/stream_steps.rb diff --git a/features/posts_from_main_page.feature b/features/posts_from_main_page.feature index 9b45e5aaf..45cf2df2f 100644 --- a/features/posts_from_main_page.feature +++ b/features/posts_from_main_page.feature @@ -25,8 +25,8 @@ Feature: posting from the main page Then I should see "I am eating a yogurt" within ".stream_element" Scenario: posting a message appends it to the top of the stream - Given I have a prexisting post - And I post "hey there" + When I click the publisher and post "sup dog" + And I click the publisher and post "hello there" Then I should see "hello there" as the first post in my stream Scenario: post a text-only message to just one aspect diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 8bc1cd921..950c6ca9f 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -103,7 +103,7 @@ Then /^(?:|I )should not see a "([^\"]*)"(?: within "([^\"]*)")?$/ do |selector, end When /^I wait for the ajax to finish$/ do - wait_until(15) { evaluate_script("$.active") == 0 } + wait_for_ajax_to_finish end When /^I have turned off jQuery effects$/ do diff --git a/features/step_definitions/factory_steps.rb b/features/step_definitions/factory_steps.rb index 91032b057..15e406e78 100644 --- a/features/step_definitions/factory_steps.rb +++ b/features/step_definitions/factory_steps.rb @@ -32,10 +32,6 @@ end World(FactoryMethods) -Given /I have a prexisting post/ do - Factory(:status_message, :author => @me.person, :public => true) -end - Given %r{^I have a (.+)$} do |model_name| create_from_table(model_name, {}, 'user' => @me) end diff --git a/features/step_definitions/posts_steps.rb b/features/step_definitions/posts_steps.rb index e454eb5e4..c57b7b169 100644 --- a/features/step_definitions/posts_steps.rb +++ b/features/step_definitions/posts_steps.rb @@ -36,13 +36,14 @@ When /^I click on the first block button/ do end - -Then /^"I should see "([^"]*)" as the first post in my stream$/ do |text| +Then /^I should see "([^"]*)" as the first post in my stream$/ do |text| first_post_text.should include(text) end -Given /^"I post "([^"]*)"$/ do |text| - make_post(text) +When /^I post "([^"]*)"$/ do |text| + click_and_post(text) end - +When /^I click the publisher and post "([^"]*)"$/ do |text| + click_and_post(text) +end diff --git a/features/step_definitions/stream_steps.rb b/features/step_definitions/stream_steps.rb new file mode 100644 index 000000000..795557b9a --- /dev/null +++ b/features/step_definitions/stream_steps.rb @@ -0,0 +1,3 @@ +Then /^I should see an image in the publisher$/ do + photo_in_publisher.should be_present +end \ No newline at end of file diff --git a/features/support/publishing_cuke_helpers.rb b/features/support/publishing_cuke_helpers.rb index 4bcb3b61e..d4cb597ef 100644 --- a/features/support/publishing_cuke_helpers.rb +++ b/features/support/publishing_cuke_helpers.rb @@ -1,14 +1,19 @@ module PublishingCukeHelpers def make_post(text) - click_publisher fill_in 'status_message_fake_text', :with => text click_button :submit + wait_for_ajax_to_finish + end + + def click_and_post(text) + click_publisher + make_post(text) end def click_publisher page.execute_script(' - $("#publisher").removeClass("closed"); - $("#publisher").find("textarea").focus(); + $("#publisher").removeClass("closed"); + $("#publisher").find("textarea").focus(); ') end @@ -20,6 +25,10 @@ module PublishingCukeHelpers find(".stream_element:contains('#{text}')") end + def wait_for_ajax_to_finish(wait_time=15) + wait_until(wait_time) { evaluate_script("$.active") == 0 } + end + def assert_nsfw(text) post = find_post_by_text(text) post.find(".shield").should be_present diff --git a/public/javascripts/app/collections/posts.js b/public/javascripts/app/collections/posts.js index 37fb1a206..f5899248c 100644 --- a/public/javascripts/app/collections/posts.js +++ b/public/javascripts/app/collections/posts.js @@ -9,4 +9,9 @@ app.collections.Posts = Backbone.Collection.extend({ parse: function(resp){ return resp.posts; } +// +// +// comparator : function(post) { +// return -post.createdAt(); +// } }); From a399572995e3ebeb30d9f00123cb49cf752ae483 Mon Sep 17 00:00:00 2001 From: Dennis Collinson Date: Mon, 6 Feb 2012 16:51:32 -0800 Subject: [PATCH 3/3] MS DC; fix participate stream ordering problem that was putting new posts on the bottom of things --- app/controllers/streams_controller.rb | 1 - features/participate_stream.feature | 21 +++++++++++++ features/step_definitions/comment_steps.rb | 7 ++++- features/step_definitions/stream_steps.rb | 10 +++++- features/support/publishing_cuke_helpers.rb | 34 +++++++++++++++++++++ public/javascripts/app/collections/posts.js | 5 --- public/javascripts/app/models/stream.js | 9 +++++- 7 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 features/participate_stream.feature diff --git a/app/controllers/streams_controller.rb b/app/controllers/streams_controller.rb index 73a40a751..f7f00f772 100644 --- a/app/controllers/streams_controller.rb +++ b/app/controllers/streams_controller.rb @@ -32,7 +32,6 @@ class StreamsController < ApplicationController end def participate - puts params.inspect stream_responder(Stream::Participate) end diff --git a/features/participate_stream.feature b/features/participate_stream.feature new file mode 100644 index 000000000..107984139 --- /dev/null +++ b/features/participate_stream.feature @@ -0,0 +1,21 @@ +@javascript +Feature: The participate stream + Scenario: Sorting + Given a user with username "bob" + When I sign in as "bob@bob.bob" + + And I post "A- I like turtles" + And I post "B- barack obama is your new bicycle" + And I post "C- barack obama is a square" + + When I pin the post "A- I like turtles" + And I wait for 1 second + And I comment "Sassy sawfish" on "C- barack obama is a square" + And I wait for 1 second + And I pin the post "B- barack obama is your new bicycle" + And I wait for 1 second + + When I go to the participate stream page + Then "B- barack obama is your new bicycle" should be post 1 + And "C- barack obama is a square" should be post 2 + And "A- I like turtles" should be post 3 diff --git a/features/step_definitions/comment_steps.rb b/features/step_definitions/comment_steps.rb index fc59010cd..ae7530e5b 100644 --- a/features/step_definitions/comment_steps.rb +++ b/features/step_definitions/comment_steps.rb @@ -1,5 +1,5 @@ When /^I focus the comment field$/ do - find("a.focus_comment_textarea").click + focus_comment_box end Then /^the first comment field should be open/ do @@ -9,3 +9,8 @@ end Then /^the first comment field should be closed$/ do find("#main_stream .stream_element .new_comment").should_not be_visible end + + +When /^I comment "([^"]*)" on "([^"]*)"$/ do |comment_text, post_text| + comment_on_post(post_text, comment_text) +end diff --git a/features/step_definitions/stream_steps.rb b/features/step_definitions/stream_steps.rb index 795557b9a..94176d93d 100644 --- a/features/step_definitions/stream_steps.rb +++ b/features/step_definitions/stream_steps.rb @@ -1,3 +1,11 @@ Then /^I should see an image in the publisher$/ do photo_in_publisher.should be_present -end \ No newline at end of file +end + +Then /^I pin the post "([^"]*)"$/ do |post_text| + pin_post(post_text) +end + +Then /^"([^"]*)" should be post (\d+)$/ do |post_text, position| + find(".stream_element:nth-child(#{position}) .post-content").text.should == post_text +end diff --git a/features/support/publishing_cuke_helpers.rb b/features/support/publishing_cuke_helpers.rb index d4cb597ef..8441ac310 100644 --- a/features/support/publishing_cuke_helpers.rb +++ b/features/support/publishing_cuke_helpers.rb @@ -25,6 +25,40 @@ module PublishingCukeHelpers find(".stream_element:contains('#{text}')") end + def pin_post(post_text) + within_post(post_text) do + click_link 'Pin' + end + wait_for_ajax_to_finish + end + + def within_post(post_text) + within find_post_by_text(post_text) do + yield + end + end + + def stream_posts + all('.stream_element') + end + + def comment_on_post(post_text, comment_text) + within_post(post_text) do + focus_comment_box + make_comment(comment_text) + end + wait_for_ajax_to_finish + end + + def make_comment(text) + fill_in "text", :with => text + click_button :submit + end + + def focus_comment_box + find("a.focus_comment_textarea").click + end + def wait_for_ajax_to_finish(wait_time=15) wait_until(wait_time) { evaluate_script("$.active") == 0 } end diff --git a/public/javascripts/app/collections/posts.js b/public/javascripts/app/collections/posts.js index f5899248c..37fb1a206 100644 --- a/public/javascripts/app/collections/posts.js +++ b/public/javascripts/app/collections/posts.js @@ -9,9 +9,4 @@ app.collections.Posts = Backbone.Collection.extend({ parse: function(resp){ return resp.posts; } -// -// -// comparator : function(post) { -// return -post.createdAt(); -// } }); diff --git a/public/javascripts/app/models/stream.js b/public/javascripts/app/models/stream.js index 0e70eb26b..b8f31d8f7 100644 --- a/public/javascripts/app/models/stream.js +++ b/public/javascripts/app/models/stream.js @@ -1,6 +1,13 @@ app.models.Stream = Backbone.Collection.extend({ initialize : function(){ - this.posts = new app.collections.Posts(); + this.posts = new app.collections.Posts([], this.postOptions()); + }, + + postOptions :function(){ + var order = this.sortOrder(); + return { + comparator : function(post) { return -post[order](); } + } }, url : function(){