Sha256: cf30a000fb59a58f658d20c3efcc7d71e950015f213b777ef4f3f50370a5efc1

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require File.join(File.dirname(__FILE__), '..',  %w[spec_helper])

require "dm-core"
require 'dm-migrations'
DataMapper.setup(:default, 'sqlite3::memory:')

class Cat
  include DataMapper::Resource
  property :id, Serial
  property :name, String
  property :age, Integer

  include CheapImports
end

class Appointment
  include DataMapper::Resource
  property :id, Serial
  property :cat_id, Integer
  property :starts_at, DateTime
  
  include CheapImports
  imports :legacy_data => {
    :starts_at => "APPOINTMENT START TIME",
    :starts_at_format => "%d %b %Y %H:%M",
    :cat_name => "ANIMAL IDENTIFIER"
  }
end

DataMapper.finalize
DataMapper.auto_migrate!

describe Cat, "importing default" do
  it "should import without any config" do
    data = %{name\tage\nFluffy\t7}
    imported_cats = Import.import(Cat, data)
    
    cats_named_fluffy = Cat.all(:name => "Fluffy")
    
    cats_named_fluffy.should have(1).items
    cats_named_fluffy.first.age.should eql(7)
  end
end

describe Appointment, "importing a specified config" do
  it "should description" do
    data = %{ANIMAL IDENTIFIER,APPOINTMENT START TIME\n}
    data << %{Fluffy,5 Jan 2009 10:30\n}
    
    appointments = Import.import(Appointment, data)
    a = appointments.first

    a.starts_at.should eql(DateTime.new(2009, 1, 5, 10, 30))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cheap_imports-0.0.4 spec/orms/datamapper_spec.rb