spec/integration/schema/inferrer_spec.rb in rom-sql-1.3.5 vs spec/integration/schema/inferrer_spec.rb in rom-sql-2.0.0.beta1
- old
+ new
@@ -37,26 +37,19 @@
context 'for a table with FKs' do
let(:dataset) { :tasks }
let(:source) { ROM::Relation::Name[:tasks] }
it 'can infer attributes for dataset' do |ex|
- if mysql?(ex)
- indexes = { index: %i(user_id).to_set }
- else
- indexes = {}
- end
-
expect(schema.to_h).
to eql(
id: ROM::SQL::Types::Serial.meta(name: :id, source: source),
title: ROM::SQL::Types::String.meta(limit: 255).optional.meta(name: :title, source: source),
user_id: ROM::SQL::Types::Int.optional.meta(
name: :user_id,
foreign_key: true,
source: source,
- target: :users,
- **indexes
+ target: :users
)
)
end
end
@@ -187,15 +180,15 @@
describe 'using commands with inferred schema' do
before do
inferrable_relations.concat %i(people)
end
- let(:relation) { container.relation(:people) }
+ let(:relation) { container.relations[:people] }
before do
conf.relation(:people) do
- schema(dataset, infer: true)
+ schema(infer: true)
end
conf.commands(:people) do
define(:create) do
result :one
@@ -354,23 +347,19 @@
index :baz, name: :baz1_idx
index :baz, name: :baz2_idx
index %i(bar baz), name: :composite_idx
end
+
+ conf.relation(:test_inferrence) { schema(infer: true) }
end
let(:dataset) { :test_inferrence }
let(:source) { ROM::Relation::Name[dataset] }
it 'infers types with indices' do
- int = ROM::SQL::Types::Int
- expect(schema.to_h).
- to eql(
- id: int.meta(name: :id, source: source, primary_key: true),
- foo: int.optional.meta(name: :foo, source: source, index: %i(foo_idx).to_set),
- bar: int.meta(name: :bar, source: source, index: %i(bar_idx composite_idx).to_set),
- baz: int.meta(name: :baz, source: source, index: %i(baz1_idx baz2_idx).to_set)
- )
+ expect(schema.indexes.map(&:name)).
+ to match_array(%i(foo_idx bar_idx baz1_idx baz2_idx composite_idx))
end
end
end
end