Sha256: af719f0466d4169424a9af3df52b004af72df4a7c3de7226de8da7fb12d9fd06

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 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
    table = database.table(name.to_s)
    table.create! true
    table.activate_associations!

    #pp database.schema

    (entry.kind_of?(Array) ? entry : [entry]).each do |hash|
      table.insert(hash)
    end
  end
end

def load_database
  Dir[File.dirname(__FILE__) + "/fixtures/*.yaml"].each do |path|
    fixtures(File::basename(path).sub(/\.yaml$/, ''))
  end
end

load_database

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
datamapper-0.3.0 spec/spec_helper.rb
datamapper-0.3.2 spec/spec_helper.rb
datamapper-0.3.1 spec/spec_helper.rb