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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 144d5fbf2df2d63302aba0a2492629817f6d2c56
4
- data.tar.gz: c2f2672f06a326665b9b1ad69cb816d765d6c105
3
+ metadata.gz: 483254dc425f015ad634c390fed0da2da47a5ce8
4
+ data.tar.gz: 4762ef0f13da2607302ec7da25da793fb5b1699c
5
5
  SHA512:
6
- metadata.gz: dac4225f3b0c3b3994342f1ed435c4b6ae4503b3963e60d21434f974c13b12622ce421d96f981156d63b59a94d5ce2be7f6dc7e0b225d14e00581c8423d86963
7
- data.tar.gz: d9371103866e97e4292b9fb7d1cb850737a8d75e34ffe2869dd11072f58feb60280fa32d40b86f8499a7da218b3f2f5ada03770191976ea79873458f377d1d93
6
+ metadata.gz: d3f94c48d05492a4c329543d00f4e97e72f47c620352b8acfa71e03d75dc4f4c6bcd96b8248970c491808c97e2e18710e4fa7461bf6afb4d02acede108e76d7e
7
+ data.tar.gz: 3934e31a415eab2da16340d3adcf647d4554264973263304c51dce40f24813be1ca3c9d32a3931e40c812b035a6a77acf3d69c69fd6e73711e4ca6d2d333b546
@@ -1,3 +1,3 @@
1
1
  module TableDiffer
2
- VERSION = "0.6.6"
2
+ VERSION = "0.6.8"
3
3
  end
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.select { |a| removed.find { |r| a.id == r.id }}
106
+ changed = added & removed
104
107
  changed.each do |obj|
105
- orig = removed.find { |r| r.id == obj.id }
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.reject! { |r| changed.find { |c| r.id == c.id }}
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'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_differ
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Bronson