counter_culture 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -64,6 +64,16 @@ end
64
64
 
65
65
  Now, the ```Category``` model will keep an up-to-date counter-cache in the ```products_count``` column of the ```categories``` table. This will work with any number of levels.
66
66
 
67
+ If you want to have a counter-cache for each level of your hierarchy, then you must add a separate counter cache for each level. In the above example, if you wanted a count of products for each category and sub_category you would change the Product class to:
68
+
69
+ ```ruby
70
+ class Product < ActiveRecord::Base
71
+ belongs_to :sub_category
72
+ counter_culture [:sub_category, :category]
73
+ counter_culture [:sub_category]
74
+ end
75
+ ```
76
+
67
77
  ### Customizing the column name
68
78
 
69
79
  ```ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.12
1
+ 0.1.13
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "counter_culture"
8
- s.version = "0.1.12"
8
+ s.version = "0.1.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Magnus von Koeller"]
12
- s.date = "2013-05-24"
12
+ s.date = "2013-07-22"
13
13
  s.description = "counter_culture provides turbo-charged counter caches that are kept up-to-date not just on create and destroy, that support multiple levels of indirection through relationships, allow dynamic column names and that avoid deadlocks by updating in the after_commit callback."
14
14
  s.email = "magnus@vonkoeller.de"
15
15
  s.extra_rdoc_files = [
@@ -115,7 +115,7 @@ module CounterCulture
115
115
  }
116
116
  # use update_all because it's faster and because a fixed counter-cache shouldn't
117
117
  # update the timestamp
118
- klass.where(:id => model.id).update_all(column_name => counts[model.id])
118
+ klass.where(:id => model.id).update_all(column_name => counts[model.id].to_i)
119
119
  end
120
120
  end
121
121
  end
@@ -773,6 +773,24 @@ describe "CounterCulture" do
773
773
  product.reviews_count.should == 1
774
774
  end
775
775
 
776
+ it "should fix where the count should go back to zero correctly" do
777
+ user = User.create
778
+ product = Product.create
779
+
780
+ user.reviews_count.should == 0
781
+
782
+ user.reviews_count = -1
783
+ user.save!
784
+
785
+ fixed = Review.counter_culture_fix_counts :skip_unsupported => true
786
+ fixed.length.should == 1
787
+
788
+ user.reload
789
+
790
+ user.reviews_count.should == 0
791
+
792
+ end
793
+
776
794
  it "should fix a second-level counter cache correctly" do
777
795
  company = Company.create
778
796
  user = User.create :manages_company_id => company.id
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: counter_culture
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
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: 2013-05-24 00:00:00.000000000 Z
12
+ date: 2013-07-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -219,7 +219,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
219
  version: '0'
220
220
  segments:
221
221
  - 0
222
- hash: 209272298773152950
222
+ hash: -3562941340638569663
223
223
  required_rubygems_version: !ruby/object:Gem::Requirement
224
224
  none: false
225
225
  requirements: