Sha256: 297a9d4beee3756f215666fb487b2fb9820dbddb7926de443073a9f0172ae638

Contents?: true

Size: 1.56 KB

Versions: 9

Compression:

Stored size: 1.56 KB

Contents

## $:.unshift(File.dirname(__FILE__))

## minitest setup

# require 'minitest/unit'
require 'minitest/autorun'

# include MiniTest::Unit  # lets us use TestCase instead of MiniTest::Unit::TestCase


# our own code

require 'beerdb'
require 'logutils/db'   # NOTE: explict require required for LogDb (not automatic) 


Country = WorldDb::Model::Country
Region  = WorldDb::Model::Region

## todo: get all models aliases (e.g. from console script)

Beer    = BeerDb::Model::Beer
Brand   = BeerDb::Model::Brand
Brewery = BeerDb::Model::Brewery


def setup_in_memory_db
  # Database Setup & Config

  db_config = {
    adapter:  'sqlite3',
    database: ':memory:'
  }

  pp db_config

  ActiveRecord::Base.logger = Logger.new( STDOUT )
  ## ActiveRecord::Base.colorize_logging = false  - no longer exists - check new api/config setting?

  ## NB: every connect will create a new empty in memory db
  ActiveRecord::Base.establish_connection( db_config )


  ## build schema

  LogDb.create
  ConfDb.create
  TagDb.create
  WorldDb.create
  BeerDb.create
end

def fillup_in_memory_db
  ## add some counties

  at = Country.create!( key: 'at', title: 'Austria', code: 'AUT', pop: 0, area: 0 )
  Region.create!( key: 'w', title: 'Wien', country_id: at.id )
  
  de = Country.create!( key: 'de', title: 'Germany', code: 'DEU', pop: 0, area: 0 )
  Region.create!( key: 'by', title: 'Bayern', country_id: de.id )
  
end

setup_in_memory_db()
fillup_in_memory_db()

AT   =  Country.find_by_key!( 'at' )
W    =  Region.find_by_key!( 'w' )

DE   =  Country.find_by_key!( 'de' )
BY   =  Region.find_by_key!( 'by' )

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
beerdb-0.9.13 test/helper.rb
beerdb-0.9.12 test/helper.rb
beerdb-0.9.11 test/helper.rb
beerdb-0.9.10 test/helper.rb
beerdb-0.9.9 test/helper.rb
beerdb-0.9.8 test/helper.rb
beerdb-0.9.7 test/helper.rb
beerdb-0.9.6 test/helper.rb
beerdb-0.9.5 test/helper.rb