custom_counter_cache 0.2.3 → 0.2.4

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: 400ada3c3c7715a41f90c457b92c2657c1e78aba
4
- data.tar.gz: 77fe16bc8457b85e482fdacd12a0b98f9c68c652
3
+ metadata.gz: 7b8cf04cebca60ef8b7cb77c5c54f0392c682e3a
4
+ data.tar.gz: 26aa1c6f245700136fe05a317ca2f7838b11ed57
5
5
  SHA512:
6
- metadata.gz: f8fa7062dde06853f72ec4879d90c4ea4c5fda69cf49274166b8ca24aa91660dfed29bdf55bb6fdad1d8a5be139d683cd80efc66767a65bb3d611fa3b83ff0ef
7
- data.tar.gz: a1626989296134b9c7cc5c30dba4eb32442932bfa54b9ba4d007a476df41ca40d2343d5c215b42896deb571838ac20d0109e9f4fd9b2dc871c4bab54eadc9ac5
6
+ metadata.gz: faedbd90dd2d0c094d53f0e6742453fcde890e69da1dbc554d96d0e19f2d6b009d4adcafc040a441f078ee11f93fd45a354f2fcd13b6da98c3e0c79700e7b630
7
+ data.tar.gz: f843efb8ff01722e9cc5e064f8c0d9c27392508b7559037ee6ee751b3537bdc35342377e38df64f82b10bfb59d35024d4926c35cecd726ded9c13d62fec4babd
@@ -1,5 +1,5 @@
1
1
  module CustomCounterCache
2
2
 
3
- VERSION = '0.2.3'
3
+ VERSION = '0.2.4'
4
4
 
5
5
  end
data/test/test_helper.rb CHANGED
@@ -44,6 +44,15 @@ end
44
44
  class ApplicationRecord < ActiveRecord::Base
45
45
  self.abstract_class = true
46
46
  include CustomCounterCache::Model
47
+ @@rails_5_1_or_newer = ActiveModel.version >= Gem::Version.new('5.1.0')
48
+
49
+ def saved_change_to_attribute_compat?(attr)
50
+ if @@rails_5_1_or_newer
51
+ saved_change_to_attribute?(attr)
52
+ else
53
+ attribute_changed?(attr)
54
+ end
55
+ end
47
56
  end
48
57
 
49
58
  class User < ApplicationRecord
@@ -55,7 +64,7 @@ end
55
64
 
56
65
  class Article < ApplicationRecord
57
66
  belongs_to :user
58
- update_counter_cache :user, :published_count, if: Proc.new { |article| article.state_changed? }
67
+ update_counter_cache :user, :published_count, if: Proc.new { |article| article.saved_change_to_attribute_compat?(:state) }
59
68
  has_many :comments, as: :commentable, dependent: :destroy
60
69
  define_counter_cache :comments_count do |article|
61
70
  article.comments.where(state: "published").count
@@ -64,7 +73,7 @@ end
64
73
 
65
74
  class Comment < ApplicationRecord
66
75
  belongs_to :commentable, polymorphic: true
67
- update_counter_cache :commentable, :comments_count, if: Proc.new { |comment| comment.state_changed? }
76
+ update_counter_cache :commentable, :comments_count, if: Proc.new { |comment| comment.saved_change_to_attribute_compat?(:state) }
68
77
  end
69
78
 
70
79
  class Counter < ApplicationRecord
@@ -87,7 +96,7 @@ end
87
96
  class Ball < ApplicationRecord
88
97
  belongs_to :box
89
98
  scope :green, lambda { where(color: 'green') }
90
- update_counter_cache :box, :green_balls_count, if: Proc.new { |ball| ball.color_changed? }
99
+ update_counter_cache :box, :green_balls_count, if: Proc.new { |ball| ball.saved_change_to_attribute_compat?(:color) }
91
100
  update_counter_cache :box, :lifetime_balls_count, except: [:update, :destroy]
92
101
  update_counter_cache :box, :destroyed_balls_count, only: [:destroy]
93
102
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_counter_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cedric Howe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2019-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -31,6 +31,9 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.3.3
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 1.4.0
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +41,9 @@ dependencies:
38
41
  - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: 1.3.3
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 1.4.0
41
47
  description: ''
42
48
  email: cedric@howe.net
43
49
  executables: []
@@ -75,5 +81,5 @@ specification_version: 4
75
81
  summary: Custom counter_cache functionality that supports conditions and multiple
76
82
  models.
77
83
  test_files:
78
- - test/counter_test.rb
79
84
  - test/test_helper.rb
85
+ - test/counter_test.rb