dirty_associations 0.4.2 → 0.4.3

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
  SHA1:
3
- metadata.gz: 046bdd6028e751c1eb05042bd2e592bb56e6ea7d
4
- data.tar.gz: 9a2d0d5a75467af5355f464e79823192adb4bd61
3
+ metadata.gz: 235e57664229317e7d94b3103ab45193a46d7c83
4
+ data.tar.gz: 6091ecd6c71b13a533e319e586f4a675d095220c
5
5
  SHA512:
6
- metadata.gz: e2ff66d8d3b18a90dc006bf8c8e3b8cf6ef3db0966f426800dc4fb265c4c42c2805945063c6884c0fe2b4033e47c6dc3cd2cde66981c7105bcec11b59ae0ddc7
7
- data.tar.gz: 4f247e7bc2c217d9c9342025de69662b49d5c07197a023f29bbe77cdb242505a58e5a74af8b80516c60081acb11453548484fb45d51c68de7e9d658a4fccaf9d
6
+ metadata.gz: 6f08073907f7c908c66ef1e4fc355970998181e428f92891dd2f559fc5fd21ddb83e038fe3e3ab822a3adadddd8ed2ae841cee22d5170de7b08cf3df26171dfc
7
+ data.tar.gz: f775303a0bfcee934d66b90c569470db022b79ef10a8612b3664b5d421fc95b320de1e96065806cc8fef04ef64fc38f384c438e7c38430c4881162e4c4d996bb
@@ -26,7 +26,7 @@ module DirtyAssociations
26
26
  end
27
27
 
28
28
  define_method "#{association}_attributes=" do |value|
29
- attribute_will_change!(association.to_s)
29
+ attribute_will_change!(association.to_s) if _nested_attributes_will_change?(value)
30
30
  super(value)
31
31
  end
32
32
 
@@ -56,4 +56,13 @@ module DirtyAssociations
56
56
  value = Array(value).reject &:blank?
57
57
  send(ids) != value
58
58
  end
59
+
60
+ def _nested_attributes_will_change?(attributes_collection)
61
+ return false unless attributes_collection.is_a?(Array) || attributes_collection.is_a?(Hash)
62
+ attributes_collection = attributes_collection.values if attributes_collection.is_a? Hash
63
+
64
+ # Only consider additions to be a change, i.e. attributes hashes with no id. Editing or destroying a
65
+ # nested model can be detected by belongs_to :touch => true on the nested model class.
66
+ attributes_collection.any? { |a| a[:id].blank? && a["id"].blank?}
67
+ end
59
68
  end
@@ -1,3 +1,3 @@
1
1
  module DirtyAssociations
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -53,6 +53,11 @@ class DirtyAssociationsTest < ActiveSupport::TestCase
53
53
  assert bar.foos_changed?
54
54
  end
55
55
 
56
+ test "editing has_many assocation attributes does not count as a change" do
57
+ bar.assign_attributes(:foos_attributes => [{ :id => bar.foos.first.id }])
58
+ refute bar.foos_changed?
59
+ end
60
+
56
61
  test "changes reset by save" do
57
62
  bar.foos = [ FactoryGirl.create(:foo) ]
58
63
  assert bar.foos_changed?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dirty_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jen Page
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-07 00:00:00.000000000 Z
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails