Sha256: 82db42259d6b227a754d4545a7f5651dac2bb0efcd907bc7455b0f0b3325f9a3
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 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 = $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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
chrono_model-0.8.2 | spec/support/matchers/index.rb |
chrono_model-0.8.0 | spec/support/matchers/index.rb |