spec/support/matchers/column.rb in chrono_model-0.8.2 vs spec/support/matchers/column.rb in chrono_model-0.9.0
- old
+ new
@@ -19,27 +19,40 @@
end
@matches.values.all?
end
- def failure_message_for_should
- "expected #{@schema}.#{table} to have ".tap do |message|
- message << @matches.map do |(name, type), match|
- "a #{name}(#{type}) column" unless match
- end.compact.to_sentence
- end
+ def failure_message
+ message_matches("expected #{@schema}.#{table} to have")
end
+ def failure_message_when_negated
+ message_matches("expected #{@schema}.#{table} to not have")
+ end
+
protected
def has_column?(name, type)
+ column_type(name) == [name, type]
+ end
+
+ def column_type(name)
table = "#{@schema}.#{self.table}"
- select_rows(<<-SQL, [table, name], 'Check column').first == [name, type]
+ select_rows(<<-SQL, [table, name], 'Check column').first
SELECT attname, FORMAT_TYPE(atttypid, atttypmod)
FROM pg_attribute
- WHERE attrelid = $1::regclass::oid
- AND attname = $2
+ WHERE attrelid = ?::regclass::oid
+ AND attname = ?
SQL
+ end
+
+ private
+ def message_matches(message)
+ (message << ' ').tap do |message|
+ message << @matches.map do |(name, type), match|
+ "a #{name}(#{type}) column" unless match
+ end.compact.to_sentence
+ end
end
end
def have_columns(*args)
HaveColumns.new(*args)