has_versions 0.7.0 → 0.7.1

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.7.0'
4
+ s.version = '0.7.1'
5
5
 
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Grant Rodgers"]
@@ -10,11 +10,14 @@ module HasVersions
10
10
  end
11
11
 
12
12
  def versioned_attributes
13
- self.class.versioned_attributes.inject({}) do |memo, attribute|
14
- if (value = send(attribute)).present?
15
- memo[attribute] = versioning_encode_value(attribute, value)
16
- end
17
- memo
13
+ create_versioned_attributes do |attribute|
14
+ send(attribute)
15
+ end
16
+ end
17
+
18
+ def versioned_attributes_was
19
+ create_versioned_attributes do |attribute|
20
+ send("#{attribute}_was")
18
21
  end
19
22
  end
20
23
 
@@ -25,6 +28,16 @@ module HasVersions
25
28
  nil
26
29
  end
27
30
  end
31
+
32
+ private
33
+ def create_versioned_attributes(&block)
34
+ self.class.versioned_attributes.inject({}) do |memo, attribute|
35
+ if (value = block.call(attribute)).present?
36
+ memo[attribute] = versioning_encode_value(attribute, value)
37
+ end
38
+ memo
39
+ end
40
+ end
28
41
  end
29
42
  end
30
43
  end
@@ -25,6 +25,13 @@ module HasVersions
25
25
  assert_equal expected, record.versioned_attributes
26
26
  end
27
27
 
28
+ # def test_instance_versioned_attributes_was
29
+ # record = VersionedRecord.new(name: 'joe', price: nil, weight: 142.0, color: 'green')
30
+ # expected = {'name' => 'joe', 'weight' => '142.0'}
31
+ #
32
+ # assert_equal expected, record.versioned_attributes_was
33
+ # end
34
+
28
35
  def test_associated_versions_when_defined
29
36
  model = Class.new(VersionedRecord) do
30
37
  versioning_configuration.associated_versions do
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.7.0
4
+ version: 0.7.1
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-09-21 00:00:00.000000000 Z
12
+ date: 2012-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport