Class: Warp::ModelMatchers::ValidationMatcher
- Inherits:
-
Matcher
- Object
- Warp::Matcher
- Matcher
- Warp::ModelMatchers::ValidationMatcher
- Defined in:
- lib/warp/model_matchers/validation_matcher.rb
Constant Summary collapse
- VALIDATORS =
{ acceptance: [ActiveModel::Validations::AcceptanceValidator], confirmation: [ActiveModel::Validations::ConfirmationValidator], exclusion: [ActiveModel::Validations::ExclusionValidator], format: [ActiveModel::Validations::FormatValidator], inclusion: [ActiveModel::Validations::InclusionValidator], length: [ActiveModel::Validations::LengthValidator], numericality: [ActiveModel::Validations::NumericalityValidator], presence: [ActiveModel::Validations::PresenceValidator] }
Instance Attribute Summary collapse
-
#attr_name ⇒ Object
readonly
Returns the value of attribute attr_name.
-
#display_options ⇒ Object
readonly
Returns the value of attribute display_options.
-
#validator_classes ⇒ Object
readonly
Returns the value of attribute validator_classes.
-
#validator_options ⇒ Object
readonly
Returns the value of attribute validator_options.
Attributes inherited from Matcher
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(attr_name, validator_classes, validator_options, display_options) ⇒ ValidationMatcher
constructor
A new instance of ValidationMatcher.
- #matches?(model_or_instance) ⇒ Boolean
Constructor Details
#initialize(attr_name, validator_classes, validator_options, display_options) ⇒ ValidationMatcher
Returns a new instance of ValidationMatcher.
38 39 40 41 42 43 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 38 def initialize(attr_name, validator_classes, , ) @attr_name = attr_name @validator_classes = validator_classes @validator_options = @display_options = end |
Instance Attribute Details
#attr_name ⇒ Object (readonly)
Returns the value of attribute attr_name.
36 37 38 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 36 def attr_name @attr_name end |
#display_options ⇒ Object (readonly)
Returns the value of attribute display_options.
36 37 38 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 36 def @display_options end |
#validator_classes ⇒ Object (readonly)
Returns the value of attribute validator_classes.
36 37 38 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 36 def validator_classes @validator_classes end |
#validator_options ⇒ Object (readonly)
Returns the value of attribute validator_options.
36 37 38 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 36 def @validator_options end |
Instance Method Details
#description ⇒ Object
65 66 67 68 69 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 65 def description str = "have validator #{validator_classes.map(&:name).join(", or ")} on :#{attr_name}" str << " with options #{description_of()}" if .present? str end |
#failure_message ⇒ Object
57 58 59 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 57 def "expected #{model_name} to #{description}" end |
#failure_message_when_negated ⇒ Object
61 62 63 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 61 def "expected #{model_name} to not #{description}" end |
#matches?(model_or_instance) ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 45 def matches?(model_or_instance) @model_or_instance = model_or_instance validators.any? do |validator| if validator_classes.any? {|validator_class| values_match?(validator_class, validator.class) } .nil? || values_match?(, validator.) else false end end end |