spec/integration/relation_schema_spec.rb in rom-sql-2.0.0.beta1 vs spec/integration/relation_schema_spec.rb in rom-sql-2.0.0.beta2

- old
+ new

@@ -197,7 +197,75 @@ assoc = ROM::Associations::Definitions::ManyToOne.new(:tags, :posts, as: :published_posts) expect(tag_associations[:published_posts].definition).to eql(assoc) end end + + context 'defining indexes', :helpers do |ctx| + it 'allows defining indexes' do + class Test::Tags < ROM::Relation[:sql] + schema(:tags) do + attribute :id, Types::Serial + attribute :name, Types::String + attribute :created_at, Types::Time + attribute :updated_at, Types::Time + + indexes do + index :name + index :created_at, :name + index :updated_at, name: :recently_idx + index :created_at, name: :unique_date, unique: true + end + end + end + + conf.register_relation(Test::Tags) + schema = container.relations[:tags].schema + + expect(schema.indexes.to_a). + to contain_exactly( + ROM::SQL::Index.new([define_attribute(:name, :String, source: schema.name)]), + ROM::SQL::Index.new( + [define_attribute(:created_at, :Time, source: schema.name), + define_attribute(:name, :String, source: schema.name)] + ), + ROM::SQL::Index.new( + [define_attribute(:updated_at, :Time, source: schema.name)], + name: :recently_idx + ), + ROM::SQL::Index.new( + [define_attribute(:created_at, :Time, source: schema.name)], + name: :unique_date, + unique: true + ) + ) + end + + if metadata[:postgres] + it 'can provide index type' do + class Test::Tags < ROM::Relation[:sql] + schema(:tags) do + attribute :id, Types::Serial + attribute :name, Types::String + + indexes do + index :name, type: :gist + end + end + end + + conf.register_relation(Test::Tags) + schema = container.relations[:tags].schema + index = schema.indexes.first + + expect(index).to eql( + ROM::SQL::Index.new( + [define_attribute(:name, :String, source: schema.name)], + type: :gist) + ) + + expect(index.type).to eql(:gist) + end + end + end end end