spec/integration/schema_inference_spec.rb in rom-sql-0.9.1 vs spec/integration/schema_inference_spec.rb in rom-sql-1.0.0.beta1
- old
+ new
@@ -17,29 +17,32 @@
end
end
context 'for simple table' do
let(:dataset) { :users }
+ let(:source) { ROM::Relation::Name[dataset] }
it 'can infer attributes for dataset' do
- expect(schema.attributes).to eql(
- id: ROM::SQL::Types::Serial.meta(name: :id),
- name: ROM::SQL::Types::String.meta(name: :name)
+ expect(schema.to_h).to eql(
+ id: ROM::SQL::Types::Serial.meta(name: :id, source: source),
+ name: ROM::SQL::Types::String.meta(name: :name, source: source)
)
end
end
context 'for a table with FKs' do
let(:dataset) { :tasks }
+ let(:source) { ROM::Relation::Name[:tasks] }
it 'can infer attributes for dataset' do
- expect(schema.attributes).to eql(
- id: ROM::SQL::Types::Serial.meta(name: :id),
- title: ROM::SQL::Types::String.optional.meta(name: :title),
+ expect(schema.to_h).to eql(
+ id: ROM::SQL::Types::Serial.meta(name: :id, source: source),
+ title: ROM::SQL::Types::String.optional.meta(name: :title, source: source),
user_id: ROM::SQL::Types::Int.optional.meta(name: :user_id,
foreign_key: true,
- relation: :users)
+ source: source,
+ target: :users)
)
end
end
context 'for complex table' do
@@ -61,19 +64,20 @@
end
end
end
let(:dataset) { :test_inferrence }
+ let(:source) { ROM::Relation::Name[dataset] }
it 'can infer attributes for dataset' do
- expect(schema.attributes).to eql(
- id: ROM::SQL::Types::Serial.meta(name: :id),
- text: ROM::SQL::Types::String.meta(name: :text),
- flag: ROM::SQL::Types::Bool.meta(name: :flag),
- date: ROM::SQL::Types::Date.optional.meta(name: :date),
- datetime: ROM::SQL::Types::Time.meta(name: :datetime),
- data: ROM::SQL::Types::Blob.optional.meta(name: :data)
+ expect(schema.to_h).to eql(
+ id: ROM::SQL::Types::Serial.meta(name: :id, source: source),
+ text: ROM::SQL::Types::String.meta(name: :text, source: source),
+ flag: ROM::SQL::Types::Bool.meta(name: :flag, source: source),
+ date: ROM::SQL::Types::Date.optional.meta(name: :date, source: source),
+ datetime: ROM::SQL::Types::Time.meta(name: :datetime, source: source),
+ data: ROM::SQL::Types::Blob.optional.meta(name: :data, source: source)
)
end
end
end
@@ -221,9 +225,22 @@
end
end
end
end
end
+ end
+ end
+ end
+
+ with_adapters(:postgres) do
+ context 'with a table without columns' do
+ before do
+ conn.create_table(:dummy) unless conn.table_exists?(:dummy)
+ conf.relation(:dummy) { schema(infer: true) }
+ end
+
+ it 'does not fail with a weird error when a relation does not have attributes' do
+ expect(container.relations[:dummy].schema).to be_empty
end
end
end
end