counter_culture 0.1.19 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7de2e21ff4b35d41446f5baabcee7e79c667255d
4
- data.tar.gz: 17e7fd7a5f09dcf4bcf883ab32bc4f85fa94fe5e
3
+ metadata.gz: f5c04260f58914bf559f6f7b94bee0af339daa44
4
+ data.tar.gz: fae72b4c05340ec945bad231311c214d2a9956d4
5
5
  SHA512:
6
- metadata.gz: bef9637468d05f04302b73392d82ed397099e4041ea3c0eed966531ea87961170125b1226de687b51523164a1733ee9a4f5bdb84cbc740f7403e81ad7a701b35
7
- data.tar.gz: 191d75d87fc71b208dc38ca853e4ab47455f3d98a7c65f203c9292c30730b1abe4a920dbe9850dc08d00e175674b075a6dbb1c333c6dec4f09cf64ad4ced922c
6
+ metadata.gz: 7ea0b1c02e7afd5f19f59226d7b4118399e7fadcaba9162d87969eb9ae3d1940110c522e9536a259588acd604289a95d5c0b8760b725348d1ec5141652e68094
7
+ data.tar.gz: dc746d48a2774df255c42300024e6c96b68c09d9e52ad9b5db0a959f8d7d24875faca48acd4836a98952688fbc566b6b22d3c94ec17188eb443683a59e222487
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
5
+ - "2.1.0"
6
+ script: TRAVIS=true bundle exec rake spec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.20 (May 14, 2014)
2
+
3
+ Bugfixes:
4
+ - counter_culture_fix counts now supports float values, where it forced integer values previously
5
+
1
6
  ## 0.1.19 (January 29, 2014)
2
7
 
3
8
  Bugfixes:
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ source "https://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development, :test do
9
+ gem "rake"
9
10
  gem "rails", '>= 3.1.0'
10
11
  gem "rspec", "~> 2.10.0"
11
12
  gem "after_commit_action"
data/Gemfile.lock CHANGED
@@ -138,6 +138,7 @@ DEPENDENCIES
138
138
  database_cleaner (>= 1.1.1)
139
139
  jeweler (~> 2.0.1)
140
140
  rails (>= 3.1.0)
141
+ rake
141
142
  rdoc (~> 3.12)
142
143
  rspec (~> 2.10.0)
143
144
  rspec-extra-formatters
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # counter_culture
1
+ # counter_culture [![Build Status](https://travis-ci.org/magnusvk/counter_culture.png)](https://travis-ci.org/magnusvk/counter_culture)
2
2
 
3
3
  Turbo-charged counter caches for your Rails app. Huge improvements over the Rails standard counter caches:
4
4
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.19
1
+ 0.1.20
@@ -2,15 +2,15 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: counter_culture 0.1.19 ruby lib
5
+ # stub: counter_culture 0.1.20 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "counter_culture"
9
- s.version = "0.1.19"
9
+ s.version = "0.1.20"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Magnus von Koeller"]
13
- s.date = "2014-01-29"
13
+ s.date = "2014-05-15"
14
14
  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."
15
15
  s.email = "magnus@vonkoeller.de"
16
16
  s.extra_rdoc_files = [
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  ".rspec",
23
23
  ".ruby-gemset",
24
24
  ".ruby-version",
25
+ ".travis.yml",
25
26
  "CHANGELOG.md",
26
27
  "Gemfile",
27
28
  "Gemfile.lock",
@@ -105,6 +106,7 @@ Gem::Specification.new do |s|
105
106
  s.specification_version = 4
106
107
 
107
108
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
109
+ s.add_development_dependency(%q<rake>, [">= 0"])
108
110
  s.add_development_dependency(%q<rails>, [">= 3.1.0"])
109
111
  s.add_development_dependency(%q<rspec>, ["~> 2.10.0"])
110
112
  s.add_development_dependency(%q<after_commit_action>, [">= 0"])
@@ -114,6 +116,7 @@ Gem::Specification.new do |s|
114
116
  s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
115
117
  s.add_runtime_dependency(%q<after_commit_action>, ["~> 0.1.3"])
116
118
  else
119
+ s.add_dependency(%q<rake>, [">= 0"])
117
120
  s.add_dependency(%q<rails>, [">= 3.1.0"])
118
121
  s.add_dependency(%q<rspec>, ["~> 2.10.0"])
119
122
  s.add_dependency(%q<after_commit_action>, [">= 0"])
@@ -124,6 +127,7 @@ Gem::Specification.new do |s|
124
127
  s.add_dependency(%q<after_commit_action>, ["~> 0.1.3"])
125
128
  end
126
129
  else
130
+ s.add_dependency(%q<rake>, [">= 0"])
127
131
  s.add_dependency(%q<rails>, [">= 3.1.0"])
128
132
  s.add_dependency(%q<rspec>, ["~> 2.10.0"])
129
133
  s.add_dependency(%q<after_commit_action>, [">= 0"])
@@ -111,11 +111,11 @@ module CounterCulture
111
111
  while (records = klass.reorder(full_primary_key(klass) + " ASC").offset(start).limit(batch_size)).any?
112
112
  # collect the counts for this batch in an id => count hash; this saves time relative
113
113
  # to running one query per record
114
- counts = counts_query.reorder(full_primary_key(klass) + " ASC").offset(start).limit(batch_size).group(full_primary_key(klass)).inject({}){|memo, model| memo[model.id] = model.count.to_i; memo}
114
+ counts = counts_query.reorder(full_primary_key(klass) + " ASC").offset(start).limit(batch_size).group(full_primary_key(klass)).inject({}){|memo, model| memo[model.id] = model.count || 0; memo}
115
115
 
116
116
  # now iterate over all the models and see whether their counts are right
117
117
  records.each do |model|
118
- if model.read_attribute(column_name) != counts[model.id].to_i
118
+ if model.read_attribute(column_name) != (counts[model.id] || 0)
119
119
  # keep track of what we fixed, e.g. for a notification email
120
120
  fixed<< {
121
121
  :entity => klass.name,
@@ -126,7 +126,7 @@ module CounterCulture
126
126
  }
127
127
  # use update_all because it's faster and because a fixed counter-cache shouldn't
128
128
  # update the timestamp
129
- klass.where(:id => model.id).update_all(column_name => counts[model.id].to_i)
129
+ klass.where(:id => model.id).update_all(column_name => counts[model.id] || 0)
130
130
  end
131
131
  end
132
132
 
@@ -1083,7 +1083,7 @@ describe "CounterCulture" do
1083
1083
  SimpleMain.find_each { |main| main.simple_dependents_count.should == main.id % 4 }
1084
1084
  end
1085
1085
 
1086
- it "should correctly sum up flaot values" do
1086
+ it "should correctly sum up float values" do
1087
1087
  user = User.create
1088
1088
 
1089
1089
  r1 = Review.create :user_id => user.id, :value => 3.4
@@ -1117,6 +1117,44 @@ describe "CounterCulture" do
1117
1117
  user.review_value_sum.round(1).should == 0
1118
1118
  end
1119
1119
 
1120
+ it "should correctly fix float values that came out of sync" do
1121
+ user = User.create
1122
+
1123
+ r1 = Review.create :user_id => user.id, :value => 3.4
1124
+ r2 = Review.create :user_id => user.id, :value => 7.2
1125
+ r3 = Review.create :user_id => user.id, :value => 5
1126
+
1127
+ user.update_column(:review_value_sum, 0)
1128
+ Review.counter_culture_fix_counts skip_unsupported: true
1129
+
1130
+ user.reload
1131
+ user.review_value_sum.round(1).should == 15.6
1132
+
1133
+ r2.destroy
1134
+
1135
+ user.update_column(:review_value_sum, 0)
1136
+ Review.counter_culture_fix_counts skip_unsupported: true
1137
+
1138
+ user.reload
1139
+ user.review_value_sum.round(1).should == 8.4
1140
+
1141
+ r3.destroy
1142
+
1143
+ user.update_column(:review_value_sum, 0)
1144
+ Review.counter_culture_fix_counts skip_unsupported: true
1145
+
1146
+ user.reload
1147
+ user.review_value_sum.round(1).should == 3.4
1148
+
1149
+ r1.destroy
1150
+
1151
+ user.update_column(:review_value_sum, 0)
1152
+ Review.counter_culture_fix_counts skip_unsupported: true
1153
+
1154
+ user.reload
1155
+ user.review_value_sum.round(1).should == 0
1156
+ end
1157
+
1120
1158
  it "should update the timestamp if touch: true is set" do
1121
1159
  user = User.create
1122
1160
  product = Product.create
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: counter_culture
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus von Koeller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-29 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rails
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -137,6 +151,7 @@ files:
137
151
  - .rspec
138
152
  - .ruby-gemset
139
153
  - .ruby-version
154
+ - .travis.yml
140
155
  - CHANGELOG.md
141
156
  - Gemfile
142
157
  - Gemfile.lock