spec/shared/database.rb in rom-repository-0.2.0 vs spec/shared/database.rb in rom-repository-0.3.0
- old
+ new
@@ -1,16 +1,30 @@
RSpec.shared_context 'database' do
- let(:configuration) { ROM::Configuration.new(:sql, uri).use(:macros) }
+ let(:configuration) { ROM::Configuration.new(:sql, uri) }
let(:conn) { configuration.gateways[:default].connection }
let(:rom) { ROM.container(configuration) }
- let(:uri) { 'postgres://localhost/rom_repository' }
+ 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, :users].each { |table| conn.drop_table?(table) }
+ [: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
@@ -22,8 +36,38 @@
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
+ 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
end