File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ def after_parse(&block)
177177 # element.
178178 #
179179 def namespace ( namespace = nil )
180- @namespace = namespace if namespace
180+ @namespace = namespace . to_s if namespace
181181 @namespace if defined? @namespace
182182 end
183183
Original file line number Diff line number Diff line change @@ -299,4 +299,36 @@ def initialize(parameters)
299299 XML
300300 end
301301 end
302+
303+ context "with namespace set on the root object using a symbol" do
304+ let ( :klass ) do
305+ Class . new do
306+ include HappyMapper
307+
308+ register_namespace "prefix" , "http://www.unicornland.com/prefix"
309+ namespace :prefix
310+ tag :foo
311+ has_one :bar , String
312+ end
313+ end
314+
315+ it "renders xml that can be parsed by the same class" do
316+ obj = klass . new
317+ obj . bar = "foobar"
318+ copy = klass . parse ( obj . to_xml )
319+ expect ( copy . bar ) . to eq obj . bar
320+ end
321+
322+ it "renders the namespace prefix on all elements" do
323+ obj = klass . new
324+ obj . bar = "foobar"
325+
326+ expect ( obj . to_xml ) . to eq <<~XML
327+ <?xml version="1.0"?>
328+ <prefix:foo xmlns:prefix="http://www.unicornland.com/prefix">
329+ <prefix:bar>foobar</prefix:bar>
330+ </prefix:foo>
331+ XML
332+ end
333+ end
302334end
Original file line number Diff line number Diff line change 1414 expect { klass . tag "foo:bar" } . to raise_error HappyMapper ::SyntaxError
1515 end
1616 end
17+
18+ describe "#namespace" do
19+ it "allows string values" do
20+ klass . namespace "foo"
21+ expect ( klass . namespace ) . to eq "foo"
22+ end
23+
24+ it "converts symbol values to string" do
25+ klass . namespace :foo
26+ expect ( klass . namespace ) . to eq "foo"
27+ end
28+ end
1729end
You can’t perform that action at this time.
0 commit comments