spec/integration/schema/inferrer_spec.rb in rom-sql-2.0.0.beta1 vs spec/integration/schema/inferrer_spec.rb in rom-sql-2.0.0.beta2
- old
+ new
@@ -10,10 +10,14 @@
def trunc_ts(time, drop_usec: false)
usec = drop_usec ? 0 : time.to_time.usec.floor
Time.mktime(time.year, time.month, time.day, time.hour, time.min, time.sec, usec)
end
+ def index_by_name(indexes, name)
+ indexes.find { |idx| idx.name == name }
+ end
+
with_adapters do |adapter|
describe 'inferring attributes' do
before do
dataset = self.dataset
conf.relation(dataset) do
@@ -333,11 +337,14 @@
end
end
end
describe 'inferring indices', oracle: false do
- before do |ex|
+ let(:dataset) { :test_inferrence }
+ let(:source) { ROM::Relation::Name[dataset] }
+
+ it 'infers types with indices' do
conn.create_table :test_inferrence do
primary_key :id
Integer :foo
Integer :bar, null: false
Integer :baz, null: false
@@ -346,20 +353,38 @@
index :bar, name: :bar_idx
index :baz, name: :baz1_idx
index :baz, name: :baz2_idx
index %i(bar baz), name: :composite_idx
+ index %i(foo bar), name: :unique_idx, unique: true
end
conf.relation(:test_inferrence) { schema(infer: true) }
+
+ expect(schema.indexes.map(&:name)).
+ to match_array(%i(foo_idx bar_idx baz1_idx baz2_idx composite_idx unique_idx))
+
+ unique_idx = index_by_name(schema.indexes, :unique_idx)
+
+ expect(unique_idx).to be_unique
end
- let(:dataset) { :test_inferrence }
- let(:source) { ROM::Relation::Name[dataset] }
+ if metadata[:postgres]
+ it 'infers cutsom index types' do
+ pending 'Sequel not returning index type'
+ conn.create_table :test_inferrence do
+ primary_key :id
+ Integer :foo
+ index :foo, name: :foo_idx, type: :gist
+ end
- it 'infers types with indices' do
- expect(schema.indexes.map(&:name)).
- to match_array(%i(foo_idx bar_idx baz1_idx baz2_idx composite_idx))
+ conf.relation(:test_inferrence) { schema(infer: true) }
+
+ index = schema.indexes.first
+
+ expect(index.name).to eql(:foo_idx)
+ expect(index.type).to eql(:gist)
+ end
end
end
end
end