Sha256: c1e69d06e13d1944c33116fb3eb5dabe038dc9c001cc946f7bdddcc96e439511
Contents?: true
Size: 825 Bytes
Versions: 2
Compression:
Stored size: 825 Bytes
Contents
module DatabaseMacros # Run migrations in the test database def run_migration(&block) # Create a new migration class if ActiveRecord.version >= Gem::Version.new('5.0') klass = Class.new(ActiveRecord::Migration[ActiveRecord.version.to_s.to_f]) else klass = Class.new(ActiveRecord::Migration) end # Create a new `up` that executes the argument klass.send(:define_method, :up) { instance_exec(&block) } # Create a new instance of it and execute its `up` method klass.new.up end def setup_database(opts = {}) adapter = "#{opts[:adapter].capitalize}Adapter".constantize.new(database: opts[:database]) adapter.establish_connection! adapter.reset_database! # Silence everything ActiveRecord::Base.logger = ActiveRecord::Migration.verbose = false end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
microscope-1.1.1 | spec/support/macros/database_macros.rb |
microscope-1.1.0 | spec/support/macros/database_macros.rb |