Sha256: 229ff86ce0ca43f0ea871f86ba6e044ffa4cc8bb82fbaecad04306c04fc52c0b

Contents?: true

Size: 974 Bytes

Versions: 3

Compression:

Stored size: 974 Bytes

Contents

shared_context 'database setup' do
  let(:uri) { DB_URI }
  let(:conn) { Sequel.connect(uri) }
  let(:configuration) { ROM::Configuration.new(:sql, conn).use(:macros) }
  let(:container) { ROM.container(configuration) }

  def drop_tables
    [:tasks, :users, :tags, :task_tags, :rabbits, :carrots, :schema_migrations].each do |name|
      conn.drop_table?(name)
    end
  end

  before do
    conn.loggers << LOGGER

    drop_tables

    conn.create_table :users do
      primary_key :id
      String :name, null: false
      index :name, unique: true
      check { char_length(name) > 2 }
    end

    conn.create_table :tasks do
      primary_key :id
      foreign_key :user_id, :users
      String :title
    end

    conn.create_table :tags do
      primary_key :id
      String :name
    end

    conn.create_table :task_tags do
      primary_key [:tag_id, :task_id]
      Integer :tag_id
      Integer :task_id
    end
  end

  after do
    conn.disconnect
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-sql-0.7.0 spec/shared/database_setup.rb
rom-sql-0.7.0.rc1 spec/shared/database_setup.rb
rom-sql-0.7.0.beta1 spec/shared/database_setup.rb