Class: Shoulda::ActiveRecord::Matchers::HaveDbColumnMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/active_record/matchers/have_db_column_matcher.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(macro, column) ⇒ HaveDbColumnMatcher

Returns a new instance of HaveDbColumnMatcher.



23
24
25
26
# File 'lib/shoulda/active_record/matchers/have_db_column_matcher.rb', line 23

def initialize(macro, column)
  @macro  = macro
  @column = column
end

Instance Method Details

#descriptionObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/shoulda/active_record/matchers/have_db_column_matcher.rb', line 61

def description
  desc = "have db column named #{@column}"
  desc << " of type #{@column_type}"    unless @column_type.nil?
  desc << " of precision #{@precision}" unless @precision.nil?
  desc << " of limit #{@limit}"         unless @limit.nil?
  desc << " of default #{@default}"     unless @default.nil?
  desc << " of null #{@null}"           unless @null.nil?
  desc << " of primary #{@primary}"     unless @primary.nil?
  desc << " of scale #{@scale}"         unless @scale.nil?
  desc
end

#failure_messageObject



53
54
55
# File 'lib/shoulda/active_record/matchers/have_db_column_matcher.rb', line 53

def failure_message
  "Expected #{expectation} (#{@missing})"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
# File 'lib/shoulda/active_record/matchers/have_db_column_matcher.rb', line 42

def matches?(subject)
  @subject = subject
  column_exists? &&
    correct_column_type? &&
    correct_precision? &&
    correct_limit? &&
    correct_default? &&
    correct_null? &&
    correct_scale?
end

#negative_failure_messageObject



57
58
59
# File 'lib/shoulda/active_record/matchers/have_db_column_matcher.rb', line 57

def negative_failure_message
  "Did not expect #{expectation}"
end

#of_type(column_type) ⇒ Object



28
29
30
31
# File 'lib/shoulda/active_record/matchers/have_db_column_matcher.rb', line 28

def of_type(column_type)
  @column_type = column_type
  self
end

#with_options(opts = {}) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/shoulda/active_record/matchers/have_db_column_matcher.rb', line 33

def with_options(opts = {})
  @precision = opts[:precision]
  @limit     = opts[:limit]
  @default   = opts[:default]
  @null      = opts[:null]
  @scale     = opts[:scale]
  self
end