active_record-json_associations 0.9.0 → 0.9.1

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
  SHA256:
3
- metadata.gz: 82a8dd8639c2897e523652a7415754704227798f98e753681d0199cc70ec055d
4
- data.tar.gz: bf59af54b968501e6b087a65ba7d95b5783fe5ec20c4c41182b5882bbdb9604d
3
+ metadata.gz: e03d284df9e4faf9319475962d17aee50025fc58407f1cb641819c070958eca6
4
+ data.tar.gz: 026dff5c42712728a8c85a59e413265f3c1c09922ec1fc366fee5db3404fb42a
5
5
  SHA512:
6
- metadata.gz: 1fbc06fdc2cd8dbf92bc5d336ab5d1b1dc45f393e26ae47e45573f346be04912544dee4b31097a3fa1767ce1981c05fa5eb046fd5428947afd9cfeb90cf9827c
7
- data.tar.gz: 402f51353a4b4865e67ae982cc4794aa60658e2afc3e97c1c8faf3eb03f93ed0306020b4618dc870e62aa34c184d85dd3e424b647254bedaf5436b92a7af0199
6
+ metadata.gz: 449f81549f3ed177a88ce17070a92b2f6b07f252193ab1cf64d706d51c85d9065f636af21242bd3a689f1b2402384d2d0487c58cc74de1f07b1c3f441da3b34d
7
+ data.tar.gz: 5dea4c68f936961403ca768f7775795fe810df3e811cadb147901faa0e2e5313512853aed0d5bdaaabefafaeb60f9cdc3375d5d5d986ca2cde42be6759b94125
@@ -24,12 +24,9 @@ module ActiveRecord
24
24
 
25
25
  if touch
26
26
  after_commit do
27
- if respond_to?(:saved_changes)
28
- old_ids, new_ids = saved_changes[one_ids.to_s]
29
- else
30
- old_ids, new_ids = previous_changes[one_ids.to_s]
31
- end
32
- ids = Array(old_ids) | Array(new_ids)
27
+ method = respond_to?(:saved_changes) ? :saved_changes : :previous_changes
28
+ old_ids, new_ids = send(method)[one_ids.to_s]
29
+ ids = Array(send(one_ids)) | Array(old_ids) | Array(new_ids)
33
30
  scope = class_name.constantize.where(self.class.primary_key => ids)
34
31
 
35
32
  if scope.respond_to?(:touch) # AR 6.0+
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module JsonAssociations
3
- VERSION = "0.9.0"
3
+ VERSION = "0.9.1"
4
4
  end
5
5
  end
@@ -153,7 +153,7 @@ describe ActiveRecord::JsonAssociations do
153
153
  end
154
154
  end
155
155
 
156
- it "touches associated records" do
156
+ it "touches records associated upon creation" do
157
157
  children = [Child.create!(updated_at: old_time), Child.create!(updated_at: old_time)]
158
158
  fuzzies = [Pet.create!(updated_at: old_time), Pet.create!(updated_at: old_time)]
159
159
  parent = Parent.create!(children: children, fuzzies: fuzzies)
@@ -161,6 +161,14 @@ describe ActiveRecord::JsonAssociations do
161
161
  expect(fuzzies.each(&:reload).map(&:updated_at)).to eq [old_time, old_time] # touch: nil
162
162
  end
163
163
 
164
+ it "touches exising association records" do
165
+ children = [Child.create!, Child.create!]
166
+ parent = Parent.create!(children: children)
167
+ children.each { |child| child.update!(updated_at: old_time) }
168
+ parent.save!
169
+ expect(children.each(&:reload).map(&:updated_at)).to eq [new_time, new_time]
170
+ end
171
+
164
172
  it "touches removed associated records" do
165
173
  peter, paul, mary = Child.create!, Child.create!, Child.create!
166
174
  parent = Parent.create!(children: [peter, paul, mary])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-json_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-20 00:00:00.000000000 Z
11
+ date: 2021-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord