class SimpleFixture

Constants

CONFIG_DIR
DB_DIR
DB_NAME
FIXTURES_DIR
MIGRATION_FILE
MODELS_FILE
VERSION

Public Class Methods

migrate(&block) click to toggle source
# File lib/simple_fixture.rb, line 15
def migrate(&block)
  Class.new(ActiveRecord::Migration::Current) do
    define_method :change do
      instance_eval &block
    end
  end.new.change
end
new() click to toggle source
# File lib/simple_fixture.rb, line 24
def initialize
  build_db_file
  establish_connection

  ActiveRecord::Base.logger = Logger.new(STDOUT)
  load MIGRATION_FILE
  load MODELS_FILE
  ActiveRecord::FixtureSet.create_fixtures(FIXTURES_DIR, ymls)
end

Private Instance Methods

build_db_file() click to toggle source
# File lib/simple_fixture.rb, line 40
def build_db_file
  Dir.mkdir DB_DIR unless Dir.exists? DB_DIR
  path = File.join(DB_DIR, "#{DB_NAME}.splite3")
  File.delete(path) if File.exists? path
  @path = path
end
establish_connection() click to toggle source
# File lib/simple_fixture.rb, line 47
def establish_connection
  ::ActiveRecord::Base.configurations = {test: {adapter: 'sqlite3', database: @path}}.with_indifferent_access
  ::ActiveRecord::Base.establish_connection(:test)
rescue => _
  ::ActiveRecord::Base.establish_connection('test')
end
ymls() click to toggle source
# File lib/simple_fixture.rb, line 36
def ymls
  Dir[File.join(FIXTURES_DIR, '*.yml')].map{ |f| File.basename(f, '.*') }
end