Sha256: 7c58ab9eb82ec6c8fb16ad7a960a4ee7474765bc2a0fc44c84acab6b8672ccd4

Contents?: true

Size: 1.81 KB

Versions: 4

Compression:

Stored size: 1.81 KB

Contents

require File.dirname(__FILE__) + '/../test_helper.rb'

context "xml serializer" do
  setup do 
    Person.restful_publish(:name, :current_location, :pets, :wallet, :created_at)
    Pet.restful_publish(:name)
    Wallet.restful_publish(:contents)
  
    @person = Person.create(:name => "Joe Bloggs", :current_location => "Under a tree", :birthday => "1990-03-09")
    @pet = @person.pets.create(:species => "cat", :age => 200, :name => "mietze")
    @wallet = @person.wallet = Wallet.new(:contents => "an old photo, 5 euros in coins")
    @person.save
  end

  teardown do
    reset_config
  end

  specify "deserialize from rails style xml" do
    restful = @person.to_restful
    expected = restful.serialize(:xml)
    serializer = Restful::Serializers::XMLSerializer.new
    resource = serializer.deserialize(expected)    
    actual = serializer.serialize(resource)

    xml_should_eql(expected, actual)
  end
  
  specify "should serialize date type correctly" do
    xml_should_eql_fixture(@person.to_restful_xml(:birthday), "people", :joe_with_birthday)  
  end
  
  specify "should convert a NULL inner association such as person.wallet to a link with a null value" do
    @person.wallet = nil

    xml_should_eql_fixture(@person.to_restful_xml(:restful_options => { :expansion => :collapsed }), "people", :verbose_no_pets)
  end
  
  specify "serialize to xml, rails style" do
    xml_should_eql_fixture(@person.to_restful_xml, "people", :with_pets_and_expanded_wallet)
  end
  
  specify "should serialize hashes correctly" do
    @person.pets.create(:species => "cat", :age => 100, :name => "motze")
    xml_should_eql_fixture(@person.to_restful_xml(:pets_ages_hash), "people", :hashy_person)
  end
    
  specify "should serialize collections correctly" do
    xml_should_eql_fixture(@person.pets.to_restful_xml, "pets", :pets_array)
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
moviepilot-restful-0.2.18 test/serializers/xml_serializer_test.rb
moviepilot-restful-0.2.19 test/serializers/xml_serializer_test.rb
moviepilot-restful-0.2.20 test/serializers/xml_serializer_test.rb
restful-0.2.20 test/serializers/xml_serializer_test.rb