Permalink
Browse files

Added specs for doing Model.new.save.

  • Loading branch information...
1 parent 1a71849 commit 4c2b6b55fd7d0ce311e4dd9399bb65c817dc05fc @postmodern committed Jul 17, 2010
Showing with 20 additions and 0 deletions.
  1. +20 −0 spec/integration/counter_cacheable_spec.rb
@@ -8,7 +8,9 @@
{:title => 'Hello', :body => 'Hello there.'}
]
)
+ end
+ before(:each) do
@user = User.first
@post = @user.posts.first
end
@@ -38,7 +40,25 @@
(new_counter - orig_counter).should == 1
end
+ it "should increment the counter cache by 1 when a new resource is saved" do
+ orig_counter = @post.comments_counter
+
+ @post.comments.new(
+ :body => 'omg',
+ :user => @user
+ ).save
+
+ new_counter = @post.comments_counter
+
+ (new_counter - orig_counter).should == 1
+ end
+
it "should decrement the counter cache by 1 when a resource is destroyed" do
+ @post.comments.create(
+ :body => 'wtf',
+ :user => @user
+ )
+
orig_counter = @post.comments_counter
@post.comments.first.destroy

0 comments on commit 4c2b6b5

Please sign in to comment.