Class: Spec::Example::MigrationExampleGroup

Inherits:
RSpec::Core::ExampleGroup
  • Object
show all
Includes:
Matchers::Migration
Defined in:
lib/spec/example/migration_example_group.rb

Instance Method Summary collapse

Methods included from Matchers::Migration

#be_primary_key, #have_column, #have_table, #permit_null

Instance Method Details

#all_databasesObject



50
51
52
# File 'lib/spec/example/migration_example_group.rb', line 50

def all_databases
  @@migrations.map(&:database).uniq
end

#migration_nameObject



46
47
48
# File 'lib/spec/example/migration_example_group.rb', line 46

def migration_name
  @migration_name ||= self.class.instance_variable_get('@description_text').to_s
end

#run_migrationObject



42
43
44
# File 'lib/spec/example/migration_example_group.rb', line 42

def run_migration
  this_migration.perform_up
end

#run_prereq_migrationsObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/spec/example/migration_example_group.rb', line 30

def run_prereq_migrations
  # 'running n-1 migrations'
  all_databases.each do |db|
    db.adapter.recreate_database
  end
  @@migrations.sort.each do |migration|
    break if migration.name.to_s == migration_name.to_s

    migration.perform_up
  end
end

#select(sql) ⇒ Object



58
59
60
# File 'lib/spec/example/migration_example_group.rb', line 58

def select(sql)
  this_migration.adapter.select(sql)
end

#table(table_name) ⇒ Object



62
63
64
# File 'lib/spec/example/migration_example_group.rb', line 62

def table(table_name)
  this_migration.adapter.table(table_name)
end

#this_migrationObject



54
55
56
# File 'lib/spec/example/migration_example_group.rb', line 54

def this_migration
  @@migrations.select { |m| m.name.to_s == migration_name }.first
end