counter_culture 3.10.0 → 3.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78d568cfdb319852f7cbfa1f09b3b17d7a583f0a56afcba26ffc6db937906c0f
4
- data.tar.gz: 220516dcbbe2966749fd1c74a6720e9bb82565bba0b41f053fc94c9948db4b73
3
+ metadata.gz: dc2af460731ae5d0d71c452bff1969ede450961b0383de35624015058e73bbce
4
+ data.tar.gz: fe4cd5de448b52f11b2b5d9409202ad115bb6e87d5008ed83eb3708fbd177745
5
5
  SHA512:
6
- metadata.gz: 5fb91dc191fad8487358613ac76eae7887113b7191ced1b59acde6a84963c2813787c1036a07490f4579e423bb9cedcf3ba324b6d2f4e1cac903cf5721949445
7
- data.tar.gz: c86cf4baee69aceec50718877ab0fd9ff6064bd460d4f0fff8615eb0836cc5c3d74e44178fbd87976a7eab18a106a5f25e09179a85380a93472cbf1e715f14ce
6
+ metadata.gz: 360b2c83a7e377c2a9974cfbd812d5df0f0d3921c93aabf5b4c0426e5f7aab156fe1cd7350607be17694b243f6cc823000b8eb2bb342fb65401ce9071dcc688e
7
+ data.tar.gz: 39a199f34ca2275c4804ab1f03a0dac80105675ef43dc473f3d9d4c479b57eb7088d32a36a67a47df00ae26e1d81d3454cf0de465209d357c181cca66de18d1c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 3.10.2 (June 24, 2025)
2
+
3
+ Bugfixes:
4
+ - Fix incorrect in-memory counter updates on `belongs_to` association (#415)
5
+
6
+ ## 3.10.1 (April 30, 2025)
7
+
8
+ Bugfixes:
9
+ - Fix issue when using `delegate` instead of `has_many :through` (#411)
10
+
1
11
  ## 3.10.0 (April 15, 2025)
2
12
 
3
13
  New features:
@@ -138,7 +138,9 @@ module CounterCulture
138
138
  unless Thread.current[:aggregate_counter_updates]
139
139
  execute_now_or_after_commit(obj) do
140
140
  klass.where(primary_key => id_to_change).update_all updates.join(', ')
141
- assign_to_associated_object(obj, relation, change_counter_column, operator, delta_magnitude)
141
+ unless options[:was]
142
+ assign_to_associated_object(obj, relation, change_counter_column, operator, delta_magnitude)
143
+ end
142
144
  end
143
145
  end
144
146
  end
@@ -370,15 +372,31 @@ module CounterCulture
370
372
  def assign_to_associated_object(obj, relation, change_counter_column, operator, delta_magnitude)
371
373
  association_name = relation_reflect(relation).name
372
374
 
373
- return unless obj.respond_to?(association_name)
375
+ association_object = association_object_for_assign(obj, association_name)
376
+ return if association_object.blank?
374
377
 
375
- if obj.association(association_name).loaded? && (association_object = obj.public_send(association_name)).present?
376
- association_object.assign_attributes(
377
- change_counter_column =>
378
- association_object_new_counter(association_object, change_counter_column, operator, delta_magnitude)
379
- )
380
- association_object_clear_change(association_object, change_counter_column)
378
+ association_object.assign_attributes(
379
+ change_counter_column =>
380
+ association_object_new_counter(association_object, change_counter_column, operator, delta_magnitude)
381
+ )
382
+ association_object_clear_change(association_object, change_counter_column)
383
+ end
384
+
385
+ def association_object_for_assign(obj, association_name)
386
+ if obj.class.reflect_on_all_associations.
387
+ find { |assoc| assoc.name.to_sym == association_name.to_sym }.
388
+ blank?
389
+ # This means that this isn't defined as an association; either it
390
+ # doesn't exist at all, or it uses delegate. In either case, we can't
391
+ # update the count this way.
392
+ return
393
+ end
394
+ if !obj.association(association_name).loaded?
395
+ # If the association isn't loaded, no need to update the count
396
+ return
381
397
  end
398
+
399
+ obj.public_send(association_name)
382
400
  end
383
401
 
384
402
  def association_object_clear_change(association_object, change_counter_column)
@@ -1,3 +1,3 @@
1
1
  module CounterCulture
2
- VERSION = '3.10.0'.freeze
2
+ VERSION = '3.10.2'.freeze
3
3
  end
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: 3.10.0
4
+ version: 3.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus von Koeller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-15 00:00:00.000000000 Z
11
+ date: 2025-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord