Sha256: b6fbdf30d2e4ceb9271c8fadcfd329c4e3e126032477d74de134d9051ff6b057

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

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)
    
    @time = DateTime.now
    

    @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)
    <cow>
      <id type='integer'>89</id>
      <composite type='integer'>34</composite>
      <name>Berta</name>
      <breed>Guernsey</breed>
    </cow>
  EOS
  end

  it "should serialize a collection to XML" do
    @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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-serializer-0.9.3 spec/unit/to_xml_spec.rb