nokogiri-happymapper 0.8.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/README.md +1 -4
  4. data/lib/happymapper/anonymous_mapper.rb +6 -5
  5. data/lib/happymapper/class_methods.rb +466 -0
  6. data/lib/happymapper/element.rb +3 -3
  7. data/lib/happymapper/item.rb +19 -13
  8. data/lib/happymapper/supported_types.rb +4 -6
  9. data/lib/happymapper/syntax_error.rb +6 -0
  10. data/lib/happymapper/version.rb +1 -1
  11. data/lib/happymapper.rb +54 -505
  12. data/lib/nokogiri-happymapper.rb +1 -1
  13. metadata +100 -107
  14. data/spec/features/after_parse_callbacks_spec.rb +0 -32
  15. data/spec/features/attribute_default_value_spec.rb +0 -48
  16. data/spec/features/attributes_spec.rb +0 -35
  17. data/spec/features/has_many_empty_array_spec.rb +0 -44
  18. data/spec/features/ignay_spec.rb +0 -92
  19. data/spec/features/inheritance_spec.rb +0 -121
  20. data/spec/features/mixed_namespaces_spec.rb +0 -60
  21. data/spec/features/parse_with_object_to_update_spec.rb +0 -116
  22. data/spec/features/same_tag_different_meaning_spec.rb +0 -44
  23. data/spec/features/to_xml_spec.rb +0 -205
  24. data/spec/features/to_xml_with_namespaces_spec.rb +0 -237
  25. data/spec/features/wildcard_tag_name_spec.rb +0 -110
  26. data/spec/features/wrap_spec.rb +0 -87
  27. data/spec/features/xpath_spec.rb +0 -84
  28. data/spec/fixtures/address.xml +0 -9
  29. data/spec/fixtures/ambigous_items.xml +0 -22
  30. data/spec/fixtures/analytics.xml +0 -61
  31. data/spec/fixtures/analytics_profile.xml +0 -127
  32. data/spec/fixtures/atom.xml +0 -19
  33. data/spec/fixtures/commit.xml +0 -52
  34. data/spec/fixtures/current_weather.xml +0 -89
  35. data/spec/fixtures/current_weather_missing_elements.xml +0 -18
  36. data/spec/fixtures/default_namespace_combi.xml +0 -6
  37. data/spec/fixtures/dictionary.xml +0 -20
  38. data/spec/fixtures/family_tree.xml +0 -21
  39. data/spec/fixtures/inagy.xml +0 -85
  40. data/spec/fixtures/lastfm.xml +0 -355
  41. data/spec/fixtures/multiple_namespaces.xml +0 -170
  42. data/spec/fixtures/multiple_primitives.xml +0 -5
  43. data/spec/fixtures/optional_attributes.xml +0 -6
  44. data/spec/fixtures/pita.xml +0 -133
  45. data/spec/fixtures/posts.xml +0 -23
  46. data/spec/fixtures/product_default_namespace.xml +0 -18
  47. data/spec/fixtures/product_no_namespace.xml +0 -10
  48. data/spec/fixtures/product_single_namespace.xml +0 -10
  49. data/spec/fixtures/quarters.xml +0 -19
  50. data/spec/fixtures/radar.xml +0 -21
  51. data/spec/fixtures/set_config_options.xml +0 -3
  52. data/spec/fixtures/statuses.xml +0 -422
  53. data/spec/fixtures/subclass_namespace.xml +0 -50
  54. data/spec/fixtures/unformatted_address.xml +0 -1
  55. data/spec/fixtures/wrapper.xml +0 -11
  56. data/spec/happymapper/anonymous_mapper_spec.rb +0 -158
  57. data/spec/happymapper/attribute_spec.rb +0 -12
  58. data/spec/happymapper/item_spec.rb +0 -177
  59. data/spec/happymapper_spec.rb +0 -1208
  60. data/spec/spec_helper.rb +0 -25
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri-happymapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Le Berrigaud
@@ -11,10 +11,10 @@ authors:
11
11
  - Etienne Vallette d'Osia
12
12
  - Franklin Webber
13
13
  - Matijs van Zuijlen
14
- autorequire:
14
+ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2019-03-18 00:00:00.000000000 Z
17
+ date: 2024-01-05 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: nokogiri
@@ -30,20 +30,48 @@ dependencies:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '1.5'
33
+ - !ruby/object:Gem::Dependency
34
+ name: pry
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.14.0
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.14.0
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: rake
35
49
  requirement: !ruby/object:Gem::Requirement
36
50
  requirements:
37
51
  - - "~>"
38
52
  - !ruby/object:Gem::Version
39
- version: '12.0'
53
+ version: '13.0'
40
54
  type: :development
41
55
  prerelease: false
42
56
  version_requirements: !ruby/object:Gem::Requirement
43
57
  requirements:
44
58
  - - "~>"
45
59
  - !ruby/object:Gem::Version
46
- version: '12.0'
60
+ version: '13.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake-manifest
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.2.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.2.0
47
75
  - !ruby/object:Gem::Dependency
48
76
  name: rspec
49
77
  requirement: !ruby/object:Gem::Requirement
@@ -58,20 +86,76 @@ dependencies:
58
86
  - - "~>"
59
87
  - !ruby/object:Gem::Version
60
88
  version: '3.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.56'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.56'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop-packaging
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.5.2
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.5.2
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop-performance
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.19'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '1.19'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rubocop-rspec
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '2.24'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '2.24'
61
145
  - !ruby/object:Gem::Dependency
62
146
  name: simplecov
63
147
  requirement: !ruby/object:Gem::Requirement
64
148
  requirements:
65
149
  - - "~>"
66
150
  - !ruby/object:Gem::Version
67
- version: 0.16.1
151
+ version: 0.22.0
68
152
  type: :development
69
153
  prerelease: false
70
154
  version_requirements: !ruby/object:Gem::Requirement
71
155
  requirements:
72
156
  - - "~>"
73
157
  - !ruby/object:Gem::Version
74
- version: 0.16.1
158
+ version: 0.22.0
75
159
  description: Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's
76
160
  Happymapper)
77
161
  email: matijs@matijs.net
@@ -88,64 +172,20 @@ files:
88
172
  - lib/happymapper.rb
89
173
  - lib/happymapper/anonymous_mapper.rb
90
174
  - lib/happymapper/attribute.rb
175
+ - lib/happymapper/class_methods.rb
91
176
  - lib/happymapper/element.rb
92
177
  - lib/happymapper/item.rb
93
178
  - lib/happymapper/supported_types.rb
179
+ - lib/happymapper/syntax_error.rb
94
180
  - lib/happymapper/text_node.rb
95
181
  - lib/happymapper/version.rb
96
182
  - lib/nokogiri-happymapper.rb
97
- - spec/features/after_parse_callbacks_spec.rb
98
- - spec/features/attribute_default_value_spec.rb
99
- - spec/features/attributes_spec.rb
100
- - spec/features/has_many_empty_array_spec.rb
101
- - spec/features/ignay_spec.rb
102
- - spec/features/inheritance_spec.rb
103
- - spec/features/mixed_namespaces_spec.rb
104
- - spec/features/parse_with_object_to_update_spec.rb
105
- - spec/features/same_tag_different_meaning_spec.rb
106
- - spec/features/to_xml_spec.rb
107
- - spec/features/to_xml_with_namespaces_spec.rb
108
- - spec/features/wildcard_tag_name_spec.rb
109
- - spec/features/wrap_spec.rb
110
- - spec/features/xpath_spec.rb
111
- - spec/fixtures/address.xml
112
- - spec/fixtures/ambigous_items.xml
113
- - spec/fixtures/analytics.xml
114
- - spec/fixtures/analytics_profile.xml
115
- - spec/fixtures/atom.xml
116
- - spec/fixtures/commit.xml
117
- - spec/fixtures/current_weather.xml
118
- - spec/fixtures/current_weather_missing_elements.xml
119
- - spec/fixtures/default_namespace_combi.xml
120
- - spec/fixtures/dictionary.xml
121
- - spec/fixtures/family_tree.xml
122
- - spec/fixtures/inagy.xml
123
- - spec/fixtures/lastfm.xml
124
- - spec/fixtures/multiple_namespaces.xml
125
- - spec/fixtures/multiple_primitives.xml
126
- - spec/fixtures/optional_attributes.xml
127
- - spec/fixtures/pita.xml
128
- - spec/fixtures/posts.xml
129
- - spec/fixtures/product_default_namespace.xml
130
- - spec/fixtures/product_no_namespace.xml
131
- - spec/fixtures/product_single_namespace.xml
132
- - spec/fixtures/quarters.xml
133
- - spec/fixtures/radar.xml
134
- - spec/fixtures/set_config_options.xml
135
- - spec/fixtures/statuses.xml
136
- - spec/fixtures/subclass_namespace.xml
137
- - spec/fixtures/unformatted_address.xml
138
- - spec/fixtures/wrapper.xml
139
- - spec/happymapper/anonymous_mapper_spec.rb
140
- - spec/happymapper/attribute_spec.rb
141
- - spec/happymapper/item_spec.rb
142
- - spec/happymapper_spec.rb
143
- - spec/spec_helper.rb
144
183
  homepage: http://github.com/mvz/happymapper
145
184
  licenses:
146
185
  - MIT
147
- metadata: {}
148
- post_install_message:
186
+ metadata:
187
+ rubygems_mfa_required: 'true'
188
+ post_install_message:
149
189
  rdoc_options: []
150
190
  require_paths:
151
191
  - lib
@@ -153,62 +193,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
193
  requirements:
154
194
  - - ">="
155
195
  - !ruby/object:Gem::Version
156
- version: 2.3.0
196
+ version: 3.0.0
157
197
  required_rubygems_version: !ruby/object:Gem::Requirement
158
198
  requirements:
159
199
  - - ">="
160
200
  - !ruby/object:Gem::Version
161
201
  version: '0'
162
202
  requirements: []
163
- rubygems_version: 3.0.3
164
- signing_key:
203
+ rubygems_version: 3.5.3
204
+ signing_key:
165
205
  specification_version: 4
166
206
  summary: Provides a simple way to map XML to Ruby Objects and back again.
167
- test_files:
168
- - spec/features/after_parse_callbacks_spec.rb
169
- - spec/features/attribute_default_value_spec.rb
170
- - spec/features/attributes_spec.rb
171
- - spec/features/has_many_empty_array_spec.rb
172
- - spec/features/ignay_spec.rb
173
- - spec/features/inheritance_spec.rb
174
- - spec/features/mixed_namespaces_spec.rb
175
- - spec/features/parse_with_object_to_update_spec.rb
176
- - spec/features/same_tag_different_meaning_spec.rb
177
- - spec/features/to_xml_spec.rb
178
- - spec/features/to_xml_with_namespaces_spec.rb
179
- - spec/features/wildcard_tag_name_spec.rb
180
- - spec/features/wrap_spec.rb
181
- - spec/features/xpath_spec.rb
182
- - spec/fixtures/address.xml
183
- - spec/fixtures/ambigous_items.xml
184
- - spec/fixtures/analytics.xml
185
- - spec/fixtures/analytics_profile.xml
186
- - spec/fixtures/atom.xml
187
- - spec/fixtures/commit.xml
188
- - spec/fixtures/current_weather.xml
189
- - spec/fixtures/current_weather_missing_elements.xml
190
- - spec/fixtures/default_namespace_combi.xml
191
- - spec/fixtures/dictionary.xml
192
- - spec/fixtures/family_tree.xml
193
- - spec/fixtures/inagy.xml
194
- - spec/fixtures/lastfm.xml
195
- - spec/fixtures/multiple_namespaces.xml
196
- - spec/fixtures/multiple_primitives.xml
197
- - spec/fixtures/optional_attributes.xml
198
- - spec/fixtures/pita.xml
199
- - spec/fixtures/posts.xml
200
- - spec/fixtures/product_default_namespace.xml
201
- - spec/fixtures/product_no_namespace.xml
202
- - spec/fixtures/product_single_namespace.xml
203
- - spec/fixtures/quarters.xml
204
- - spec/fixtures/radar.xml
205
- - spec/fixtures/set_config_options.xml
206
- - spec/fixtures/statuses.xml
207
- - spec/fixtures/subclass_namespace.xml
208
- - spec/fixtures/unformatted_address.xml
209
- - spec/fixtures/wrapper.xml
210
- - spec/happymapper/anonymous_mapper_spec.rb
211
- - spec/happymapper/attribute_spec.rb
212
- - spec/happymapper/item_spec.rb
213
- - spec/happymapper_spec.rb
214
- - spec/spec_helper.rb
207
+ test_files: []
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'after_parse callbacks', type: :feature do
6
- module AfterParseSpec
7
- class Address
8
- include HappyMapper
9
- element :street, String
10
- end
11
- end
12
-
13
- after do
14
- AfterParseSpec::Address.after_parse_callbacks.clear
15
- end
16
-
17
- it 'callbacks with the newly created object' do
18
- from_cb = nil
19
- called = false
20
- cb1 = proc { |object| from_cb = object }
21
- cb2 = proc { called = true }
22
- AfterParseSpec::Address.after_parse(&cb1)
23
- AfterParseSpec::Address.after_parse(&cb2)
24
-
25
- object = AfterParseSpec::Address.parse fixture_file('address.xml')
26
-
27
- aggregate_failures do
28
- expect(from_cb).to eq(object)
29
- expect(called).to eq(true)
30
- end
31
- end
32
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'Attribute Default Value', type: :feature do
6
- context 'when given a default value' do
7
- class Meal
8
- include HappyMapper
9
- tag 'meal'
10
- attribute :type, String, default: 'omnivore'
11
- end
12
-
13
- let(:default_meal_type) { 'omnivore' }
14
-
15
- context 'when no value has been specified' do
16
- it 'returns the default value' do
17
- meal = Meal.parse('<meal />')
18
- expect(meal.type).to eq default_meal_type
19
- end
20
- end
21
-
22
- context 'when saving to xml' do
23
- let(:expected_xml) { %(<?xml version="1.0"?>\n<meal/>\n) }
24
-
25
- it 'the default value is not included' do
26
- meal = Meal.new
27
- expect(meal.to_xml).to eq expected_xml
28
- end
29
- end
30
-
31
- context 'when a new, non-nil value has been set' do
32
- let(:expected_xml) { %(<?xml version="1.0"?>\n<meal type="kosher"/>\n) }
33
-
34
- it 'returns the new value' do
35
- meal = Meal.parse('<meal />')
36
- meal.type = 'vegan'
37
-
38
- expect(meal.type).not_to eq default_meal_type
39
- end
40
-
41
- it 'saves the new value to the xml' do
42
- meal = Meal.new
43
- meal.type = 'kosher'
44
- expect(meal.to_xml).to eq expected_xml
45
- end
46
- end
47
- end
48
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'Attribute Method Conversion', type: :feature do
6
- module AttributeMethodConversion
7
- class Document
8
- include HappyMapper
9
-
10
- has_many :link, String, attributes: { 'data-src': String, type: String, href: String }
11
- end
12
- end
13
-
14
- let(:xml_document) do
15
- %(<document>
16
- <link data-src='http://cooking.com/roastbeef' type='recipe'>Roast Beef</link>
17
- </document>)
18
- end
19
-
20
- let(:document) do
21
- AttributeMethodConversion::Document.parse(xml_document, single: true)
22
- end
23
-
24
- it 'link' do
25
- expect(document.link).to eq ['Roast Beef']
26
- end
27
-
28
- it 'link.data_src' do
29
- expect(document.link.first.data_src).to eq 'http://cooking.com/roastbeef'
30
- end
31
-
32
- it 'link.type' do
33
- expect(document.link.first.type).to eq 'recipe'
34
- end
35
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Sheep
6
- class Item
7
- include HappyMapper
8
- end
9
-
10
- class Navigator
11
- include HappyMapper
12
- tag 'navigator'
13
-
14
- # This is purposefully set to have the name 'items' with the tag 'item'.
15
- # The idea is that it should not find the empty items contained within the
16
- # xml and return an empty array. This exercises the order of how nodes
17
- # are searched for within an XML document.
18
- has_many :items, Item, tag: 'item'
19
-
20
- has_many :items_with_a_different_name, Item, tag: 'item'
21
- end
22
- end
23
-
24
- RSpec.describe 'empty arrays of items based on tags', type: :feature do
25
- let(:xml) do
26
- <<-XML
27
- <navigator>
28
- <items/>
29
- </navigator>
30
- XML
31
- end
32
-
33
- let(:navigator) do
34
- Sheep::Navigator.parse(xml)
35
- end
36
-
37
- it 'returns an empty array' do
38
- expect(navigator.items_with_a_different_name).to be_empty
39
- end
40
-
41
- it 'looks for items based on the element tag, not the element name' do
42
- expect(navigator.items).to be_empty
43
- end
44
- end
@@ -1,92 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- class CatalogTree
6
- include HappyMapper
7
-
8
- tag 'CatalogTree'
9
- register_namespace 'xmlns', 'urn:eventis:prodis:onlineapi:1.0'
10
- register_namespace 'xsi', 'http://www.w3.org/2001/XMLSchema-instance'
11
- register_namespace 'xsd', 'http://www.w3.org/2001/XMLSchema'
12
-
13
- attribute :code, String
14
-
15
- has_many :nodes, 'CatalogNode', tag: 'Node', xpath: '.'
16
- end
17
-
18
- class CatalogNode
19
- include HappyMapper
20
-
21
- tag 'Node'
22
-
23
- attribute :back_office_id, String, tag: 'vodBackOfficeId'
24
-
25
- has_one :name, String, tag: 'Name'
26
- # other important fields
27
-
28
- has_many :translations, 'CatalogNode::Translations', tag: 'Translation', xpath: 'child::*'
29
-
30
- class Translations
31
- include HappyMapper
32
- tag 'Translation'
33
-
34
- attribute :language, String, tag: 'Language'
35
- has_one :name, String, tag: 'Name'
36
- end
37
-
38
- has_many :nodes, CatalogNode, tag: 'Node', xpath: 'child::*'
39
- end
40
-
41
- RSpec.describe 'parsing a VOD catalog', type: :feature do
42
- let(:catalog_tree) { CatalogTree.parse(fixture_file('inagy.xml'), single: true) }
43
-
44
- it 'is not nil' do
45
- expect(catalog_tree).not_to be_nil
46
- end
47
-
48
- it 'has the attribute code' do
49
- expect(catalog_tree.code).to eq('NLD')
50
- end
51
-
52
- it 'has many nodes' do
53
- nodes = catalog_tree.nodes
54
-
55
- aggregate_failures do
56
- expect(nodes).not_to be_empty
57
- expect(nodes.length).to eq(2)
58
- end
59
- end
60
-
61
- describe 'first node' do
62
- let(:first_node) { catalog_tree.nodes.first }
63
-
64
- it 'has a name' do
65
- expect(first_node.name).to eq('Parent 1')
66
- end
67
-
68
- it 'has translations' do
69
- translations = first_node.translations
70
-
71
- aggregate_failures do
72
- expect(translations.length).to eq(2)
73
- expect(translations.first.language).to eq('en-GB')
74
- expect(translations.last.name).to eq('Parent 1 de')
75
- end
76
- end
77
-
78
- it 'has subnodes' do
79
- nodes = first_node.nodes
80
-
81
- aggregate_failures do
82
- expect(nodes).to be_kind_of(Enumerable)
83
- expect(nodes).not_to be_empty
84
- expect(nodes.length).to eq(1)
85
- end
86
- end
87
-
88
- it 'first node - first node name' do
89
- expect(first_node.nodes.first.name).to eq('First')
90
- end
91
- end
92
- end
@@ -1,121 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'Using inheritance to share elements and attributes', type: :feature do
6
- class Genetics
7
- include HappyMapper
8
- content :dna, String
9
- end
10
-
11
- class Parent
12
- include HappyMapper
13
- attribute :love, Integer
14
- element :genetics, Genetics
15
- end
16
-
17
- class Child < Parent
18
- include HappyMapper
19
- attribute :naivety, String
20
- has_many :immunities, String
21
- end
22
-
23
- class Overwrite < Parent
24
- include HappyMapper
25
-
26
- attribute :love, String
27
- element :genetics, Integer
28
- end
29
-
30
- describe 'Overwrite' do
31
- let(:overwrite) do
32
- xml =
33
- '<overwrite love="love" naivety="trusting">' \
34
- '<genetics>1001</genetics><immunities>Chicken Pox</immunities>' \
35
- '</overwrite>'
36
- Overwrite.parse(xml, single: true)
37
- end
38
-
39
- it 'overrides the parent elements and attributes' do
40
- aggregate_failures do
41
- expect(Overwrite.attributes.count).to eq Parent.attributes.count
42
- expect(Overwrite.elements.count).to eq Parent.elements.count
43
- end
44
- end
45
-
46
- context 'when parsing xml' do
47
- it 'parses the new overwritten attribut' do
48
- expect(overwrite.love).to be == 'love'
49
- end
50
-
51
- it 'parses the new overwritten element' do
52
- expect(overwrite.genetics).to be == 1001
53
- end
54
- end
55
-
56
- context 'when saving to xml' do
57
- let(:xml) do
58
- overwrite = Overwrite.new
59
- overwrite.genetics = 1
60
- overwrite.love = 'love'
61
- Nokogiri::XML(overwrite.to_xml).root
62
- end
63
-
64
- it 'has only 1 genetics element' do
65
- expect(xml.xpath('//genetics').count).to be == 1
66
- end
67
-
68
- it 'has only 1 love attribute' do
69
- expect(xml.xpath('@love').text).to be == 'love'
70
- end
71
- end
72
- end
73
-
74
- describe 'Child', 'a subclass of the Parent' do
75
- let(:child) do
76
- xml =
77
- '<child love="99" naivety="trusting">' \
78
- '<genetics>ABBA</genetics><immunities>Chicken Pox</immunities>' \
79
- '</child>'
80
- Child.parse(xml)
81
- end
82
-
83
- context 'when parsing xml' do
84
- it 'is possible to deserialize XML into a Child class instance' do
85
- aggregate_failures do
86
- expect(child.love).to eq 99
87
- expect(child.genetics.dna).to eq 'ABBA'
88
- expect(child.naivety).to eq 'trusting'
89
- expect(child.immunities.size).to eq(1)
90
- end
91
- end
92
- end
93
-
94
- context 'when saving to xml' do
95
- let(:xml) do
96
- child = Child.new
97
- child.love = 100
98
- child.naivety = 'Bright Eyed'
99
- child.immunities = ['Small Pox', 'Chicken Pox', 'Mumps']
100
- genetics = Genetics.new
101
- genetics.dna = 'GATTACA'
102
- child.genetics = genetics
103
- Nokogiri::XML(child.to_xml).root
104
- end
105
-
106
- it 'saves both the Child and Parent attributes' do
107
- aggregate_failures do
108
- expect(xml.xpath('@naivety').text).to eq 'Bright Eyed'
109
- expect(xml.xpath('@love').text).to eq '100'
110
- end
111
- end
112
-
113
- it 'saves both the Child and Parent elements' do
114
- aggregate_failures do
115
- expect(xml.xpath('genetics').text).to eq 'GATTACA'
116
- expect(xml.xpath('immunities').size).to eq(3)
117
- end
118
- end
119
- end
120
- end
121
- end