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/posts_from_main_page.feature b/features/posts_from_main_page.feature index fffe3073c..45cf2df2f 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 + 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 When I select only "PostingTo" aspect And I expand the publisher 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/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/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..c57b7b169 100644 --- a/features/step_definitions/posts_steps.rb +++ b/features/step_definitions/posts_steps.rb @@ -34,3 +34,16 @@ 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 + +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..94176d93d --- /dev/null +++ b/features/step_definitions/stream_steps.rb @@ -0,0 +1,11 @@ +Then /^I should see an image in the publisher$/ do + photo_in_publisher.should be_present +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 new file mode 100644 index 000000000..8441ac310 --- /dev/null +++ b/features/support/publishing_cuke_helpers.rb @@ -0,0 +1,72 @@ +module PublishingCukeHelpers + def make_post(text) + 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(); + ') + 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 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 + + 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 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(){