counter_culture 1.10.0 → 1.11.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/README.md +27 -2
- data/VERSION +1 -1
- data/counter_culture.gemspec +3 -3
- data/lib/counter_culture/counter.rb +3 -2
- data/spec/counter_culture_spec.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8e94799083d30c0bd97dbcdd70290c18bcfcd68
|
4
|
+
data.tar.gz: 49074978dffb068623ecf6aec34483d84d4f3704
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12d07d5c17e2f17eaadf865f180849b2a140f5d6a59cf074fdcbd98ac27dae74c0a340052a4bf1ea444029d592be2270d5b93985d599c7615287bafa31c8edd3
|
7
|
+
data.tar.gz: e5c827862773bb11853e2ee918b3b6559af9fcc087db6ec5bfd50cf428efed0d4fdd7560f0e3099e4e2237af6c17c7e31cce7a951af26c879953d11912638924
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 1.11.0 (May 4, 2018)
|
2
|
+
|
3
|
+
Bugfixes:
|
4
|
+
- Fix `with_papertrail` behavior while still addressing the deprecation warning, and actually recording the correct counts (#218, see [airblade/paper_trail#1076](https://github.com/airblade/paper_trail/issues/1076))
|
5
|
+
|
1
6
|
## 1.10.1 (April 20, 2018)
|
2
7
|
|
3
8
|
Improvements:
|
data/README.md
CHANGED
@@ -301,14 +301,23 @@ class Product < ActiveRecord::Base
|
|
301
301
|
end
|
302
302
|
```
|
303
303
|
|
304
|
+
If you would like to avoid this configuration and simply skip counter caches with
|
305
|
+
dynamic column names, while still fixing those counters on the model that are not
|
306
|
+
dynamic, you can pass `skip_unsupported`:
|
307
|
+
|
308
|
+
```ruby
|
309
|
+
Product.counter_culture_fix_counts skip_unsupported: true
|
310
|
+
```
|
311
|
+
|
304
312
|
#### Handling over-written, dynamic foreign keys
|
305
313
|
|
306
314
|
Manually populating counter caches with dynamically over-written foreign keys (```:foreign_key_values``` option) is not supported. You will have to write code to handle this case yourself.
|
307
315
|
|
308
316
|
### Soft-deletes / `paranoia` gem
|
309
317
|
|
310
|
-
This gem will keep counters correctly updated when using the
|
311
|
-
|
318
|
+
This gem will keep counters correctly updated when using the
|
319
|
+
[`paranoia` gem](https://github.com/rubysherpas/paranoia)
|
320
|
+
for soft-delete support. However, to ensure that counts are incremented after a
|
312
321
|
restore you have to make sure that the call to `acts_as_paranoid` comes before
|
313
322
|
the call to `counter_culture` in your model:
|
314
323
|
|
@@ -321,6 +330,22 @@ class SoftDelete < ActiveRecord::Base
|
|
321
330
|
end
|
322
331
|
```
|
323
332
|
|
333
|
+
### PaperTrail integration
|
334
|
+
|
335
|
+
If you are using the [`paper_trail` gem](https://github.com/airblade/paper_trail)
|
336
|
+
and would like new versions to be created when the counter cache columns are
|
337
|
+
changed by counter_culture, you can set the `with_papertrail` option:
|
338
|
+
|
339
|
+
```ruby
|
340
|
+
class Review < ActiveRecord::Base
|
341
|
+
counter_culture :product, with_papertrail: true
|
342
|
+
end
|
343
|
+
|
344
|
+
class Product < ActiveRecord::Base
|
345
|
+
has_paper_trail
|
346
|
+
end
|
347
|
+
```
|
348
|
+
|
324
349
|
#### Polymorphic associations
|
325
350
|
|
326
351
|
counter_culture now supports polymorphic associations of one level only.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.11.0
|
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.11.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.11.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 = "2018-
|
14
|
+
s.date = "2018-05-07"
|
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 = [
|
@@ -71,8 +71,9 @@ module CounterCulture
|
|
71
71
|
if @with_papertrail
|
72
72
|
instance = klass.where(primary_key => id_to_change).first
|
73
73
|
if instance
|
74
|
-
if
|
75
|
-
|
74
|
+
if instance.paper_trail.respond_to?(:save_with_version)
|
75
|
+
# touch_with_version is deprecated starting in PaperTrail 9.0.0
|
76
|
+
instance.paper_trail.save_with_version(validate: false)
|
76
77
|
else
|
77
78
|
instance.paper_trail.touch_with_version
|
78
79
|
end
|
@@ -1949,6 +1949,21 @@ describe "CounterCulture" do
|
|
1949
1949
|
|
1950
1950
|
expect(product.reviews_count).to eq(1)
|
1951
1951
|
expect(product.versions.count).to eq(2)
|
1952
|
+
|
1953
|
+
attrs_from_versions = YAML.load(product.versions.reorder(:id).last.object)
|
1954
|
+
# should be the value before the counter change
|
1955
|
+
expect(attrs_from_versions['reviews_count']).to eq(0)
|
1956
|
+
|
1957
|
+
user.reviews.create :user_id => user.id, :product_id => product.id, :approvals => 13
|
1958
|
+
|
1959
|
+
product.reload
|
1960
|
+
|
1961
|
+
expect(product.reviews_count).to eq(2)
|
1962
|
+
expect(product.versions.count).to eq(3)
|
1963
|
+
|
1964
|
+
attrs_from_versions = YAML.load(product.versions.reorder(:id).last.object)
|
1965
|
+
# should be the value before the counter change
|
1966
|
+
expect(attrs_from_versions['reviews_count']).to eq(1)
|
1952
1967
|
end
|
1953
1968
|
|
1954
1969
|
it "does not create a papertrail version when papertrail flag not set" do
|
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.11.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: 2018-
|
11
|
+
date: 2018-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: after_commit_action
|