ar-resque-counter-cache 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -73,7 +73,7 @@ module ArResqueCounterCache
|
|
73
73
|
# however, we need the `:counter_cache` option to be present so that
|
74
74
|
# `ActiveRecord::Base.reset_counters` works correctly (as of
|
75
75
|
# activerecord 3.2.9).
|
76
|
-
options[:counter_cache] = true
|
76
|
+
options[:counter_cache] = true if options[:async_counter_cache]
|
77
77
|
reflection
|
78
78
|
end
|
79
79
|
|
@@ -44,5 +44,22 @@ describe ArResqueCounterCache::ActiveRecord do
|
|
44
44
|
user.reload
|
45
45
|
user.posts_count.should eq(10)
|
46
46
|
end
|
47
|
+
|
48
|
+
it "should allow normal counter caches" do
|
49
|
+
user.dogs.create(:name => "Ruff")
|
50
|
+
user.reload
|
51
|
+
user.dogs_count.should eq(1)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should allow non-counter caches" do
|
55
|
+
user2 = User.create(:name => "Sam")
|
56
|
+
cat = user.cats.create(:name => "Missy")
|
57
|
+
# Transfership of ownership would trigger counter cache methods... it
|
58
|
+
# should do nothing here.
|
59
|
+
cat.user = user2
|
60
|
+
cat.save!
|
61
|
+
user.cats.size.should eq(0)
|
62
|
+
user2.cats.size.should eq(1)
|
63
|
+
end
|
47
64
|
end
|
48
65
|
end
|
data/spec/models.rb
CHANGED
@@ -7,6 +7,7 @@ class CreateModelsForTest < ActiveRecord::Migration
|
|
7
7
|
t.string :name
|
8
8
|
t.integer :posts_count, :default => 0
|
9
9
|
t.integer :comments_count, :default => 0
|
10
|
+
t.integer :dogs_count, :default => 0
|
10
11
|
end
|
11
12
|
create_table :posts do |t|
|
12
13
|
t.string :body
|
@@ -18,17 +19,29 @@ class CreateModelsForTest < ActiveRecord::Migration
|
|
18
19
|
t.belongs_to :user
|
19
20
|
t.belongs_to :post
|
20
21
|
end
|
22
|
+
create_table :dogs do |t|
|
23
|
+
t.string :name
|
24
|
+
t.belongs_to :user
|
25
|
+
end
|
26
|
+
create_table :cats do |t|
|
27
|
+
t.string :name
|
28
|
+
t.belongs_to :user
|
29
|
+
end
|
21
30
|
end
|
22
31
|
def self.down
|
23
32
|
drop_table(:users)
|
24
33
|
drop_table(:posts)
|
25
34
|
drop_table(:comments)
|
35
|
+
drop_table(:dogs)
|
36
|
+
drop_table(:cats)
|
26
37
|
end
|
27
38
|
end
|
28
39
|
|
29
40
|
class User < ActiveRecord::Base
|
30
41
|
has_many :comments
|
31
42
|
has_many :posts
|
43
|
+
has_many :dogs
|
44
|
+
has_many :cats
|
32
45
|
end
|
33
46
|
|
34
47
|
class Post < ActiveRecord::Base
|
@@ -40,3 +53,13 @@ class Comment < ActiveRecord::Base
|
|
40
53
|
belongs_to :user, :async_counter_cache => true
|
41
54
|
belongs_to :post, :async_counter_cache => "count_of_comments"
|
42
55
|
end
|
56
|
+
|
57
|
+
# Old school counter cache.
|
58
|
+
class Dog < ActiveRecord::Base
|
59
|
+
belongs_to :user, :counter_cache => true
|
60
|
+
end
|
61
|
+
|
62
|
+
# No counter cache at all.
|
63
|
+
class Cat < ActiveRecord::Base
|
64
|
+
belongs_to :user
|
65
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-resque-counter-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|