dirty_associations 0.2.1 → 0.3.0
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 +4 -4
- data/lib/dirty_associations.rb +10 -8
- data/lib/dirty_associations/version.rb +1 -1
- data/test/dirty_associations_test.rb +15 -10
- data/test/dummy/app/models/bar.rb +1 -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: 7f1871cdecda4666339e95a6ca04c82f51eff5d8
|
4
|
+
data.tar.gz: 326db54144ab7b20cbb9e0e2e9d65349c20ccc90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 002a1955767d7eff828b5fb8859230b78457b1bcf0225fced244267fdc19662c679177f9770fd93c03eed6f4636732d8819794888f15f42ec2ca62b22b5efb87
|
7
|
+
data.tar.gz: 0576f15b928b3670f0e24152e2642fbcf5e487628658fac96686ba4762ac113500cad171c6f72a25068c3e1184854cf3d6831bbfa3919850ab458a2239aef462
|
data/lib/dirty_associations.rb
CHANGED
@@ -14,19 +14,21 @@ module DirtyAssociations
|
|
14
14
|
# The +association+ parameter should be a string or symbol representing the name of an association.
|
15
15
|
def monitor_association_changes(association)
|
16
16
|
ids = "#{association.to_s.singularize}_ids"
|
17
|
-
|
17
|
+
attributes = "#{association.to_s}_attributes"
|
18
|
+
|
19
|
+
[association, ids, attributes].each do |name|
|
18
20
|
define_method "#{name}=" do |value|
|
19
|
-
attribute_will_change!(
|
21
|
+
attribute_will_change!(association)
|
20
22
|
super(value)
|
21
23
|
end
|
22
|
-
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
define_method "#{name}_changed?" do
|
26
|
+
changes.has_key?(association.to_s)
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
define_method "#{name}_previously_changed?" do
|
30
|
+
previous_changes.has_key?(association.to_s)
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -4,42 +4,47 @@ class DirtyAssociationsTest < ActiveSupport::TestCase
|
|
4
4
|
test "setting has_many association adds object to changes" do
|
5
5
|
foo = FactoryGirl.create(:foo)
|
6
6
|
|
7
|
-
refute bar.
|
7
|
+
refute bar.foos_changed?
|
8
8
|
|
9
9
|
bar.foos = [ foo ]
|
10
10
|
assert_equal [ foo ], bar.foos
|
11
|
-
assert bar.
|
11
|
+
assert bar.foos_changed?
|
12
12
|
end
|
13
13
|
|
14
14
|
test "setting has_many association ids adds association to changes" do
|
15
15
|
foo = FactoryGirl.create(:foo)
|
16
16
|
|
17
|
-
refute bar.
|
17
|
+
refute bar.foos_changed?
|
18
18
|
|
19
19
|
bar.foo_ids = [ foo.id ]
|
20
20
|
assert_equal [ foo.id ], bar.foo_ids
|
21
|
-
assert bar.
|
21
|
+
assert bar.foos_changed?
|
22
|
+
end
|
23
|
+
|
24
|
+
test "setting has_many assocation attributes adds association to changes" do
|
25
|
+
bar.assign_attributes(:foos_attributes => [{}, {}])
|
26
|
+
assert bar.foos_changed?
|
22
27
|
end
|
23
28
|
|
24
29
|
test "changes reset by save" do
|
25
30
|
bar.foos = [ FactoryGirl.create(:foo) ]
|
26
|
-
assert bar.
|
31
|
+
assert bar.foos_changed?
|
27
32
|
|
28
33
|
bar.save
|
29
|
-
refute bar.
|
34
|
+
refute bar.foos_changed?
|
30
35
|
end
|
31
36
|
|
32
37
|
test "has_many association appears in previous_changes after save" do
|
33
|
-
refute bar.
|
38
|
+
refute bar.foos_previously_changed?
|
34
39
|
|
35
40
|
bar.foos = [ FactoryGirl.create(:foo) ]
|
36
|
-
refute bar.
|
41
|
+
refute bar.foos_previously_changed?
|
37
42
|
|
38
43
|
bar.save
|
39
|
-
assert bar.
|
44
|
+
assert bar.foos_previously_changed?
|
40
45
|
|
41
46
|
bar.save
|
42
|
-
refute bar.
|
47
|
+
refute bar.foos_previously_changed?
|
43
48
|
end
|
44
49
|
|
45
50
|
private
|
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
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jen Page
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|