Class: RspecSequel::Matchers::HaveColumnMatcher

Inherits:
Base
  • Object
show all
Defined in:
lib/rspec_sequel/matchers/have_column.rb

Instance Method Summary collapse

Methods inherited from Base

#failure_message, #failure_message_when_negated, #hash_to_nice_string, #initialize, #matches?

Constructor Details

This class inherits a constructor from RspecSequel::Base

Instance Method Details

#descriptionObject



5
6
7
8
9
# File 'lib/rspec_sequel/matchers/have_column.rb', line 5

def description
  desc = "have a column #{@attribute.inspect}"
  desc << " with type #{@options[:type]}" if @options[:type]
  desc
end

#valid?(db, i, c, attribute, options) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rspec_sequel/matchers/have_column.rb', line 11

def valid?(db, i, c, attribute, options)

  # check column existance
  col = db.schema(c.table_name).detect{|col| col[0]==attribute}
  matching = !col.nil?

  # check type
  if @options[:type]
    expected = db.send(:type_literal, {:type => options[:type]}).to_s
    if matching
      found = [col[1][:type].to_s, col[1][:db_type].to_s]
      @suffix << "(type found: #{found.uniq.join(", ")})"
      matching &&= found.include?(expected)
    end
  end
  matching
end