def in_memory_database?
  return false unless Rails.env == "test"

  db_config = Rails.configuration.database_configuration['test']

  db_config && db_config['adapter'] == 'sqlite3' && db_config['database'] == ':memory:'
end

if in_memory_database?
  puts "creating sqlite in memory database"
  load "#{Rails.root}/db/schema.rb"
end

Fix in-memory database schema for tests
Fix in-memory database schema for tests

The "rake spec" command does not really work with default in-memory sqlite
database:

  $ rake spec
  [ ... snip ... ]
  Finished in 0.01067 seconds
  19 examples, 15 failures, 4 pending

Fix that by using the following trick by Chris Roos:

  http://calicowebdev.com/2011/01/25/rails-3-sqlite-3-in-memory-databases/

to make sure we load schema to the in-memory database for tests.

Signed-off-by: Pekka Enberg <add4fcd06328a394f0ad91feda7ee057316dc5ed@kernel.org>
