diff --git a/spec/models/activities_comment_observer_spec.rb b/spec/models/activities_comment_observer_spec.rb index 43832c229..4ee07a956 100755 --- a/spec/models/activities_comment_observer_spec.rb +++ b/spec/models/activities_comment_observer_spec.rb @@ -5,32 +5,44 @@ include SpecActivityHelper include Stubby + def stub_comments_counter! + counter = stub('approved_comments_counter', :increment! => true, :decrement! => true) + stub_site.stub!(:approved_comments_counter).and_return counter + stub_section.stub!(:approved_comments_counter).and_return counter + stub_article.stub!(:approved_comments_counter).and_return counter + end + it "should log a 'created' activity on save when the comment is a new_record" do scenario :comment_created + stub_comments_counter! expect_activity_new_with :actions => ['created'] Comment.with_observers('activities/comment_observer') { @comment.save! } end it "should log an 'edited' activity on save when the comment already exists" do scenario :comment_updated + stub_comments_counter! expect_activity_new_with :actions => ['edited'] Comment.with_observers('activities/comment_observer') { @comment.save! } end it "should log an 'approved' activity on save when the comment is approved and the approved attribute has changed" do scenario :comment_approved + stub_comments_counter! expect_activity_new_with :actions => ['approved'] Comment.with_observers('activities/comment_observer') { @comment.save! } end it "should log a 'unapproved' activity on save when the comment is a draft and the approved attribute has changed" do scenario :comment_unapproved + stub_comments_counter! expect_activity_new_with :actions => ['unapproved'] Comment.with_observers('activities/comment_observer') { @comment.save! } end it "should log a 'deleted' activity on destroy" do scenario :comment_destroyed + stub_comments_counter! expect_activity_new_with :actions => ['deleted'] Comment.with_observers('activities/comment_observer') { @comment.destroy } end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 648657f5d..a9c19afac 100755 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -67,7 +67,7 @@ end it 'updates the commentable after create' do - Comment.after_create.should include(:update_commentable) + Comment.after_save.should include(:update_commentable) end it 'updates the commentable after destroy' do diff --git a/spec/scenarios/forum_with_three_comments.rb b/spec/scenarios/forum_with_three_comments.rb index 9bd2a7880..dbf578140 100644 --- a/spec/scenarios/forum_with_three_comments.rb +++ b/spec/scenarios/forum_with_three_comments.rb @@ -3,6 +3,10 @@ @forum.stub!(:build_path).and_return 'forum' @forum.save! + counter = stub('approved_comments_counter', :increment! => true, :decrement! => true) + @forum.stub!(:approved_comments_counter).and_return counter + stub_site.stub!(:approved_comments_counter).and_return counter + @three_days_ago = 3.days.ago @two_days_ago = 2.days.ago @one_day_ago = 1.days.ago