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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f0d12b75377e5baffc9364982bfd8d08f2f5530
4
- data.tar.gz: 21a22f582dd41bc8a6e7d9cc85a70757f5acb982
3
+ metadata.gz: b8e94799083d30c0bd97dbcdd70290c18bcfcd68
4
+ data.tar.gz: 49074978dffb068623ecf6aec34483d84d4f3704
5
5
  SHA512:
6
- metadata.gz: d0a5bba782c586130d2436ae029e147d848a3fd740ecf2060e45a43e8df8775401dedd7b1df23643a71420a7c5ecbab63f4a47359c770263cfc5997110d7b608
7
- data.tar.gz: f83999e34478258e389cb0d893194b0839104c5f7fd3adcef11b2833bfae1b5de72b087fc0d71e8528aca3479b52b9664cdf43bddf8c12f67e5fcd3125e4851d
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 `paranoia` gem for
311
- soft-delete support. However, to ensure that counts are incremented after a
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.10.0
1
+ 1.11.0
@@ -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.10.0 ruby lib
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.10.0"
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-04-20"
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 PaperTrail::VERSION::MAJOR >= 9
75
- instance.touch
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.10.0
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-04-20 00:00:00.000000000 Z
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