Sha256: c4bede29433fec8ca58e4b991866ea9d7c4b34aeda13d4091d28cf17c5305e26

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require 'pp'

ENV['LOG_NAME'] = 'spec'
require File.dirname(__FILE__) + '/../environment'

# Define a fixtures helper method to load up our test data.
def fixtures(name)
  entry = YAML::load_file(File.dirname(__FILE__) + "/fixtures/#{name}.yaml")
  klass = begin
    Kernel::const_get(Inflector.classify(Inflector.singularize(name)))
  rescue
    nil
  end
  
  unless klass.nil?  
    database.logger.debug { "AUTOMIGRATE: #{klass}" }
    klass.auto_migrate!
  
    (entry.kind_of?(Array) ? entry : [entry]).each do |hash|
      if hash['type']
        Object::const_get(hash['type'])::create(hash)
      else
        klass::create(hash)
      end
    end
  else
    # TODO: Get rid of the stupid AnimalsExhibit model...
    table = database.table(name.to_s)
    table.create! true
    
    pp database.schema
    
    (entry.kind_of?(Array) ? entry : [entry]).each do |hash|  
      table.insert(hash)
    end
  end
end

# Pre-fill the database so non-destructive tests don't need to reload fixtures.
Dir[File.dirname(__FILE__) + "/fixtures/*.yaml"].each do |path|
  fixtures(File::basename(path).sub(/\.yaml$/, ''))
end

Version data entries

2 entries across 2 versions & 1 rubygems

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