Class: SchemaExpectations::RSpecMatchers::ValidateSchemaNullableMatcher

Inherits:
Base
  • Object
show all
Defined in:
lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb

Instance Method Summary collapse

Methods inherited from Base

#except, #only

Instance Method Details

#descriptionObject



71
72
73
# File 'lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb', line 71

def description
  'validate NOT NULL columns are present'
end

#failure_messageObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb', line 47

def failure_message
  errors = []

  (@present_column_names - @not_null_column_names).each do |column_name|
    errors << "#{@model.name} #{column_name} has unconditional presence validation but is missing NOT NULL"
  end

  (@not_null_column_names - @present_column_names).each do |column_name|
    conditions = validator_allow_nil_conditions_for_column_name(column_name) ||
      validator_conditions_for_column_name(column_name)
    if conditions
      errors << "#{@model.name} #{column_name} is NOT NULL but its presence validator was conditional: #{conditions.inspect}"
    else
      errors << "#{@model.name} #{column_name} is NOT NULL but has no presence validation"
    end
  end

  errors.join(', ')
end

#failure_message_when_negatedObject



67
68
69
# File 'lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb', line 67

def failure_message_when_negated
  "#{@model.name} should not match NOT NULL with its presence validation but does"
end

#matches?(model) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb', line 42

def matches?(model)
  setup(model)
  @not_null_column_names == @present_column_names
end