Skip to content

Commit

Permalink
fix counter related specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Fuchs committed Jul 17, 2008
1 parent 7657741 commit 4c509f3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions spec/models/activities_comment_observer_spec.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/models/comment_spec.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/scenarios/forum_with_three_comments.rb
Expand Up @@ -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
Expand Down

0 comments on commit 4c509f3

Please sign in to comment.