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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 257485aedd64efe7fa6d054b77d54170f88df34a
4
- data.tar.gz: fd59ea55659f4c66717f7386945bb93268a2c5ad
3
+ metadata.gz: 45d1871f0c220d0b4ada77d026082e91c02ec396
4
+ data.tar.gz: a3e3b9cbdbab8d8de36b05f1946d6e978e8a1ee8
5
5
  SHA512:
6
- metadata.gz: 1056dad890bac7862cc6f3d9a729412e85efbbe00d31798cc2f0f9b504c6b163e23b86df16c803703ba4f8e17e52d5a66e27b131bf4a27ede191192d0b76666b
7
- data.tar.gz: 84cd87e9e0a0c3044087f5273139937ab1aec2650df93fbcf39e4fd1aa3d3f6c41541073fcf79407389951f236c3c75ad3e25facbe158fe886f35d698ff1e8cf
6
+ metadata.gz: a79ae365d86fdd374c75a1a7267564a99d3b43885c45905f5a7ef7abc6aff6d04095f241af792d13ed5f5f5979d4dbb73d753417255deeb8183693a621fbc706
7
+ data.tar.gz: 166f643bd80237a11548e908c9708d2311d651ceec97504fb62228e5050ed21a37555456e06c4e65111bad6c43f2b0b4e89f1b2b6e5ef7d3381dc703efd247b6
@@ -1,3 +1,8 @@
1
+ ## 1.2.0 (February 21, 2017)
2
+
3
+ New features:
4
+ - Add support for custom timestamp column with `touch` option
5
+
1
6
  ## 1.1.1 (January 13, 2017)
2
7
 
3
8
  Bugfixes:
data/Gemfile CHANGED
@@ -14,6 +14,7 @@ group :development, :test do
14
14
  gem "rails", '>= 3.1.0'
15
15
  gem "rspec", "~> 3.0"
16
16
  gem "awesome_print"
17
+ gem "timecop"
17
18
  end
18
19
 
19
20
  group :development do
@@ -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 like so:
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 can be useful when you use Rails' caching mechanism and display a counter cache's value in the cached fragment.
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
1
+ 1.2.0
data/circle.yml CHANGED
@@ -1,3 +1,6 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.3.1
1
4
  database:
2
5
  override:
3
6
  - echo "No database setup required..."
@@ -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.1.1 ruby lib
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.1.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-01-13"
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).each do |timestamp_column|
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
- sleep 1
1405
+ Timecop.travel(1.second.from_now) do
1406
+ review = Review.create :user_id => user.id, :product_id => product.id
1406
1407
 
1407
- review = Review.create :user_id => user.id, :product_id => product.id
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
- user.reload; product.reload
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
- expect(user.created_at.to_i).to eq(user.updated_at.to_i)
1412
- expect(product.created_at.to_i).to be < product.updated_at.to_i
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
@@ -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'
@@ -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.1.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-01-13 00:00:00.000000000 Z
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
@@ -1 +0,0 @@
1
- 2.2.4