Sha256: 53a701e030dee4101f8cb285f6ab735fd8cea02044c01c65f6fb6bbb7948544a

Contents?: true

Size: 1.92 KB

Versions: 10

Compression:

Stored size: 1.92 KB

Contents

RSpec.shared_context 'database' do
  let(:configuration) { ROM::Configuration.new(:sql, uri) }
  let(:conn) { configuration.gateways[:default].connection }
  let(:rom) { ROM.container(configuration) }
  let(:uri) do
    if defined? JRUBY_VERSION
      'jdbc:postgresql://localhost/rom_repository'
    else
      'postgres://localhost/rom_repository'
    end
  end

  before do
    conn.loggers << LOGGER

    [: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

10 entries across 10 versions & 1 rubygems

Version Path
rom-repository-1.2.0 spec/shared/database.rb
rom-repository-1.1.0 spec/shared/database.rb
rom-repository-1.0.2 spec/shared/database.rb
rom-repository-1.0.1 spec/shared/database.rb
rom-repository-1.0.0 spec/shared/database.rb
rom-repository-1.0.0.rc2 spec/shared/database.rb
rom-repository-1.0.0.rc1 spec/shared/database.rb
rom-repository-1.0.0.beta3 spec/shared/database.rb
rom-repository-1.0.0.beta2 spec/shared/database.rb
rom-repository-1.0.0.beta1 spec/shared/database.rb