From a399572995e3ebeb30d9f00123cb49cf752ae483 Mon Sep 17 00:00:00 2001 From: Dennis Collinson Date: Mon, 6 Feb 2012 16:51:32 -0800 Subject: [PATCH] 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(){