From 5fb328864e09e10b5216f443adc8a79dbc523455 Mon Sep 17 00:00:00 2001 From: Asphyxia <dario.cavuotti@gmail.com> Date: Sun, 27 Jan 2013 00:19:27 -0300 Subject: [PATCH] Activity stream keeping retracted participations --- app/models/comment.rb | 1 + app/models/like.rb | 1 + features/activity_stream.feature | 108 ++++++++++++++++++++ features/step_definitions/stream_steps.rb | 8 ++ features/support/publishing_cuke_helpers.rb | 6 ++ 5 files changed, 124 insertions(+) create mode 100644 features/activity_stream.feature diff --git a/app/models/comment.rb b/app/models/comment.rb index aa86daedb9..3eca8287d5 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -22,6 +22,7 @@ class Comment < ActiveRecord::Base belongs_to :commentable, :touch => true, :polymorphic => true alias_attribute :post, :commentable belongs_to :author, :class_name => 'Person' + has_one :participation, :dependent => :destroy, :foreign_key => :target_id, :primary_key => :commentable_id delegate :name, to: :author, prefix: true delegate :comment_email_subject, to: :parent diff --git a/app/models/like.rb b/app/models/like.rb index 530fa2aa50..99061ba3fa 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -12,6 +12,7 @@ class Like < Federated::Relayable {:target => @target, :positive => true} end end + has_one :participation, :dependent => :destroy, :foreign_key => :target_id, :primary_key => :target_id after_commit :on => :create do self.parent.update_likes_counter diff --git a/features/activity_stream.feature b/features/activity_stream.feature new file mode 100644 index 0000000000..345cee9e76 --- /dev/null +++ b/features/activity_stream.feature @@ -0,0 +1,108 @@ +@javascript +Feature: The activity stream + Background: + Given following users exist: + | username | email | + | Bob Jones | bob@bob.bob | + | Alice Smith | alice@alice.alice | + And a user with email "bob@bob.bob" is connected with "alice@alice.alice" + When "alice@alice.alice" has posted a status message with a photo + + Scenario: Sorting + When I sign in as "bob@bob.bob" + + And I post "A- I like turtles" + And I wait for 1 second + And I post "B- barack obama is your new bicycle" + And I wait for 1 second + And I post "C- barack obama is a square" + And I wait for 1 second + + When I go to the activity stream page + Then "C- barack obama is a square" should be post 1 + And "B- barack obama is your new bicycle" should be post 2 + And "A- I like turtles" should be post 3 + + When I like 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 like the post "B- barack obama is your new bicycle" + And I wait for 1 second + + When I go to the activity 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 + + Scenario: delete a comment + 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 the following: + | text | is that a poodle? | + And I press "Comment" + And I wait for the ajax to finish + + When I go to the activity stream page + Then I should see "Look at this dog" + And I should see "is that a poodle?" + + When I am on "alice@alice.alice"'s page + And I hover over the ".comment" + And I preemptively confirm the alert + And I click to delete the first comment + And I wait for the ajax to finish + + And I go to the activity stream page + Then I should not see "Look at this dog" + + Scenario: unliking a post + 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 like the post "Look at this dog" + And I go to the activity stream page + Then I should see "Look at this dog" + + When I am on "alice@alice.alice"'s page + And I unlike the post "Look at this dog" + And I go to the activity stream page + Then I should not see "Look at this dog" + + Scenario: multiple participations + 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 like the post "Look at this dog" + And I go to the activity stream page + Then I should see "Look at this dog" + + When 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 the following: + | text | is that a poodle? | + And I press "Comment" + And I wait for the ajax to finish + + And I go to the activity stream page + Then I should see "Look at this dog" + + When I am on "alice@alice.alice"'s page + And I unlike the post "Look at this dog" + And I go to the activity stream page + Then I should see "Look at this dog" + + When I am on "alice@alice.alice"'s page + And I hover over the ".comment" + And I preemptively confirm the alert + And I click to delete the first comment + And I wait for the ajax to finish + + And I go to the activity stream page + Then I should not see "Look at this dog" diff --git a/features/step_definitions/stream_steps.rb b/features/step_definitions/stream_steps.rb index 901f4da3d3..f93fc4f6a3 100644 --- a/features/step_definitions/stream_steps.rb +++ b/features/step_definitions/stream_steps.rb @@ -2,6 +2,14 @@ When /^I (?:like|unlike) the post "([^"]*)" in the stream$/ do |post_text| like_stream_post(post_text) end +Then /^I should see an image in the publisher$/ do + photo_in_publisher.should be_present +end + +Then /^I (un)?like the post "([^"]*)"$/ do |negate, post_text| + negate ? unlike_post(post_text) : like_post(post_text) +end + Then /^"([^"]*)" should be post (\d+)$/ do |post_text, position| stream_element_numbers_content(position).should have_content(post_text) end diff --git a/features/support/publishing_cuke_helpers.rb b/features/support/publishing_cuke_helpers.rb index c76c46f681..6d7ea8d256 100644 --- a/features/support/publishing_cuke_helpers.rb +++ b/features/support/publishing_cuke_helpers.rb @@ -106,6 +106,12 @@ module PublishingCukeHelpers end end + def unlike_post(post_text) + within_post(post_text) do + find(:css, 'a.unlike').click + end + end + def stream_posts all('.stream_element') end -- GitLab