dirty_associations 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dirty_associations.rb +10 -1
- data/lib/dirty_associations/version.rb +1 -1
- data/test/dirty_associations_test.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 235e57664229317e7d94b3103ab45193a46d7c83
|
4
|
+
data.tar.gz: 6091ecd6c71b13a533e319e586f4a675d095220c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f08073907f7c908c66ef1e4fc355970998181e428f92891dd2f559fc5fd21ddb83e038fe3e3ab822a3adadddd8ed2ae841cee22d5170de7b08cf3df26171dfc
|
7
|
+
data.tar.gz: f775303a0bfcee934d66b90c569470db022b79ef10a8612b3664b5d421fc95b320de1e96065806cc8fef04ef64fc38f384c438e7c38430c4881162e4c4d996bb
|
data/lib/dirty_associations.rb
CHANGED
@@ -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
|
@@ -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.
|
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-
|
11
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|