Sha256: 691da18b4d14e05c681c3e719d32b6563f911e4e22cee26e4b2e6770543f4e68
Contents?: true
Size: 1.17 KB
Versions: 2
Compression:
Stored size: 1.17 KB
Contents
module DatabaseMacros # Run migrations in the test database def run_migration(&block) # Create a new migration class klass = Class.new(ActiveRecord::Migration) # Create a new `up` that executes the argument klass.send(:define_method, :up) { self.instance_exec(&block) } # Create a new instance of it and execute its `up` method klass.new.up end def self.database_file @database_file || File.expand_path('../test.db', __FILE__) end def setup_database # Make sure the test database file is gone cleanup_database # Establish the connection SQLite3::Database.new FileUtils.touch(DatabaseMacros.database_file).first ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: DatabaseMacros.database_file) # Silence everything ActiveRecord::Base.logger = ActiveRecord::Migration.verbose = false end def cleanup_database FileUtils.rm(DatabaseMacros.database_file) if File.exists?(DatabaseMacros.database_file) end # Run the built-in migration def run_default_migration load File.expand_path('../../../../lib/generators/camaraderie/templates/migration.rb', __FILE__) AddCamaraderie.new.up end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
camaraderie-0.2.1 | spec/support/macros/database_macros.rb |
camaraderie-0.2 | spec/support/macros/database_macros.rb |