table_differ 0.6.6 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/table_differ/version.rb +1 -1
- data/lib/table_differ.rb +6 -3
- data/spec/remap_spec.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 483254dc425f015ad634c390fed0da2da47a5ce8
|
4
|
+
data.tar.gz: 4762ef0f13da2607302ec7da25da793fb5b1699c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3f94c48d05492a4c329543d00f4e97e72f47c620352b8acfa71e03d75dc4f4c6bcd96b8248970c491808c97e2e18710e4fa7461bf6afb4d02acede108e76d7e
|
7
|
+
data.tar.gz: 3934e31a415eab2da16340d3adcf647d4554264973263304c51dce40f24813be1ca3c9d32a3931e40c812b035a6a77acf3d69c69fd6e73711e4ca6d2d333b546
|
data/lib/table_differ/version.rb
CHANGED
data/lib/table_differ.rb
CHANGED
@@ -64,6 +64,9 @@ module TableDiffer
|
|
64
64
|
args = params.inject({}) { |hash,key| hash[key] = record[key]; hash }
|
65
65
|
real_record = model.where(args).first
|
66
66
|
if real_record
|
67
|
+
if model != self
|
68
|
+
real_record = self.new(real_record.attributes) # convert fake model to real model
|
69
|
+
end
|
67
70
|
real_record.original_attributes = record.attributes
|
68
71
|
result = real_record
|
69
72
|
end
|
@@ -100,15 +103,15 @@ module TableDiffer
|
|
100
103
|
removed = table_differ_remap_objects(options[:unique_by], removed, oldtable)
|
101
104
|
end
|
102
105
|
|
103
|
-
changed = added
|
106
|
+
changed = added & removed
|
104
107
|
changed.each do |obj|
|
105
|
-
orig = removed.find { |r| r
|
108
|
+
orig = removed.find { |r| r == obj }
|
106
109
|
raise "this is impossible" if orig.nil?
|
107
110
|
obj.original_attributes = (orig.original_attributes || orig.attributes).except(*ignore)
|
108
111
|
end
|
109
112
|
|
110
113
|
added -= changed
|
111
|
-
removed
|
114
|
+
removed -= changed
|
112
115
|
[*added, *removed].each { |o| o.original_attributes = nil }
|
113
116
|
|
114
117
|
[added, removed, changed]
|
data/spec/remap_spec.rb
CHANGED
@@ -17,7 +17,8 @@ describe "diffing a model" do
|
|
17
17
|
# we can find added and changed records by surrogate IDs but, of course, can't find removed ones
|
18
18
|
expect(added).to eq [third]
|
19
19
|
expect(added.first.original_attributes).to eq nil
|
20
|
-
expect(removed.map(&:attributes)).to eq [{"id" => secid, "name" => "two", "original_name" => "two", "alternate_value" => nil}]
|
20
|
+
# expect(removed.map(&:attributes)).to eq [{"id" => secid, "name" => "two", "original_name" => "two", "alternate_value" => nil}]
|
21
|
+
expect(removed).to eq [second]
|
21
22
|
expect(removed.first.original_attributes).to eq nil
|
22
23
|
expect(changed).to eq [first]
|
23
24
|
expect(changed.first.name).to eq 'uno'
|