Sha256: 201207aa8656fa2ef394878357fce0b068d78a69a4a5907cdd4c82495213c82b
Contents?: true
Size: 1.52 KB
Versions: 8
Compression:
Stored size: 1.52 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 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 = $1 AND i.relname = $2 AND i.relnamespace = ( SELECT oid FROM pg_namespace WHERE nspname = $3 ) ORDER BY a.attname SQL end def failure_message_for_should "expected #{schema}.#{table} to 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
8 entries across 8 versions & 1 rubygems