Class: SchemaExpectations::RSpecMatchers::ValidateSchemaUniquenessMatcher
- Inherits:
-
Base
- Object
- Base
- SchemaExpectations::RSpecMatchers::ValidateSchemaUniquenessMatcher
- Defined in:
- lib/schema_expectations/rspec_matchers/validate_schema_uniqueness.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #matches?(model) ⇒ Boolean
Methods inherited from Base
Instance Method Details
#description ⇒ Object
78 79 80 |
# File 'lib/schema_expectations/rspec_matchers/validate_schema_uniqueness.rb', line 78 def description 'validate unique indexes have uniqueness validation' end |
#failure_message ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/schema_expectations/rspec_matchers/validate_schema_uniqueness.rb', line 54 def errors = [] (@validator_unique_scopes - @schema_unique_scopes).each do |scope| errors << "#{@model.name} scope #{scope.inspect} has unconditional uniqueness validation but is missing a unique database index" end (@schema_unique_scopes - @validator_unique_scopes - absent_scopes).each do |scope| conditions = validator_conditions_for_scope(scope) || validator_allow_empty_conditions_for_scope(scope) if conditions errors << "#{@model.name} scope #{scope.inspect} has a unique index but its uniqueness validator was conditional: #{conditions.inspect}" else errors << "#{@model.name} scope #{scope.inspect} has a unique index but no uniqueness validation" end end errors.join(', ') end |
#failure_message_when_negated ⇒ Object
74 75 76 |
# File 'lib/schema_expectations/rspec_matchers/validate_schema_uniqueness.rb', line 74 def "#{@model.name} should not match unique indexes with its uniqueness validation but does" end |
#matches?(model) ⇒ Boolean
48 49 50 51 52 |
# File 'lib/schema_expectations/rspec_matchers/validate_schema_uniqueness.rb', line 48 def matches?(model) setup(model) (@validator_unique_scopes - @schema_unique_scopes).empty? && (@schema_unique_scopes - @validator_unique_scopes - absent_scopes).empty? end |