Skip to content
Browse files

Added specs for the :counter_index option.

  • Loading branch information...
1 parent ce58073 commit 99658162b908d1a73d4337aae25ad324f1c27b62 @postmodern committed Jul 17, 2010
Showing with 15 additions and 1 deletion.
  1. +13 −0 spec/integration/counter_cacheable_spec.rb
  2. +2 −1 spec/integration/models/comment.rb
View
13 spec/integration/counter_cacheable_spec.rb
@@ -23,6 +23,10 @@
User.properties.should be_named('post_comments_counter')
end
+ it "should optionally define a counter index column" do
+ Comment.properties.should be_named('users_index')
+ end
+
it "should have a counter cache of 0 by default" do
@post.comments_counter.should == 0
end
@@ -40,6 +44,15 @@
(new_counter - orig_counter).should == 1
end
+ it "should increment the counter cache by 1 when a new resource is created" do
+ @post.comments.create(
+ :body => 'lol',
+ :user => @user
+ )
+
+ @post.comments.last.users_index.should == 1
+ end
+
it "should increment the counter cache by 1 when a new resource is saved" do
orig_counter = @post.comments_counter
View
3 spec/integration/models/comment.rb
@@ -17,6 +17,7 @@ class Comment
belongs_to :user
counter_cacheable :post
- counter_cacheable :user, :counter_property => :post_comments_counter
+ counter_cacheable :user, :counter_property => :post_comments_counter,
+ :counter_index => true
end

0 comments on commit 9965816

Please sign in to comment.
Something went wrong with that request. Please try again.