nokogiri-happymapper 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/happymapper.rb CHANGED
@@ -250,7 +250,9 @@ module HappyMapper
250
250
  namespace = options[:namespace]
251
251
  elsif namespaces.has_key?("xmlns")
252
252
  namespace ||= DEFAULT_NS
253
- namespaces[namespace] = namespaces.delete("xmlns")
253
+ default_namespace = namespaces.delete("xmlns")
254
+ namespaces[namespace] ||= default_namespace
255
+ namespaces["xmlns:#{namespaces.key(default_namespace)}"] = default_namespace
254
256
  elsif namespaces.has_key?(DEFAULT_NS)
255
257
  namespace ||= DEFAULT_NS
256
258
  end
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0"?>
2
+ <bk:book xmlns="urn:ISBN:0-395-36341-6" xmlns:bk="urn:loc.gov:books">
3
+ <bk:title>Cheaper by the Dozen</bk:title>
4
+ <number>1568491379</number>
5
+ </bk:book>
@@ -535,8 +535,21 @@ class OptionalAttribute
535
535
  tag 'address'
536
536
 
537
537
  attribute :street, String
538
- end
538
+ end
539
+
540
+ class DefaultNamespaceCombi
541
+ include HappyMapper
542
+
539
543
 
544
+ register_namespace 'bk', "urn:loc.gov:books"
545
+ register_namespace 'isbn', "urn:ISBN:0-395-36341-6"
546
+ namespace 'bk'
547
+
548
+ tag 'book'
549
+
550
+ element :title, String, :namespace => 'bk', :tag => "title"
551
+ element :number, String, :namespace => 'isbn', :tag => "number"
552
+ end
540
553
 
541
554
  describe HappyMapper do
542
555
 
@@ -925,6 +938,22 @@ describe HappyMapper do
925
938
  end
926
939
 
927
940
  end
941
+
942
+ describe "Default namespace combi" do
943
+ before(:each) do
944
+ file_contents = fixture_file('default_namespace_combi.xml')
945
+ @book = DefaultNamespaceCombi.parse(file_contents, :single => true)
946
+ end
947
+
948
+ it "should parse title" do
949
+ @book.title.should == "Cheaper by the Dozen"
950
+ end
951
+
952
+ it "should parse number" do
953
+ @book.number.should == "1568491379"
954
+ end
955
+
956
+ end
928
957
 
929
958
  describe 'Xml Content' do
930
959
  before(:each) do
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.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -71,6 +71,7 @@ files:
71
71
  - spec/fixtures/atom.xml
72
72
  - spec/fixtures/commit.xml
73
73
  - spec/fixtures/current_weather.xml
74
+ - spec/fixtures/default_namespace_combi.xml
74
75
  - spec/fixtures/dictionary.xml
75
76
  - spec/fixtures/family_tree.xml
76
77
  - spec/fixtures/inagy.xml
@@ -129,6 +130,7 @@ test_files:
129
130
  - spec/fixtures/atom.xml
130
131
  - spec/fixtures/commit.xml
131
132
  - spec/fixtures/current_weather.xml
133
+ - spec/fixtures/default_namespace_combi.xml
132
134
  - spec/fixtures/dictionary.xml
133
135
  - spec/fixtures/family_tree.xml
134
136
  - spec/fixtures/inagy.xml