Sha256: 8e85908c2f67757cdc1ebb5a2d38d5cfd9df452ee5bffe063bd3a4750221fe49

Contents?: true

Size: 888 Bytes

Versions: 1

Compression:

Stored size: 888 Bytes

Contents

require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'

describe DataMapper::Serialize, '#to_csv' do
  #
  # ==== blah, it's CSV
  #

  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 CSV" do
    peter = Cow.new
    peter.id = 44
    peter.composite = 344
    peter.name = 'Peter'
    peter.breed = 'Long Horn'
    peter.to_csv.chomp.should == '44,344,Peter,Long Horn'
  end

  it "should serialize a collection to CSV" do
    @collection.to_csv.gsub(/[[:space:]]+\n/, "\n").should ==
      "1,2,Betsy,Jersey\n" +
      "10,20,Berta,Guernsey\n"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-serializer-0.9.2 spec/unit/to_csv_spec.rb