Sha256: f7783302ea7d1e4a6890b5f7e6691bf605fecd3f21bd37da64524986a404622d

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

require File.dirname(__FILE__) + "/spec_helper"

describe DataMapper::Support::Serialization do
  
  before(:all) do
    fixtures(:animals)
    fixtures(:zoos)
  end
  
  it "should serialize to YAML" do
    Animal.first(:name => 'Frog').to_yaml.strip.should == <<-EOS.margin
      --- 
      id: 1
      name: Frog
      notes: I am a Frog!
      nice: false
    EOS
  end
  
  it "should serialize to XML" do
    Animal.first(:name => 'Frog').to_xml.should == <<-EOS.compress_lines(false)
      <animal id="1">
        <name>Frog</name>
        <notes>I am a Frog!</notes>
        <nice>false</nice>
      </animal>
    EOS
    
    san_diego_zoo = Zoo.first(:name => 'San Diego')
    san_diego_zoo.to_xml.should == <<-EOS.compress_lines(false)
      <zoo id="2">
        <name>San Diego</name>
        <notes/>
        <updated_at>#{san_diego_zoo.updated_at.dup}</updated_at>
      </zoo>
    EOS
  end
  
  it "should serialize to JSON" do
    
    Animal.first(:name => 'Frog').to_json.should == <<-EOS.compress_lines
      {
        "id": 1,
        "name": "Frog",
        "notes": "I am a Frog!",
        "nice": false
      }
    EOS
    
    san_diego_zoo = Zoo.first(:name => 'San Diego')
    san_diego_zoo.to_json.should == <<-EOS.compress_lines
      {
        "id": 2,
        "name": "San Diego",
        "notes": null,
        "updated_at": #{san_diego_zoo.updated_at.dup.to_json}
      }
    EOS
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
datamapper-0.2.4 spec/serialization_spec.rb
datamapper-0.2.5 spec/serialization_spec.rb