active_model_archive 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "active_model_archive"
5
- s.version = '0.9.0'
5
+ s.version = '0.9.1'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Grant Rodgers"]
8
8
  s.email = ["grantr@gmail.com"]
@@ -12,7 +12,9 @@ module ActiveModelArchive
12
12
 
13
13
  def each_instance(io)
14
14
  each_archive(io) do |hash|
15
- yield new(hash)
15
+ attributes = {}
16
+ valid_archive_keys.each { |key| attributes[key] = hash[key] }
17
+ yield new(attributes)
16
18
  end
17
19
  end
18
20
 
@@ -33,6 +35,10 @@ module ActiveModelArchive
33
35
 
34
36
  count
35
37
  end
38
+
39
+ def valid_archive_keys
40
+ @valid_archive_keys ||= new.attributes.keys
41
+ end
36
42
  end
37
43
  end
38
44
  end
data/test/restore_test.rb CHANGED
@@ -33,20 +33,39 @@ class ActiveModelArchive::RestoreTest < MiniTest::Spec
33
33
 
34
34
  def test_each_instance
35
35
  json_io = StringIO.new %{
36
- {
37
- "id": 42,
38
- "color": "green"
39
- }
40
- }
36
+ {
37
+ "id": 42,
38
+ "color": "green"
39
+ }
40
+ }
41
+
42
+ results = []
43
+ TestModel.each_instance(json_io) do |object|
44
+ results << object
45
+ end
46
+
47
+ assert_equal 1, results.size
48
+ assert_equal 42, results.first.id
49
+ assert_equal 'green', results.first.color
50
+ end
41
51
 
42
- results = []
43
- TestModel.each_instance(json_io) do |object|
44
- results << object
45
- end
52
+ def test_each_instance_slices_attributes
53
+ assert_raises NoMethodError do
54
+ TestModel.new foo: 'bar', color: 'green'
55
+ end
56
+
57
+ json_io = StringIO.new %{
58
+ {
59
+ "foo": "bar",
60
+ "color": "green"
61
+ }
62
+ }
46
63
 
47
- assert_equal 1, results.size
48
- assert_equal 42, results.first.id
49
- assert_equal 'green', results.first.color
64
+ results = []
65
+ TestModel.each_instance(json_io) do |object|
66
+ results << object
67
+ end
68
+ assert_equal 'green', results.first.color
50
69
  end
51
70
 
52
71
  def test_restore!
data/test/test_helper.rb CHANGED
@@ -14,6 +14,7 @@ class TestModel
14
14
 
15
15
  def initialize(attrs = {})
16
16
  @attributes = {}
17
+
17
18
  self.attributes = attrs
18
19
  end
19
20
 
@@ -21,16 +22,28 @@ class TestModel
21
22
  @attributes['id']
22
23
  end
23
24
 
25
+ def id=(val)
26
+ @attributes['id'] = val
27
+ end
28
+
24
29
  def color
25
30
  @attributes['color']
26
31
  end
27
32
 
33
+ def color=(val)
34
+ @attributes['color'] = val
35
+ end
36
+
28
37
  def attributes=(attrs)
29
- @attributes['color'] = attrs[:color] || attrs['color']
30
- @attributes['id'] = attrs[:id] || attrs['id']
38
+ attrs.each do |key, value|
39
+ send("#{key}=", value)
40
+ end
31
41
  end
32
42
 
33
43
  def attributes
34
- @attributes
44
+ {
45
+ 'id' => id,
46
+ 'color' => color
47
+ }
35
48
  end
36
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_archive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70251111770820 !ruby/object:Gem::Requirement
16
+ requirement: &70351174947160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70251111770820
24
+ version_requirements: *70351174947160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yajl-ruby
27
- requirement: &70251111770120 !ruby/object:Gem::Requirement
27
+ requirement: &70351174946320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70251111770120
35
+ version_requirements: *70351174946320
36
36
  description: Adds dump and restore functionality to activemodel classes
37
37
  email:
38
38
  - grantr@gmail.com