Module: RSpec::Sequel::MigrationExampleGroup::ClassMethods

Defined in:
lib/rspec/sequel/migration_example_group.rb

Instance Method Summary collapse

Instance Method Details

#postgres_schema(&block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rspec/sequel/migration_example_group.rb', line 20

def postgres_schema &block
  db = Sequel::DATABASES.find { |db| db.database_type == :postgres }
  raise "Please connect to a Postgres database (eg. in spec_helper) before using ::postgres_schema." unless db
  db = Sequel.connect(db.opts.merge search_path: ['spec'])
  db.drop_schema :spec, cascade: true, if_exists: true
  before(:all) do
    db.create_schema :spec
    db.instance_eval &block if block
  end
  let(:db) { db }
  after(:all) { db.drop_schema :spec, cascade: true, if_exists: true }
  around(:each) { |ex|  db.transaction(rollback: :always) { ex.run  } }
end