nokogiri-happymapper 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -5
  3. data/README.md +85 -69
  4. data/lib/happymapper.rb +27 -22
  5. data/lib/happymapper/anonymous_mapper.rb +35 -30
  6. data/lib/happymapper/item.rb +1 -1
  7. data/lib/happymapper/supported_types.rb +2 -7
  8. data/lib/happymapper/version.rb +1 -1
  9. data/spec/features/after_parse_callbacks_spec.rb +29 -0
  10. data/spec/{attribute_default_value_spec.rb → features/attribute_default_value_spec.rb} +3 -3
  11. data/spec/{attributes_spec.rb → features/attributes_spec.rb} +6 -6
  12. data/spec/{has_many_empty_array_spec.rb → features/has_many_empty_array_spec.rb} +1 -1
  13. data/spec/{ignay_spec.rb → features/ignay_spec.rb} +10 -19
  14. data/spec/{inheritance_spec.rb → features/inheritance_spec.rb} +1 -1
  15. data/spec/{mixed_namespaces_spec.rb → features/mixed_namespaces_spec.rb} +17 -17
  16. data/spec/{parse_with_object_to_update_spec.rb → features/parse_with_object_to_update_spec.rb} +0 -0
  17. data/spec/features/same_tag_different_meaning_spec.rb +44 -0
  18. data/spec/{to_xml_spec.rb → features/to_xml_spec.rb} +2 -2
  19. data/spec/{to_xml_with_namespaces_spec.rb → features/to_xml_with_namespaces_spec.rb} +0 -0
  20. data/spec/{wilcard_tag_name_spec.rb → features/wildcard_tag_name_spec.rb} +5 -5
  21. data/spec/{wrap_spec.rb → features/wrap_spec.rb} +4 -4
  22. data/spec/{xpath_spec.rb → features/xpath_spec.rb} +17 -23
  23. data/spec/happymapper/anonymous_mapper_spec.rb +158 -0
  24. data/spec/happymapper/element_spec.rb +1 -1
  25. data/spec/happymapper/item_spec.rb +75 -45
  26. data/spec/happymapper_spec.rb +120 -125
  27. metadata +32 -28
  28. data/spec/happymapper_parse_spec.rb +0 -131
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.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Le Berrigaud
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2018-08-27 00:00:00.000000000 Z
17
+ date: 2018-08-28 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: nokogiri
@@ -93,8 +93,20 @@ files:
93
93
  - lib/happymapper/supported_types.rb
94
94
  - lib/happymapper/text_node.rb
95
95
  - lib/happymapper/version.rb
96
- - spec/attribute_default_value_spec.rb
97
- - spec/attributes_spec.rb
96
+ - spec/features/after_parse_callbacks_spec.rb
97
+ - spec/features/attribute_default_value_spec.rb
98
+ - spec/features/attributes_spec.rb
99
+ - spec/features/has_many_empty_array_spec.rb
100
+ - spec/features/ignay_spec.rb
101
+ - spec/features/inheritance_spec.rb
102
+ - spec/features/mixed_namespaces_spec.rb
103
+ - spec/features/parse_with_object_to_update_spec.rb
104
+ - spec/features/same_tag_different_meaning_spec.rb
105
+ - spec/features/to_xml_spec.rb
106
+ - spec/features/to_xml_with_namespaces_spec.rb
107
+ - spec/features/wildcard_tag_name_spec.rb
108
+ - spec/features/wrap_spec.rb
109
+ - spec/features/xpath_spec.rb
98
110
  - spec/fixtures/address.xml
99
111
  - spec/fixtures/ambigous_items.xml
100
112
  - spec/fixtures/analytics.xml
@@ -123,23 +135,13 @@ files:
123
135
  - spec/fixtures/subclass_namespace.xml
124
136
  - spec/fixtures/unformatted_address.xml
125
137
  - spec/fixtures/wrapper.xml
138
+ - spec/happymapper/anonymous_mapper_spec.rb
126
139
  - spec/happymapper/attribute_spec.rb
127
140
  - spec/happymapper/element_spec.rb
128
141
  - spec/happymapper/item_spec.rb
129
142
  - spec/happymapper/text_node_spec.rb
130
- - spec/happymapper_parse_spec.rb
131
143
  - spec/happymapper_spec.rb
132
- - spec/has_many_empty_array_spec.rb
133
- - spec/ignay_spec.rb
134
- - spec/inheritance_spec.rb
135
- - spec/mixed_namespaces_spec.rb
136
- - spec/parse_with_object_to_update_spec.rb
137
144
  - spec/spec_helper.rb
138
- - spec/to_xml_spec.rb
139
- - spec/to_xml_with_namespaces_spec.rb
140
- - spec/wilcard_tag_name_spec.rb
141
- - spec/wrap_spec.rb
142
- - spec/xpath_spec.rb
143
145
  homepage: http://github.com/mvz/happymapper
144
146
  licenses:
145
147
  - MIT
@@ -165,8 +167,20 @@ signing_key:
165
167
  specification_version: 4
166
168
  summary: Provides a simple way to map XML to Ruby Objects and back again.
167
169
  test_files:
168
- - spec/attribute_default_value_spec.rb
169
- - spec/attributes_spec.rb
170
+ - spec/features/after_parse_callbacks_spec.rb
171
+ - spec/features/attribute_default_value_spec.rb
172
+ - spec/features/attributes_spec.rb
173
+ - spec/features/has_many_empty_array_spec.rb
174
+ - spec/features/ignay_spec.rb
175
+ - spec/features/inheritance_spec.rb
176
+ - spec/features/mixed_namespaces_spec.rb
177
+ - spec/features/parse_with_object_to_update_spec.rb
178
+ - spec/features/same_tag_different_meaning_spec.rb
179
+ - spec/features/to_xml_spec.rb
180
+ - spec/features/to_xml_with_namespaces_spec.rb
181
+ - spec/features/wildcard_tag_name_spec.rb
182
+ - spec/features/wrap_spec.rb
183
+ - spec/features/xpath_spec.rb
170
184
  - spec/fixtures/address.xml
171
185
  - spec/fixtures/ambigous_items.xml
172
186
  - spec/fixtures/analytics.xml
@@ -195,20 +209,10 @@ test_files:
195
209
  - spec/fixtures/subclass_namespace.xml
196
210
  - spec/fixtures/unformatted_address.xml
197
211
  - spec/fixtures/wrapper.xml
212
+ - spec/happymapper/anonymous_mapper_spec.rb
198
213
  - spec/happymapper/attribute_spec.rb
199
214
  - spec/happymapper/element_spec.rb
200
215
  - spec/happymapper/item_spec.rb
201
216
  - spec/happymapper/text_node_spec.rb
202
- - spec/happymapper_parse_spec.rb
203
217
  - spec/happymapper_spec.rb
204
- - spec/has_many_empty_array_spec.rb
205
- - spec/ignay_spec.rb
206
- - spec/inheritance_spec.rb
207
- - spec/mixed_namespaces_spec.rb
208
- - spec/parse_with_object_to_update_spec.rb
209
218
  - spec/spec_helper.rb
210
- - spec/to_xml_spec.rb
211
- - spec/to_xml_with_namespaces_spec.rb
212
- - spec/wilcard_tag_name_spec.rb
213
- - spec/wrap_spec.rb
214
- - spec/xpath_spec.rb
@@ -1,131 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe HappyMapper do
6
- context '.parse' do
7
- context 'on a single root node' do
8
- subject { described_class.parse fixture_file('address.xml') }
9
-
10
- it 'should parse child elements' do
11
- expect(subject.street).to eq('Milchstrasse')
12
- expect(subject.housenumber).to eq('23')
13
- expect(subject.postcode).to eq('26131')
14
- expect(subject.city).to eq('Oldenburg')
15
- end
16
-
17
- it 'should not create a content entry when the xml contents no text content' do
18
- expect(subject).not_to respond_to :content
19
- end
20
-
21
- context 'child elements with attributes' do
22
- it 'should parse the attributes' do
23
- expect(subject.country.code).to eq('de')
24
- end
25
-
26
- it 'should parse the content' do
27
- expect(subject.country.content).to eq('Germany')
28
- end
29
- end
30
- end
31
-
32
- context 'element names with special characters' do
33
- subject { described_class.parse fixture_file('ambigous_items.xml') }
34
-
35
- it 'should create accessor methods with similar names' do
36
- expect(subject.my_items.item).to be_kind_of Array
37
- end
38
- end
39
-
40
- context 'element names with camelCased elements and Capital Letters' do
41
- subject { described_class.parse fixture_file('subclass_namespace.xml') }
42
-
43
- it 'parses camel-cased child elements correctly' do
44
- expect(subject.photo.publish_options.author).to eq('Stephanie')
45
- expect(subject.gallery.photo.title).to eq('photo title')
46
- end
47
-
48
- it 'parses camel-cased child properties correctly' do
49
- expect(subject.publish_options.created_day).to eq('2011-01-14')
50
- end
51
- end
52
-
53
- context 'with elements with camelCased attribute names' do
54
- subject { described_class.parse '<foo barBaz="quuz"/>' }
55
-
56
- it 'parses attributes correctly' do
57
- expect(subject.bar_baz).to eq('quuz')
58
- end
59
- end
60
-
61
- context 'several elements nested deep' do
62
- subject { described_class.parse fixture_file('ambigous_items.xml') }
63
-
64
- it 'should parse the entire relationship' do
65
- expect(subject.my_items.item.first.item.name).to eq('My first internal item')
66
- end
67
- end
68
-
69
- context 'xml that contains multiple entries' do
70
- subject { described_class.parse fixture_file('multiple_primitives.xml') }
71
-
72
- it "should parse the elements as it would a 'has_many'" do
73
- expect(subject.name).to eq('value')
74
- expect(subject.image).to eq(%w(image1 image2))
75
- end
76
- end
77
-
78
- context 'xml with multiple namespaces' do
79
- subject { described_class.parse fixture_file('subclass_namespace.xml') }
80
-
81
- it 'should parse the elements an values correctly' do
82
- expect(subject.title).to eq('article title')
83
- end
84
-
85
- it 'parses attribute names correctly' do
86
- expect(subject.name).to eq 'title'
87
- end
88
- end
89
-
90
- context 'with value elements with different namespace' do
91
- let(:xml) do
92
- <<~XML
93
- <a:foo xmlns:a="http://foo.org/a" xmlns:b="http://foo.org/b">
94
- <b:bar>Hello</b:bar>
95
- </a:foo>
96
- XML
97
- end
98
- let(:result) { described_class.parse xml }
99
-
100
- it 'parses the value elements correctly' do
101
- expect(result.bar).to eq 'Hello'
102
- end
103
- end
104
-
105
- context 'after_parse callbacks' do
106
- module AfterParseSpec
107
- class Address
108
- include HappyMapper
109
- element :street, String
110
- end
111
- end
112
-
113
- after do
114
- AfterParseSpec::Address.after_parse_callbacks.clear
115
- end
116
-
117
- it 'should callback with the newly created object' do
118
- from_cb = nil
119
- called = false
120
- cb1 = proc { |object| from_cb = object }
121
- cb2 = proc { called = true }
122
- AfterParseSpec::Address.after_parse(&cb1)
123
- AfterParseSpec::Address.after_parse(&cb2)
124
-
125
- object = AfterParseSpec::Address.parse fixture_file('address.xml')
126
- expect(from_cb).to eq(object)
127
- expect(called).to eq(true)
128
- end
129
- end
130
- end
131
- end