Sha256: 5e2334b6f4d007d52be9299a3272ddbd258f5cf97586cdb3a74abee5cd1369cc

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

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

describe DataMapper::Support::Serialization do
  
  before(:all) do
    fixtures(:animals)
  end
  
  it "should serialize to YAML" do
    Animal.first(:name => 'Frog').to_yaml.should == <<-EOS.margin
      --- 
      id: 1
      name: Frog
      notes: I am a Frog!
      
    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>
      </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!"
      }
    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

1 entries across 1 versions & 1 rubygems

Version Path
datamapper-0.2.3 spec/serialization_spec.rb