spec/unit/to_xml_spec.rb in dm-serializer-0.9.2 vs spec/unit/to_xml_spec.rb in dm-serializer-0.9.3
- old
+ new
@@ -6,10 +6,13 @@
# ==== enterprisey XML
#
before(:all) do
query = DataMapper::Query.new(DataMapper::repository(:default), Cow)
+
+ @time = DateTime.now
+
@collection = DataMapper::Collection.new(query) do |c|
c.load([1, 2, 'Betsy', 'Jersey'])
c.load([10, 20, 'Berta', 'Guernsey'])
end
@@ -33,10 +36,38 @@
</cow>
EOS
end
it "should serialize a collection to XML" do
- @collection.to_xml.gsub(/[[:space:]]+\n/, "\n").should ==
- "<cow><id type='integer'>1</id><composite type='integer'>2</composite><name>Betsy</name><breed>Jersey</breed></cow>\n" +
- "<cow><id type='integer'>10</id><composite type='integer'>20</composite><name>Berta</name><breed>Guernsey</breed></cow>\n"
+ @collection.to_xml.should == <<-EOS.compress_lines(false)
+ <cows type='array'>
+ <cow>
+ <id type='integer'>1</id>
+ <composite type='integer'>2</composite>
+ <name>Betsy</name>
+ <breed>Jersey</breed>
+ </cow>
+ <cow>
+ <id type='integer'>10</id>
+ <composite type='integer'>20</composite>
+ <name>Berta</name>
+ <breed>Guernsey</breed>
+ </cow>
+ </cows>
+ EOS
end
+
+ describe "multiple repositories" do
+ before(:all) do
+ QuantumCat.auto_migrate!
+ repository(:alternate){QuantumCat.auto_migrate!}
+ end
+
+ it "should use the repsoitory for the model" do
+ gerry = QuantumCat.create(:name => "gerry")
+ george = repository(:alternate){QuantumCat.create(:name => "george", :is_dead => false)}
+ gerry.to_xml.should_not match(/is_dead/)
+ george.to_xml.should match(/is_dead/)
+ end
+ end
+
end