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
Methods inherited from Warp::Matcher
#description_of, #failure_message_for_should, #failure_message_for_should_not, #values_match?
Constructor Details
#initialize(attr_name, validator_classes, validator_options, display_options) ⇒ ValidationMatcher
Returns a new instance of ValidationMatcher.
36 37 38 39 40 41 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 36 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.
34 35 36 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 34 def attr_name @attr_name end |
#display_options ⇒ Object (readonly)
Returns the value of attribute display_options.
34 35 36 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 34 def @display_options end |
#validator_classes ⇒ Object (readonly)
Returns the value of attribute validator_classes.
34 35 36 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 34 def validator_classes @validator_classes end |
#validator_options ⇒ Object (readonly)
Returns the value of attribute validator_options.
34 35 36 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 34 def @validator_options end |
Instance Method Details
#description ⇒ Object
63 64 65 66 67 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 63 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
55 56 57 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 55 def "expected #{model_name} to #{description}" end |
#failure_message_when_negated ⇒ Object
59 60 61 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 59 def "expected #{model_name} to not #{description}" end |
#matches?(model_or_instance) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/warp/model_matchers/validation_matcher.rb', line 43 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 |