require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
describe DataMapper::Serialize, '#to_xml' do
#
# ==== enterprisey XML
#
before(:all) do
query = DataMapper::Query.new(DataMapper::repository(:default), Cow)
@collection = DataMapper::Collection.new(query) do |c|
c.load([1, 2, 'Betsy', 'Jersey'])
c.load([10, 20, 'Berta', 'Guernsey'])
end
@empty_collection = DataMapper::Collection.new(query) {}
end
it "should serialize a resource to XML" do
berta = Cow.new
berta.id = 89
berta.composite = 34
berta.name = 'Berta'
berta.breed = 'Guernsey'
berta.to_xml.should == <<-EOS.compress_lines(false)
89
34
Berta
Guernsey
EOS
end
it "should serialize a collection to XML" do
@collection.to_xml.gsub(/[[:space:]]+\n/, "\n").should ==
"12BetsyJersey\n" +
"1020BertaGuernsey\n"
end
end