nokogiri-happymapper 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +26 -1
- data/README.md +204 -117
- data/lib/happymapper.rb +318 -343
- data/lib/happymapper/anonymous_mapper.rb +27 -29
- data/lib/happymapper/attribute.rb +7 -5
- data/lib/happymapper/element.rb +19 -24
- data/lib/happymapper/item.rb +18 -20
- data/lib/happymapper/supported_types.rb +20 -19
- data/lib/happymapper/text_node.rb +4 -3
- data/lib/happymapper/version.rb +3 -1
- data/spec/attribute_default_value_spec.rb +14 -15
- data/spec/attributes_spec.rb +14 -15
- data/spec/happymapper/attribute_spec.rb +4 -4
- data/spec/happymapper/element_spec.rb +3 -1
- data/spec/happymapper/item_spec.rb +49 -41
- data/spec/happymapper/text_node_spec.rb +3 -1
- data/spec/happymapper_parse_spec.rb +62 -44
- data/spec/happymapper_spec.rb +270 -263
- data/spec/has_many_empty_array_spec.rb +8 -7
- data/spec/ignay_spec.rb +27 -31
- data/spec/inheritance_spec.rb +30 -24
- data/spec/mixed_namespaces_spec.rb +14 -15
- data/spec/parse_with_object_to_update_spec.rb +37 -38
- data/spec/spec_helper.rb +18 -0
- data/spec/to_xml_spec.rb +64 -63
- data/spec/to_xml_with_namespaces_spec.rb +66 -64
- data/spec/wilcard_tag_name_spec.rb +25 -21
- data/spec/wrap_spec.rb +11 -11
- data/spec/xpath_spec.rb +33 -32
- metadata +33 -5
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start do
|
5
|
+
track_files 'lib/**/*.rb'
|
6
|
+
add_filter '/spec/'
|
7
|
+
add_filter 'lib/happymapper/version.rb'
|
8
|
+
end
|
9
|
+
|
10
|
+
if ENV['CI']
|
11
|
+
begin
|
12
|
+
require 'coveralls'
|
13
|
+
Coveralls.wear!
|
14
|
+
rescue LoadError
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
1
19
|
require 'rspec'
|
2
20
|
|
3
21
|
require 'happymapper'
|
data/spec/to_xml_spec.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'spec_helper'
|
4
4
|
|
5
|
+
describe 'Saving #to_xml' do
|
5
6
|
module ToXML
|
6
7
|
class Address
|
7
8
|
include HappyMapper
|
8
9
|
|
9
10
|
tag 'address'
|
10
11
|
|
11
|
-
attribute :location, String, :
|
12
|
+
attribute :location, String, on_save: :when_saving_location
|
12
13
|
|
13
14
|
element :street, String
|
14
15
|
element :postcode, String
|
@@ -16,8 +17,8 @@ describe "Saving #to_xml" do
|
|
16
17
|
|
17
18
|
element :housenumber, String
|
18
19
|
|
19
|
-
attribute :modified, Boolean, :
|
20
|
-
element :temporary, Boolean, :
|
20
|
+
attribute :modified, Boolean, read_only: true
|
21
|
+
element :temporary, Boolean, read_only: true
|
21
22
|
#
|
22
23
|
# to_xml will default to the attr_accessor method and not the attribute,
|
23
24
|
# allowing for that to be overwritten
|
@@ -28,19 +29,18 @@ describe "Saving #to_xml" do
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def when_saving_location(loc)
|
31
|
-
loc +
|
32
|
+
loc + '-live'
|
32
33
|
end
|
33
34
|
|
34
35
|
#
|
35
36
|
# Write a empty element even if this is not specified
|
36
37
|
#
|
37
|
-
element :description, String, :
|
38
|
+
element :description, String, state_when_nil: true
|
38
39
|
|
39
40
|
#
|
40
41
|
# Perform the on_save operation when saving
|
41
42
|
#
|
42
|
-
has_one :date_created, Time, :
|
43
|
-
|
43
|
+
has_one :date_created, Time, on_save: ->(time) { Time.parse(time).strftime('%T %D') if time }
|
44
44
|
|
45
45
|
#
|
46
46
|
# Execute the method with the same name
|
@@ -48,23 +48,23 @@ describe "Saving #to_xml" do
|
|
48
48
|
#
|
49
49
|
# Write multiple elements and call on_save when saving
|
50
50
|
#
|
51
|
-
has_many :dates_updated, Time, :
|
52
|
-
times.compact.map {|time|
|
51
|
+
has_many :dates_updated, Time, on_save: lambda { |times|
|
52
|
+
times.compact.map { |time| Time.parse(time).strftime('%T %D') } if times
|
53
|
+
}
|
53
54
|
|
54
55
|
#
|
55
56
|
# Class composition
|
56
57
|
#
|
57
|
-
element :country, 'Country', :
|
58
|
+
element :country, 'Country', tag: 'country'
|
58
59
|
|
59
60
|
attribute :occupied, Boolean
|
60
61
|
|
61
62
|
def initialize(parameters)
|
62
|
-
parameters.each_pair do |property,value|
|
63
|
-
send("#{property}=",value) if respond_to?("#{property}=")
|
63
|
+
parameters.each_pair do |property, value|
|
64
|
+
send("#{property}=", value) if respond_to?("#{property}=")
|
64
65
|
end
|
65
66
|
@modified = @temporary = true
|
66
67
|
end
|
67
|
-
|
68
68
|
end
|
69
69
|
|
70
70
|
#
|
@@ -75,9 +75,9 @@ describe "Saving #to_xml" do
|
|
75
75
|
class Country
|
76
76
|
include HappyMapper
|
77
77
|
|
78
|
-
attribute :code, String, :
|
79
|
-
has_one :name, String, :
|
80
|
-
has_one :description, 'Description', :
|
78
|
+
attribute :code, String, tag: 'countryCode'
|
79
|
+
has_one :name, String, tag: 'countryName'
|
80
|
+
has_one :description, 'Description', tag: 'description'
|
81
81
|
|
82
82
|
#
|
83
83
|
# This inner-class here is to demonstrate saving a text node
|
@@ -86,8 +86,8 @@ describe "Saving #to_xml" do
|
|
86
86
|
class Description
|
87
87
|
include HappyMapper
|
88
88
|
content :description, String
|
89
|
-
attribute :category, String, :
|
90
|
-
attribute :rating, String, :
|
89
|
+
attribute :category, String, tag: 'category'
|
90
|
+
attribute :rating, String, tag: 'rating', state_when_nil: true
|
91
91
|
|
92
92
|
def initialize(desc)
|
93
93
|
@description = desc
|
@@ -95,107 +95,108 @@ describe "Saving #to_xml" do
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def initialize(parameters)
|
98
|
-
parameters.each_pair do |property,value|
|
99
|
-
send("#{property}=",value) if respond_to?("#{property}=")
|
98
|
+
parameters.each_pair do |property, value|
|
99
|
+
send("#{property}=", value) if respond_to?("#{property}=")
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
103
102
|
end
|
104
103
|
end
|
105
104
|
|
106
105
|
let(:subject) do
|
106
|
+
country = ToXML::Country.new(name: 'USA', code: 'us', empty_code: nil,
|
107
|
+
description: ToXML::Country::Description.new('A lovely country'))
|
108
|
+
|
107
109
|
address = ToXML::Address.new 'street' => 'Mockingbird Lane',
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
'occupied' => false
|
110
|
+
'location' => 'Home',
|
111
|
+
'housenumber' => '1313',
|
112
|
+
'postcode' => '98103',
|
113
|
+
'city' => 'Seattle',
|
114
|
+
'country' => country,
|
115
|
+
'date_created' => '2011-01-01 15:00:00',
|
116
|
+
'occupied' => false
|
116
117
|
|
117
|
-
address.dates_updated = [
|
118
|
+
address.dates_updated = ['2011-01-01 16:01:00', '2011-01-02 11:30:01']
|
118
119
|
|
119
120
|
Nokogiri::XML(address.to_xml).root
|
120
121
|
end
|
121
122
|
|
122
|
-
it
|
123
|
+
it 'saves elements' do
|
123
124
|
elements = { 'street' => 'Mockingbird Lane', 'postcode' => '98103', 'city' => 'Seattle' }
|
124
|
-
elements.each_pair do |property,value|
|
125
|
-
expect(subject.xpath(
|
125
|
+
elements.each_pair do |property, value|
|
126
|
+
expect(subject.xpath(property.to_s).text).to eq value
|
126
127
|
end
|
127
128
|
end
|
128
129
|
|
129
|
-
it
|
130
|
-
expect(subject.xpath('@location').text).to eq
|
130
|
+
it 'saves attributes' do
|
131
|
+
expect(subject.xpath('@location').text).to eq 'Home-live'
|
131
132
|
end
|
132
133
|
|
133
134
|
it 'saves attributes that are Boolean and have a value of false' do
|
134
|
-
expect(subject.xpath('@occupied').text).to eq
|
135
|
+
expect(subject.xpath('@occupied').text).to eq 'false'
|
135
136
|
end
|
136
137
|
|
137
138
|
context "when an element has a 'read_only' parameter" do
|
138
|
-
it
|
139
|
+
it 'does not save elements' do
|
139
140
|
expect(subject.xpath('temporary')).to be_empty
|
140
141
|
end
|
141
142
|
end
|
142
143
|
|
143
144
|
context "when an attribute has a 'read_only' parameter" do
|
144
|
-
it
|
145
|
-
expect(subject.xpath(
|
145
|
+
it 'does not save attributes' do
|
146
|
+
expect(subject.xpath('@modified')).to be_empty
|
146
147
|
end
|
147
148
|
end
|
148
149
|
|
149
150
|
context "when an element has a 'state_when_nil' parameter" do
|
150
|
-
it
|
151
|
-
expect(subject.xpath('description').text).to eq
|
151
|
+
it 'saves an empty element' do
|
152
|
+
expect(subject.xpath('description').text).to eq ''
|
152
153
|
end
|
153
154
|
end
|
154
155
|
|
155
156
|
context "when an element has a 'on_save' parameter" do
|
156
|
-
context
|
157
|
-
it
|
158
|
-
expect(subject.xpath(
|
157
|
+
context 'with a symbol which represents a function' do
|
158
|
+
it 'saves the element with the result of the function' do
|
159
|
+
expect(subject.xpath('housenumber').text).to eq '[1313]'
|
159
160
|
end
|
160
161
|
end
|
161
162
|
|
162
|
-
context
|
163
|
-
it
|
164
|
-
expect(subject.xpath('date_created').text).to eq
|
163
|
+
context 'with a lambda' do
|
164
|
+
it 'saves the result of the lambda' do
|
165
|
+
expect(subject.xpath('date_created').text).to eq '15:00:00 01/01/11'
|
165
166
|
end
|
166
167
|
end
|
167
168
|
end
|
168
169
|
|
169
170
|
context "when a has_many has a 'on_save' parameter" do
|
170
|
-
context
|
171
|
-
it
|
171
|
+
context 'with a lambda' do
|
172
|
+
it 'saves the results' do
|
172
173
|
dates_updated = subject.xpath('dates_updated')
|
173
174
|
expect(dates_updated.length).to eq 2
|
174
|
-
expect(dates_updated.first.text).to eq
|
175
|
-
expect(dates_updated.last.text).to eq
|
175
|
+
expect(dates_updated.first.text).to eq '16:01:00 01/01/11'
|
176
|
+
expect(dates_updated.last.text).to eq '11:30:01 01/02/11'
|
176
177
|
end
|
177
178
|
end
|
178
179
|
end
|
179
180
|
|
180
181
|
context "when an attribute has a 'on_save' parameter" do
|
181
|
-
context
|
182
|
-
it
|
183
|
-
expect(subject.xpath('@location').text).to eq
|
182
|
+
context 'with a symbol which represents a function' do
|
183
|
+
it 'saves the result' do
|
184
|
+
expect(subject.xpath('@location').text).to eq 'Home-live'
|
184
185
|
end
|
185
186
|
end
|
186
187
|
end
|
187
188
|
|
188
|
-
context
|
189
|
-
it
|
190
|
-
expect(subject.xpath('country/@countryCode').text).to eq
|
189
|
+
context 'when an element type is a HappyMapper subclass' do
|
190
|
+
it 'saves attributes' do
|
191
|
+
expect(subject.xpath('country/@countryCode').text).to eq 'us'
|
191
192
|
end
|
192
193
|
|
193
|
-
it
|
194
|
-
expect(subject.xpath('country/countryName').text).to eq
|
194
|
+
it 'saves elements' do
|
195
|
+
expect(subject.xpath('country/countryName').text).to eq 'USA'
|
195
196
|
end
|
196
197
|
|
197
|
-
it
|
198
|
-
expect(subject.xpath('country/description').text).to eq
|
198
|
+
it 'saves elements' do
|
199
|
+
expect(subject.xpath('country/description').text).to eq 'A lovely country'
|
199
200
|
end
|
200
201
|
end
|
201
202
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module ToXMLWithNamespaces
|
4
|
-
|
5
6
|
#
|
6
7
|
# Similar example as the to_xml but this time with namespacing
|
7
8
|
#
|
@@ -14,9 +15,9 @@ module ToXMLWithNamespaces
|
|
14
15
|
tag 'Address'
|
15
16
|
namespace 'address'
|
16
17
|
|
17
|
-
element :country, 'Country', :
|
18
|
+
element :country, 'Country', tag: 'country', namespace: 'country'
|
18
19
|
|
19
|
-
attribute :location, String, :
|
20
|
+
attribute :location, String, on_save: :when_saving_location
|
20
21
|
|
21
22
|
element :street, String
|
22
23
|
element :postcode, String
|
@@ -40,29 +41,29 @@ module ToXMLWithNamespaces
|
|
40
41
|
#
|
41
42
|
# Write a empty element even if this is not specified
|
42
43
|
#
|
43
|
-
element :description, String, :
|
44
|
+
element :description, String, state_when_nil: true
|
44
45
|
|
45
46
|
#
|
46
47
|
# Perform the on_save operation when saving
|
47
48
|
#
|
48
|
-
has_one :date_created, Time, :
|
49
|
+
has_one :date_created, Time, on_save: ->(time) { Time.parse(time).strftime('%T %D') if time }
|
49
50
|
|
50
51
|
#
|
51
52
|
# Write multiple elements and call on_save when saving
|
52
53
|
#
|
53
|
-
has_many :dates_updated, Time, :
|
54
|
-
times.compact.map {|time|
|
54
|
+
has_many :dates_updated, Time, on_save: lambda { |times|
|
55
|
+
times.compact.map { |time| Time.parse(time).strftime('%T %D') } if times
|
56
|
+
}
|
55
57
|
|
56
58
|
#
|
57
59
|
# Class composition
|
58
60
|
#
|
59
61
|
|
60
62
|
def initialize(parameters)
|
61
|
-
parameters.each_pair do |property,value|
|
62
|
-
send("#{property}=",value) if respond_to?("#{property}=")
|
63
|
+
parameters.each_pair do |property, value|
|
64
|
+
send("#{property}=", value) if respond_to?("#{property}=")
|
63
65
|
end
|
64
66
|
end
|
65
|
-
|
66
67
|
end
|
67
68
|
|
68
69
|
#
|
@@ -75,122 +76,124 @@ module ToXMLWithNamespaces
|
|
75
76
|
|
76
77
|
register_namespace 'countryName', 'http://www.company.com/countryName'
|
77
78
|
|
78
|
-
attribute :code, String, :
|
79
|
-
has_one :name, String, :
|
79
|
+
attribute :code, String, tag: 'countryCode'
|
80
|
+
has_one :name, String, tag: 'countryName', namespace: 'countryName'
|
80
81
|
|
81
82
|
def initialize(parameters)
|
82
|
-
parameters.each_pair do |property,value|
|
83
|
-
send("#{property}=",value) if respond_to?("#{property}=")
|
83
|
+
parameters.each_pair do |property, value|
|
84
|
+
send("#{property}=", value) if respond_to?("#{property}=")
|
84
85
|
end
|
85
86
|
end
|
86
|
-
|
87
87
|
end
|
88
88
|
|
89
|
-
|
90
89
|
#
|
91
90
|
# This class is an example of a class that has a default namespace
|
92
|
-
#xmlns="urn:eventis:prodis:onlineapi:1.0"
|
91
|
+
# xmlns="urn:eventis:prodis:onlineapi:1.0"
|
92
|
+
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
93
|
+
# xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
93
94
|
#
|
94
95
|
class Recipe
|
95
96
|
include HappyMapper
|
96
97
|
|
97
98
|
# this is the default namespace of the document
|
98
99
|
register_namespace 'xmlns', 'urn:eventis:prodis:onlineapi:1.0'
|
99
|
-
register_namespace 'xsi',
|
100
|
-
register_namespace 'xsd',
|
100
|
+
register_namespace 'xsi', 'http://www.w3.org/2001/XMLSchema-instance'
|
101
|
+
register_namespace 'xsd', 'http://www.w3.org/2001/XMLSchema'
|
101
102
|
|
102
103
|
has_many :ingredients, String
|
103
104
|
|
104
105
|
def initialize(parameters)
|
105
|
-
parameters.each_pair {|property,value| send("#{property}=",value) if respond_to?("#{property}=") }
|
106
|
+
parameters.each_pair { |property, value| send("#{property}=", value) if respond_to?("#{property}=") }
|
106
107
|
end
|
107
108
|
end
|
108
109
|
end
|
109
110
|
|
110
|
-
describe
|
111
|
-
|
112
|
-
context "#to_xml", "with namespaces" do
|
113
|
-
|
111
|
+
describe 'Saving #to_xml', 'with xml namespaces' do
|
112
|
+
context '#to_xml', 'with namespaces' do
|
114
113
|
let(:subject) do
|
114
|
+
country = ToXMLWithNamespaces::Country.new(name: 'USA', code: 'us')
|
115
115
|
address = ToXMLWithNamespaces::Address.new('street' => 'Mockingbird Lane',
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
116
|
+
'location' => 'Home',
|
117
|
+
'housenumber' => '1313',
|
118
|
+
'postcode' => '98103',
|
119
|
+
'city' => 'Seattle',
|
120
|
+
'country' => country,
|
121
|
+
'date_created' => '2011-01-01 15:00:00')
|
123
122
|
|
124
|
-
address.dates_updated = [
|
123
|
+
address.dates_updated = ['2011-01-01 16:01:00', '2011-01-02 11:30:01']
|
125
124
|
|
126
125
|
Nokogiri::XML(address.to_xml).root
|
127
126
|
end
|
128
127
|
|
129
|
-
it
|
128
|
+
it 'sets the namespace specified in the class' do
|
129
|
+
expect(subject.xpath('/').children.first.namespace.prefix).to eq 'address'
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'saves elements' do
|
130
133
|
elements = { 'street' => 'Mockingbird Lane', 'postcode' => '98103', 'city' => 'Seattle' }
|
131
134
|
|
132
|
-
elements.each_pair do |property,value|
|
135
|
+
elements.each_pair do |property, value|
|
133
136
|
expect(subject.xpath("address:#{property}").text).to eq value
|
134
137
|
end
|
135
138
|
end
|
136
139
|
|
137
|
-
it
|
138
|
-
expect(subject.xpath('@location').text).to eq
|
140
|
+
it 'saves attributes' do
|
141
|
+
expect(subject.xpath('@location').text).to eq 'Home-live'
|
139
142
|
end
|
140
143
|
|
141
144
|
context "when an element has a 'state_when_nil' parameter" do
|
142
|
-
it
|
143
|
-
expect(subject.xpath('address:description').text).to eq
|
145
|
+
it 'saves an empty element' do
|
146
|
+
expect(subject.xpath('address:description').text).to eq ''
|
144
147
|
end
|
145
148
|
end
|
146
149
|
|
147
150
|
context "when an element has a 'on_save' parameter" do
|
148
|
-
context
|
149
|
-
it
|
150
|
-
expect(subject.xpath(
|
151
|
+
context 'with a symbol which represents a function' do
|
152
|
+
it 'saves the element with the result of a function call and not the value of the ivar' do
|
153
|
+
expect(subject.xpath('address:housenumber').text).to eq '[1313]'
|
151
154
|
end
|
152
155
|
end
|
153
156
|
|
154
|
-
context
|
155
|
-
it
|
156
|
-
expect(subject.xpath('address:date_created').text).to eq
|
157
|
+
context 'with a lambda' do
|
158
|
+
it 'saves the results' do
|
159
|
+
expect(subject.xpath('address:date_created').text).to eq '15:00:00 01/01/11'
|
157
160
|
end
|
158
161
|
end
|
159
162
|
end
|
160
163
|
|
161
164
|
context "when an attribute has a 'on_save' parameter" do
|
162
|
-
context
|
163
|
-
it
|
164
|
-
expect(subject.xpath('@location').text).to eq
|
165
|
+
context 'with a lambda' do
|
166
|
+
it 'saves the result' do
|
167
|
+
expect(subject.xpath('@location').text).to eq 'Home-live'
|
165
168
|
end
|
166
169
|
end
|
167
170
|
end
|
168
171
|
|
169
172
|
context "when a has_many has a 'on_save' parameter" do
|
170
|
-
context
|
171
|
-
it
|
173
|
+
context 'with a lambda' do
|
174
|
+
it 'saves the result' do
|
172
175
|
dates_updated = subject.xpath('address:dates_updated')
|
173
176
|
expect(dates_updated.length).to eq 2
|
174
|
-
expect(dates_updated.first.text).to eq
|
175
|
-
expect(dates_updated.last.text).to eq
|
177
|
+
expect(dates_updated.first.text).to eq '16:01:00 01/01/11'
|
178
|
+
expect(dates_updated.last.text).to eq '11:30:01 01/02/11'
|
176
179
|
end
|
177
180
|
end
|
178
181
|
end
|
179
182
|
|
180
|
-
context
|
181
|
-
it
|
182
|
-
expect(subject.xpath('country:country/@countryCode').text).to eq
|
183
|
+
context 'when an element type is a HappyMapper subclass' do
|
184
|
+
it 'saves attributes' do
|
185
|
+
expect(subject.xpath('country:country/@countryCode').text).to eq 'us'
|
183
186
|
end
|
184
187
|
|
185
|
-
it
|
186
|
-
expect(subject.xpath('country:country/countryName:countryName').text).to eq
|
188
|
+
it 'saves elements' do
|
189
|
+
expect(subject.xpath('country:country/countryName:countryName').text).to eq 'USA'
|
187
190
|
end
|
188
191
|
end
|
189
192
|
end
|
190
193
|
|
191
|
-
context
|
192
|
-
it
|
193
|
-
recipe = ToXMLWithNamespaces::Recipe.new(:
|
194
|
+
context 'with a default namespace' do
|
195
|
+
it 'writes the default namespace to xml without repeating xmlns' do
|
196
|
+
recipe = ToXMLWithNamespaces::Recipe.new(ingredients: ['One Cup Flour', 'Two Scoops of Lovin'])
|
194
197
|
expect(recipe.to_xml).to match(/xmlns=\"urn:eventis:prodis:onlineapi:1\.0\"/)
|
195
198
|
end
|
196
199
|
end
|
@@ -201,7 +204,7 @@ describe "Saving #to_xml", "with xml namespaces" do
|
|
201
204
|
let(:expected_xml) do
|
202
205
|
<<-XML.gsub(/^\s*\|/, '')
|
203
206
|
|<?xml version="1.0"?>
|
204
|
-
|<coffeemachine xmlns:
|
207
|
+
|<coffeemachine xmlns:beverage="http://beverages.org/Beverage/0.1" xmlns:coffee="http://coffee.org/Coffee/0.1">
|
205
208
|
| <beverage:beverage name="coffee"/>
|
206
209
|
|</coffeemachine>
|
207
210
|
XML
|
@@ -216,17 +219,16 @@ describe "Saving #to_xml", "with xml namespaces" do
|
|
216
219
|
|
217
220
|
class CoffeeMachine
|
218
221
|
include HappyMapper
|
219
|
-
register_namespace 'coffee',
|
220
|
-
register_namespace 'beverage',
|
222
|
+
register_namespace 'coffee', 'http://coffee.org/Coffee/0.1'
|
223
|
+
register_namespace 'beverage', 'http://beverages.org/Beverage/0.1'
|
221
224
|
|
222
225
|
element :beverage, 'beverage', namespace: 'beverage'
|
223
226
|
end
|
224
227
|
|
225
228
|
it 'uses the element declaration namespace on the element' do
|
226
229
|
machine = CoffeeMachine.new
|
227
|
-
machine.beverage = Beverage.new.tap {|obj| obj.name = 'coffee'}
|
230
|
+
machine.beverage = Beverage.new.tap { |obj| obj.name = 'coffee' }
|
228
231
|
expect(machine.to_xml).to eq(expected_xml)
|
229
232
|
end
|
230
233
|
end
|
231
|
-
|
232
234
|
end
|