class SchemaExpectations::RSpecMatchers::ValidateSchemaNullableMatcher
Public Instance Methods
description()
click to toggle source
# File lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb, line 71 def description 'validate NOT NULL columns are present' end
failure_message()
click to toggle source
# 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_negated()
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
column_name_to_attribute(column_name)
click to toggle source
# File lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb, line 93 def column_name_to_attribute(column_name) @validation_reflector.attributes.detect do |attribute| @column_reflector.for_attributes(attribute).column_names. include? column_name end end
filter_column_names(column_names)
click to toggle source
# File lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb, line 105 def filter_column_names(column_names) column_names &= @only if @only column_names -= @except if @except column_names end
not_null_column_names()
click to toggle source
# File lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb, line 100 def not_null_column_names @column_reflector.not_null. without_present_default.column_names end
present_attributes()
click to toggle source
# File lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb, line 83 def present_attributes @validation_reflector.presence. unconditional.disallow_nil.attributes end
present_column_names()
click to toggle source
# File lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb, line 88 def present_column_names @column_reflector.for_attributes(*present_attributes). without_present_default.column_names end
setup(model)
click to toggle source
Calls superclass method
SchemaExpectations::RSpecMatchers::Base#setup
# File lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb, line 77 def setup(model) super @not_null_column_names = filter_column_names(not_null_column_names).sort @present_column_names = filter_column_names(present_column_names).sort end
validator_allow_nil_conditions_for_column_name(column_name)
click to toggle source
# File lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb, line 111 def validator_allow_nil_conditions_for_column_name(column_name) @validation_reflector.allow_nil_conditions_for_attribute column_name_to_attribute column_name end
validator_conditions_for_column_name(column_name)
click to toggle source
# File lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb, line 115 def validator_conditions_for_column_name(column_name) @validation_reflector.conditions_for_attribute column_name_to_attribute column_name end