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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a65574b97c92c0fe647e9186b3a15ddda3b131c
4
- data.tar.gz: 25aa22d82fc9c76ed6310b4b5605fd49d1a378c9
3
+ metadata.gz: 7f1871cdecda4666339e95a6ca04c82f51eff5d8
4
+ data.tar.gz: 326db54144ab7b20cbb9e0e2e9d65349c20ccc90
5
5
  SHA512:
6
- metadata.gz: 75feb4f410bd61d3e78fea770c8511d8f2ebe1dde334e2c33e7e552c79cb9439decf580b73d47689288d532663fef1596cfd087c3ad72f2341912d32456e1361
7
- data.tar.gz: 29e9e0775a5669199c8eeed9eba2906eb169c7d542f72767ef97ace4d55652094e6e8e419b78749341ce790441484446a50e7291f3edd57933ff2efbad501571
6
+ metadata.gz: 002a1955767d7eff828b5fb8859230b78457b1bcf0225fced244267fdc19662c679177f9770fd93c03eed6f4636732d8819794888f15f42ec2ca62b22b5efb87
7
+ data.tar.gz: 0576f15b928b3670f0e24152e2642fbcf5e487628658fac96686ba4762ac113500cad171c6f72a25068c3e1184854cf3d6831bbfa3919850ab458a2239aef462
@@ -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
- [association, ids].each do |name|
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!(ids)
21
+ attribute_will_change!(association)
20
22
  super(value)
21
23
  end
22
- end
23
24
 
24
- define_method "#{ids}_changed?" do
25
- changed.include?(ids)
26
- end
25
+ define_method "#{name}_changed?" do
26
+ changes.has_key?(association.to_s)
27
+ end
27
28
 
28
- define_method "#{ids}_previously_changed?" do
29
- previous_changes.keys.include?(ids)
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
@@ -1,3 +1,3 @@
1
1
  module DirtyAssociations
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  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.foo_ids_changed?
7
+ refute bar.foos_changed?
8
8
 
9
9
  bar.foos = [ foo ]
10
10
  assert_equal [ foo ], bar.foos
11
- assert bar.foo_ids_changed?
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.foo_ids_changed?
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.foo_ids_changed?
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.foo_ids_changed?
31
+ assert bar.foos_changed?
27
32
 
28
33
  bar.save
29
- refute bar.foo_ids_changed?
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.foo_ids_previously_changed?
38
+ refute bar.foos_previously_changed?
34
39
 
35
40
  bar.foos = [ FactoryGirl.create(:foo) ]
36
- refute bar.foo_ids_previously_changed?
41
+ refute bar.foos_previously_changed?
37
42
 
38
43
  bar.save
39
- assert bar.foo_ids_previously_changed?
44
+ assert bar.foos_previously_changed?
40
45
 
41
46
  bar.save
42
- refute bar.foo_ids_previously_changed?
47
+ refute bar.foos_previously_changed?
43
48
  end
44
49
 
45
50
  private
@@ -3,4 +3,5 @@ class Bar < ActiveRecord::Base
3
3
 
4
4
  has_many :foos
5
5
  monitor_association_changes :foos
6
+ accepts_nested_attributes_for :foos
6
7
  end
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.2.1
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: 2013-11-14 00:00:00.000000000 Z
11
+ date: 2014-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails