Sha256: 899dfd05560a27be12518d14663dc820a733c375c18f58bd3b17f60a10885988

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

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

context "params 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_with_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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
purzelrakete-restful-0.2.2 test/serializers/xml_serializer_test.rb
purzelrakete-restful-0.2.3 test/serializers/xml_serializer_test.rb