Permalink
Browse files

add test for polymorphic has_many association

  • Loading branch information...
flyerhzm committed Oct 6, 2011
1 parent f08891c commit 8fef2fc7254b4f6e9c2d4dd719e8fcf86f112b7b
Showing with 24 additions and 1 deletion.
  1. +24 −1 spec/cacheable_spec.rb
View
@@ -9,7 +9,7 @@
@post1 = @user.posts.create(:title => 'post1')
@post2 = @user.posts.create(:title => 'post2')
@comment1 = @post1.comments.create
- @comment2 = @post2.comments.create
+ @comment2 = @post1.comments.create
end
before :each do
@@ -103,6 +103,22 @@
end
end
+ context "has_many with polymorphic" do
+ it "should not cache associations" do
+ cache.data["posts/#{@post1.id}/association/comments"].should be_nil
+ end
+
+ it "should cache Post#comments" do
+ @post1.cached_comments.should == [@comment1, @comment2]
+ cache.data["posts/#{@post1.id}/association/comments"].should == [@comment1, @comment2]
+ end
+
+ it "should cache Post#comments multiple times" do
+ @post1.cached_comments
+ @post1.cached_comments.should == [@comment1, @comment2]
+ end
+ end
+
context "has_one" do
it "should not cache associations" do
cache.data["users/#{@user.id}/association/account"].should be_nil
@@ -149,6 +165,13 @@
cache.data["users/#{@user.id}/association/posts"].should be_nil
end
+ it "should delete has_many with polymorphic with_association cache" do
+ @post1.cached_comments
+ cache.data["posts/#{@post1.id}/association/comments"].should_not be_nil
+ @comment1.save
+ cache.data["posts/#{@post1.id}/association/comments"].should be_nil
+ end
+
it "should delete has_one with_association cache" do
@user.cached_account
cache.data["users/#{@user.id}/association/account"].should_not be_nil

0 comments on commit 8fef2fc

Please sign in to comment.