Sha256: 515853175f1201744416b0a2f70cd349627b106d2561c145fc341effdd6aa2c8

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

RSpec.shared_context 'database setup' do
  let(:configuration) { ROM::Configuration.new(:sql, DB_URI) }

  let(:conn) { configuration.gateways[:default].connection }

  let(:rom) { ROM.container(configuration) }

  before do
    conn.loggers << LOGGER
  end
end

RSpec.shared_context 'database' do
  include_context 'database setup'

  before do
    [:tags, :tasks, :posts, :users, :posts_labels, :labels, :books,
     :reactions, :messages].each { |table| conn.drop_table?(table) }

    conn.create_table :books do
      primary_key :id
      column :title, String
      column :created_at, Time
      column :updated_at, Time
    end

    conn.create_table :users do
      primary_key :id
      column :name, String
    end

    conn.create_table :tasks do
      primary_key :id
      foreign_key :user_id, :users, null: false, on_delete: :cascade
      column :title, String
    end

    conn.create_table :tags do
      primary_key :id
      foreign_key :task_id, :tasks, null: false, on_delete: :cascade
      column :name, String
    end

    conn.create_table :labels do
      primary_key :id
      column :name, String
    end

    conn.create_table :posts do
      primary_key :id
      foreign_key :author_id, :users, null: false, on_delete: :cascade
      column :title, String, null: false
      column :body, String
    end

    conn.create_table :posts_labels do
      foreign_key :post_id, :labels, null: false, on_delete: :cascade
      foreign_key :label_id, :labels, null: false, on_delete: :cascade
      primary_key [:post_id, :label_id]
    end

    conn.create_table :messages do
      primary_key :message_id
      column :author, String
      column :body, String
    end

    conn.create_table :reactions do
      primary_key :reaction_id
      foreign_key :message_id, :messages, null: false
      column :author, String
    end
  end

  after do
    rom.disconnect
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-repository-1.3.1 spec/shared/database.rb