counter_culture 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/README.md +11 -2
- data/VERSION +1 -1
- data/circle.yml +3 -0
- data/counter_culture.gemspec +6 -4
- data/lib/counter_culture/counter.rb +3 -1
- data/spec/counter_culture_spec.rb +18 -5
- data/spec/models/review.rb +1 -1
- data/spec/schema.rb +1 -0
- metadata +16 -3
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45d1871f0c220d0b4ada77d026082e91c02ec396
|
4
|
+
data.tar.gz: a3e3b9cbdbab8d8de36b05f1946d6e978e8a1ee8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a79ae365d86fdd374c75a1a7267564a99d3b43885c45905f5a7ef7abc6aff6d04095f241af792d13ed5f5f5979d4dbb73d753417255deeb8183693a621fbc706
|
7
|
+
data.tar.gz: 166f643bd80237a11548e908c9708d2311d651ceec97504fb62228e5050ed21a37555456e06c4e65111bad6c43f2b0b4e89f1b2b6e5ef7d3381dc703efd247b6
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -150,6 +150,7 @@ GEM
|
|
150
150
|
sqlite3 (1.3.11)
|
151
151
|
thor (0.19.1)
|
152
152
|
thread_safe (0.3.5)
|
153
|
+
timecop (0.8.1)
|
153
154
|
tzinfo (1.2.2)
|
154
155
|
thread_safe (~> 0.1)
|
155
156
|
|
@@ -170,6 +171,7 @@ DEPENDENCIES
|
|
170
171
|
rspec (~> 3.0)
|
171
172
|
rspec-extra-formatters
|
172
173
|
sqlite3
|
174
|
+
timecop
|
173
175
|
|
174
176
|
BUNDLED WITH
|
175
177
|
1.13.7
|
data/README.md
CHANGED
@@ -198,12 +198,21 @@ Now, the ```Category``` model will keep an up-to-date counter-cache in the ```pr
|
|
198
198
|
|
199
199
|
### Updating timestamps when counts change
|
200
200
|
|
201
|
-
By default, counter_culture does not update the timestamp of models when it updates their counter caches. If you would like every change in the counter cache column to result in an updated timestamp, simply set the touch option to true
|
201
|
+
By default, counter_culture does not update the timestamp of models when it updates their counter caches. If you would like every change in the counter cache column to result in an updated timestamp, simply set the touch option to true:
|
202
202
|
```ruby
|
203
203
|
counter_culture :category, :touch => true
|
204
204
|
```
|
205
205
|
|
206
|
-
This
|
206
|
+
This is useful when you require your caches to get invalidated when the counter cache changes.
|
207
|
+
|
208
|
+
### Custom timestamp column
|
209
|
+
|
210
|
+
You may also specify a custom timestamp column that gets updated only when a particular counter cache changes:
|
211
|
+
```ruby
|
212
|
+
counter_culture :category, :touch => 'category_count_changed'
|
213
|
+
```
|
214
|
+
|
215
|
+
With this option, any time the `category_counter_cache` changes both the `category_count_changed` and `updated_at` columns will get updated.
|
207
216
|
|
208
217
|
### Executing counter cache updates after commit
|
209
218
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/circle.yml
CHANGED
data/counter_culture.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
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 1.
|
5
|
+
# stub: counter_culture 1.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "counter_culture"
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Magnus von Koeller"]
|
14
|
-
s.date = "2017-
|
14
|
+
s.date = "2017-02-21"
|
15
15
|
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."
|
16
16
|
s.email = "magnus@vonkoeller.de"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -22,7 +22,6 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.files = [
|
23
23
|
".document",
|
24
24
|
".rspec",
|
25
|
-
".ruby-version",
|
26
25
|
".travis.yml",
|
27
26
|
"CHANGELOG.md",
|
28
27
|
"Gemfile",
|
@@ -130,6 +129,7 @@ Gem::Specification.new do |s|
|
|
130
129
|
s.add_development_dependency(%q<rails>, [">= 3.1.0"])
|
131
130
|
s.add_development_dependency(%q<rspec>, ["~> 3.0"])
|
132
131
|
s.add_development_dependency(%q<awesome_print>, [">= 0"])
|
132
|
+
s.add_development_dependency(%q<timecop>, [">= 0"])
|
133
133
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
134
134
|
s.add_development_dependency(%q<bundler>, [">= 1.2.0"])
|
135
135
|
s.add_development_dependency(%q<jeweler>, ["~> 2.1"])
|
@@ -141,6 +141,7 @@ Gem::Specification.new do |s|
|
|
141
141
|
s.add_dependency(%q<rails>, [">= 3.1.0"])
|
142
142
|
s.add_dependency(%q<rspec>, ["~> 3.0"])
|
143
143
|
s.add_dependency(%q<awesome_print>, [">= 0"])
|
144
|
+
s.add_dependency(%q<timecop>, [">= 0"])
|
144
145
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
145
146
|
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
146
147
|
s.add_dependency(%q<jeweler>, ["~> 2.1"])
|
@@ -153,6 +154,7 @@ Gem::Specification.new do |s|
|
|
153
154
|
s.add_dependency(%q<rails>, [">= 3.1.0"])
|
154
155
|
s.add_dependency(%q<rspec>, ["~> 3.0"])
|
155
156
|
s.add_dependency(%q<awesome_print>, [">= 0"])
|
157
|
+
s.add_dependency(%q<timecop>, [">= 0"])
|
156
158
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
157
159
|
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
158
160
|
s.add_dependency(%q<jeweler>, ["~> 2.1"])
|
@@ -56,7 +56,9 @@ module CounterCulture
|
|
56
56
|
# and here we update the timestamp, if so desired
|
57
57
|
if touch
|
58
58
|
current_time = obj.send(:current_time_from_proper_timezone)
|
59
|
-
obj.send(:timestamp_attributes_for_update_in_model)
|
59
|
+
timestamp_columns = obj.send(:timestamp_attributes_for_update_in_model)
|
60
|
+
timestamp_columns << touch if touch != true
|
61
|
+
timestamp_columns.each do |timestamp_column|
|
60
62
|
updates << "#{timestamp_column} = '#{current_time.to_formatted_s(:db)}'"
|
61
63
|
end
|
62
64
|
end
|
@@ -1402,14 +1402,27 @@ describe "CounterCulture" do
|
|
1402
1402
|
user = User.create
|
1403
1403
|
product = Product.create
|
1404
1404
|
|
1405
|
-
|
1405
|
+
Timecop.travel(1.second.from_now) do
|
1406
|
+
review = Review.create :user_id => user.id, :product_id => product.id
|
1406
1407
|
|
1407
|
-
|
1408
|
+
user.reload; product.reload
|
1409
|
+
|
1410
|
+
expect(user.created_at.to_i).to eq(user.updated_at.to_i)
|
1411
|
+
expect(product.created_at.to_i).to be < product.updated_at.to_i
|
1412
|
+
end
|
1413
|
+
end
|
1408
1414
|
|
1409
|
-
|
1415
|
+
it "should update the timestamp for custom column if touch: rexiews_updated_at is set" do
|
1416
|
+
product = Product.create
|
1417
|
+
|
1418
|
+
Timecop.travel(1.second.from_now) do
|
1419
|
+
Review.create :product_id => product.id
|
1410
1420
|
|
1411
|
-
|
1412
|
-
|
1421
|
+
product.reload
|
1422
|
+
|
1423
|
+
expect(product.created_at.to_i).to be < product.rexiews_updated_at.to_i
|
1424
|
+
expect(product.created_at.to_i).to be < product.updated_at.to_i
|
1425
|
+
end
|
1413
1426
|
end
|
1414
1427
|
|
1415
1428
|
it "should update counts correctly when creating using nested attributes" do
|
data/spec/models/review.rb
CHANGED
@@ -3,7 +3,7 @@ class Review < ActiveRecord::Base
|
|
3
3
|
belongs_to :product
|
4
4
|
|
5
5
|
counter_culture :product, :touch => true
|
6
|
-
counter_culture :product, :column_name => 'rexiews_count'
|
6
|
+
counter_culture :product, :column_name => 'rexiews_count', touch: :rexiews_updated_at
|
7
7
|
counter_culture :user
|
8
8
|
counter_culture :user, :column_name => proc { |model| model.review_type && model.review_type != 'null' ? "#{model.review_type}_count" : nil }, :column_names => {"reviews.review_type = 'using'" => 'using_count', "reviews.review_type = 'tried'" => 'tried_count', "reviews.review_type = 'null'" => nil}
|
9
9
|
counter_culture :user, :column_name => 'review_approvals_count', :delta_column => 'approvals'
|
data/spec/schema.rb
CHANGED
@@ -50,6 +50,7 @@ ActiveRecord::Schema.define(:version => 20120522160158) do
|
|
50
50
|
t.integer "reviews_count", :default => 0, :null => false
|
51
51
|
t.integer "simple_reviews_count", :default => 0, :null => false
|
52
52
|
t.integer "rexiews_count", :default => 0, :null => false
|
53
|
+
t.datetime "rexiews_updated_at"
|
53
54
|
t.integer "twitter_reviews_count", :default => 0, :null => false
|
54
55
|
t.integer "category_id"
|
55
56
|
t.datetime "created_at"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: counter_culture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
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: 2017-
|
11
|
+
date: 2017-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: after_commit_action
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: timecop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: rdoc
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,7 +178,6 @@ extra_rdoc_files:
|
|
164
178
|
files:
|
165
179
|
- ".document"
|
166
180
|
- ".rspec"
|
167
|
-
- ".ruby-version"
|
168
181
|
- ".travis.yml"
|
169
182
|
- CHANGELOG.md
|
170
183
|
- Gemfile
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.2.4
|