spec/happymapper_spec.rb in jimmyz-happymapper-0.3.2 vs spec/happymapper_spec.rb in jimmyz-happymapper-0.3.3

- old
+ new

@@ -168,11 +168,12 @@ element :name, String end class Radar include HappyMapper - has_many :places, Place + # places needs to be deep because it lives out in places/place + has_many :places, Place, :deep => true end class Post include HappyMapper @@ -548,10 +549,16 @@ last_event.address.state.should == 'FL' last_event.address.zip.should == '327506398' track.tran_detail.cust_tran_id.should == '20090102-111321' end + it "should not parse deep for elements unless deep option is set" do + tree = FamilySearch::FamilyTree.parse(fixture_file('family_tree.xml')) + tree.persons.person.size.should_not == 2 + tree.persons.person.size.should == 1 + end + it "should parse family search xml" do tree = FamilySearch::FamilyTree.parse(fixture_file('family_tree.xml')) tree.version.should == '1.0.20071213.942' tree.status_message.should == 'OK' tree.status_code.should == '200' @@ -593,10 +600,16 @@ doc.should match_xpath("/address/postcode","26131") doc.should match_xpath("/address/city","Oldenburg") doc.should match_xpath("/address/country","Germany") end + it "should include an xml version/encoding header" do + address = Address.new + xml = address.to_xml + xml.should =~ /<?xml version=".*" encoding=".*"?>/ + end + it "should return xml with non-primitive elements from ruby objects" do posts = Posts.parse(fixture_file('posts.xml')) xml = posts.to_xml doc = REXML::Document.new xml doc.should have_nodes("/posts",1) @@ -643,9 +656,16 @@ ft = FamilySearch::FamilyTree.new #ft has nil persons element should not raise error lambda{ ft.to_xml }.should_not raise_error + + # Check for nil elements of primitive type + info = FamilySearch::Information.new + namespace = {'fsapi-v1' => 'http://api.familysearch.org/v1'} + doc = REXML::Document.new info.to_xml + doc.should have_nodes("/fsapi-v1:information/fsapi-v1:gender",0,namespace) + doc.should have_nodes("/fsapi-v1:information/fsapi-v1:living",0,namespace) end describe "with namespace url and prefix" do before(:all) do ft = FamilySearch::FamilyTree.parse(fixture_file('family_tree.xml'))