has_versions 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/has_versions.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "has_versions"
4
- s.version = '0.6.2'
4
+ s.version = '0.6.3'
5
5
 
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Grant Rodgers"]
@@ -1,16 +1,16 @@
1
1
  module HasVersions
2
2
  module Version
3
3
  module Diff
4
- def diff(original = parent)
5
- diff_fetch(original) do
6
- original_snapshot = original.nil? ? {} : original.decoded_snapshot
4
+ def diff(other = parent)
5
+ diff_fetch(other) do
6
+ other_snapshot = other.nil? ? {} : other.decoded_snapshot
7
7
 
8
8
  output = {}
9
9
  decoded_snapshot.each do |attribute, new_value|
10
- original_value = original_snapshot[attribute]
10
+ other_value = other_snapshot[attribute]
11
11
 
12
- if original_value != new_value
13
- output[attribute] = [original_value, new_value]
12
+ if other_value != new_value
13
+ output[attribute] = [other_value, new_value]
14
14
  end
15
15
  end
16
16
 
@@ -18,14 +18,12 @@ module HasVersions
18
18
  end
19
19
  end
20
20
 
21
- def modified_attributes
22
- diff.keys
21
+ def applied_modifications(other)
22
+ diff.keys - diff(other).keys
23
23
  end
24
24
 
25
- def different_attributes
26
- modified_attributes.select do |attribute|
27
- target.send(attribute) != decoded_snapshot[attribute]
28
- end
25
+ def unused_modifications(other)
26
+ diff.keys & diff(other).keys
29
27
  end
30
28
 
31
29
  def decoded_snapshot
@@ -39,9 +37,9 @@ module HasVersions
39
37
  end
40
38
 
41
39
  private
42
- def diff_fetch(original)
40
+ def diff_fetch(other)
43
41
  @diff_cache ||= {}
44
- @diff_cache[original] ||= yield
42
+ @diff_cache[other] ||= yield
45
43
  end
46
44
  end
47
45
  end
@@ -45,18 +45,14 @@ module HasVersions
45
45
  assert_equal({'name' => [nil, 'decoded: bar'], 'weight' => [nil, 'decoded: 4.3']}, diff)
46
46
  end
47
47
 
48
- def test_modified_attributes
48
+ def test_modifications
49
49
  target = DiffRecord.new
50
- version = DiffRecord.version_model.new(target: target, snapshot: {'name' => 'joe', 'weight' => '129'})
51
-
52
- assert_equal version.snapshot.keys, version.modified_attributes
53
- end
54
-
55
- def test_different_attributes
56
- target = DiffRecord.new(name: 'decoded: sam', color: 'decoded: green', weight: 'decoded: 129')
57
- version = DiffRecord.version_model.new(target: target, snapshot: {'name' => 'joe', 'weight' => '129'})
58
-
59
- assert_equal ['name'], version.different_attributes
50
+ parent = DiffRecord.version_model.new(target: target, snapshot: {'color' => 'green', 'name' => 'joe', 'weight' => '50'})
51
+ version = DiffRecord.version_model.new(target: target, parent: parent, snapshot: {'color' => 'green', 'name' => 'sam', 'weight' => '129'})
52
+ other = DiffRecord.version_model.new(target: target, snapshot: {'color' => 'blue', 'name' => 'sam', 'weight' => '100'})
53
+
54
+ assert_equal ['name'], version.applied_modifications(other)
55
+ assert_equal ['weight'], version.unused_modifications(other)
60
56
  end
61
57
 
62
58
  def test_decoded_snapshot
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_versions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-26 00:00:00.000000000 Z
12
+ date: 2012-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport