unhappymapper 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -598,6 +598,12 @@ module HappyMapper
598
598
 
599
599
  end
600
600
 
601
+ # Write out to XML, this value was set above, based on whether or not an XML
602
+ # builder object was passed to it as a parameter. When there was no parameter
603
+ # we assume we are at the root level of the #to_xml call and want the actual
604
+ # xml generated from the object. If an XML builder instance was specified
605
+ # then we assume that has been called recursively to generate a larger
606
+ # XML document.
601
607
  write_out_to_xml ? builder.to_xml : builder
602
608
 
603
609
  end
@@ -43,7 +43,7 @@ module HappyMapper
43
43
  if n.respond_to?(:content)
44
44
  typecast(n.content)
45
45
  else
46
- typecast(n.to_s)
46
+ typecast(n)
47
47
  end
48
48
  end
49
49
  elsif constant == XmlContent
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <addresses>
3
+ <address street=""/>
4
+ <address street="Milchstrasse"/>
5
+ <address />
6
+ </addresses>
@@ -530,6 +530,13 @@ class Video
530
530
 
531
531
  end
532
532
 
533
+ class OptionalAttribute
534
+ include HappyMapper
535
+ tag 'address'
536
+
537
+ attribute :street, String
538
+ end
539
+
533
540
 
534
541
  describe HappyMapper do
535
542
 
@@ -882,6 +889,25 @@ describe HappyMapper do
882
889
  l = Location.parse(fixture_file('lastfm.xml'))
883
890
  l.first.latitude.should == "51.53469"
884
891
  end
892
+
893
+ describe "Parse optional attributes" do
894
+
895
+ it "should parse an empty String as empty" do
896
+ a = OptionalAttribute.parse(fixture_file('optional_attributes.xml'))
897
+ a[0].street.should == ""
898
+ end
899
+
900
+ it "should parse a String with value" do
901
+ a = OptionalAttribute.parse(fixture_file('optional_attributes.xml'))
902
+ a[1].street.should == "Milchstrasse"
903
+ end
904
+
905
+ it "should parse a String with value" do
906
+ a = OptionalAttribute.parse(fixture_file('optional_attributes.xml'))
907
+ a[2].street.should be_nil
908
+ end
909
+
910
+ end
885
911
 
886
912
  describe 'Xml Content' do
887
913
  before(:each) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unhappymapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -18,7 +18,7 @@ date: 2011-08-22 00:00:00.000000000Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: nokogiri
21
- requirement: &70134376050820 !ruby/object:Gem::Requirement
21
+ requirement: &70233821937220 !ruby/object:Gem::Requirement
22
22
  none: false
23
23
  requirements:
24
24
  - - ~>
@@ -26,10 +26,10 @@ dependencies:
26
26
  version: 1.4.2
27
27
  type: :runtime
28
28
  prerelease: false
29
- version_requirements: *70134376050820
29
+ version_requirements: *70233821937220
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
- requirement: &70134376050340 !ruby/object:Gem::Requirement
32
+ requirement: &70233821936180 !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ~>
@@ -37,7 +37,7 @@ dependencies:
37
37
  version: 1.3.0
38
38
  type: :development
39
39
  prerelease: false
40
- version_requirements: *70134376050340
40
+ version_requirements: *70233821936180
41
41
  description: Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's
42
42
  Happymapper)
43
43
  email: franklin.webber@gmail.com
@@ -67,6 +67,7 @@ files:
67
67
  - spec/fixtures/lastfm.xml
68
68
  - spec/fixtures/multiple_namespaces.xml
69
69
  - spec/fixtures/multiple_primitives.xml
70
+ - spec/fixtures/optional_attributes.xml
70
71
  - spec/fixtures/pita.xml
71
72
  - spec/fixtures/posts.xml
72
73
  - spec/fixtures/product_default_namespace.xml
@@ -124,6 +125,7 @@ test_files:
124
125
  - spec/fixtures/lastfm.xml
125
126
  - spec/fixtures/multiple_namespaces.xml
126
127
  - spec/fixtures/multiple_primitives.xml
128
+ - spec/fixtures/optional_attributes.xml
127
129
  - spec/fixtures/pita.xml
128
130
  - spec/fixtures/posts.xml
129
131
  - spec/fixtures/product_default_namespace.xml