Sha256: 5cc67e075cc73a4156ae5dfff7305699209090a4eb0d18e8b14d3f69f567a33a
Contents?: true
Size: 1.68 KB
Versions: 20
Compression:
Stored size: 1.68 KB
Contents
module ChronoTest::Matchers module Index class HaveIndex < ChronoTest::Matchers::Base attr_reader :name, :columns, :schema def initialize(name, columns, schema = 'public') @name = name @columns = columns.sort @schema = schema end def description 'have index' end def matches?(table) super(table) select_values(<<-SQL, [ table, name, schema ], 'Check index') == columns SELECT a.attname FROM pg_class t JOIN pg_index d ON t.oid = d.indrelid JOIN pg_class i ON i.oid = d.indexrelid JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(d.indkey) WHERE i.relkind = 'i' AND t.relname = ? AND i.relname = ? AND i.relnamespace = ( SELECT oid FROM pg_namespace WHERE nspname = ? ) ORDER BY a.attname SQL end def failure_message "expected #{schema}.#{table} to have a #{name} index on #{columns}" end def failure_message_when_negated "expected #{schema}.#{table} to not have a #{name} index on #{columns}" end end def have_index(*args) HaveIndex.new(*args) end class HaveTemporalIndex < HaveIndex def initialize(name, columns) super(name, columns, temporal_schema) end end def have_temporal_index(*args) HaveTemporalIndex.new(*args) end class HaveHistoryIndex < HaveIndex def initialize(name, columns) super(name, columns, history_schema) end end def have_history_index(*args) HaveHistoryIndex.new(*args) end end end
Version data entries
20 entries across 20 versions & 1 rubygems