require File.join( File.dirname(__FILE__), "..", "spec_helper" )
describe DataMapper::Serialize do
class Cow
include DataMapper::Resource
property :id, Integer, :serial => true
property :name, String
property :breed, String
end
before(:all) do
properties = Cow.properties(:default)
properties_with_indexes = Hash[*properties.zip((0...properties.length).to_a).flatten]
@collection = DataMapper::Collection.new(DataMapper::repository(:default), Cow, properties_with_indexes)
@collection.load([1, 'Betsy', 'Jersey'])
@collection.load([10, 'Berta', 'Guernsey'])
end
describe "#to_xml" do
it "should serialize a resource to XML" do
berta = Cow.new
berta.id = 89
berta.name = 'Berta'
berta.breed = 'Guernsey'
berta.to_xml.should == <<-EOS
89BertaGuernsey
EOS
end
it "should serialize a collection to XML" do
@collection.to_xml.gsub(/[[:space:]]+\n/, "\n").should == <<-EOS
1BetsyJersey10BertaGuernsey
EOS
end
end
end