Sha256: 19334120d4e199b7b804cce0219a875b66d0a490dc35a2ce8c9f7a0662b30158

Contents?: true

Size: 1.17 KB

Versions: 12

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/partisan/templates/migration.rb', __FILE__)
    AddFollowsMigration.new.up
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
partisan-0.5.1 spec/support/macros/database_macros.rb
partisan-0.5 spec/support/macros/database_macros.rb
partisan-0.4.2 spec/support/macros/database_macros.rb
partisan-0.4.1 spec/support/macros/database_macros.rb
partisan-0.4 spec/support/macros/database_macros.rb
partisan-0.3 spec/support/macros/database_macros.rb
partisan-0.2.3 spec/support/macros/database_macros.rb
partisan-0.2.2 spec/support/macros/database_macros.rb
partisan-0.2.1 spec/support/macros/database_macros.rb
partisan-0.2 spec/support/macros/database_macros.rb
partisan-0.1.1 spec/support/macros/database_macros.rb
partisan-0.1 spec/support/macros/database_macros.rb