Class: Shoulda::Matchers::ActiveRecord::AssociationMatchers::RequiredMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveRecord::AssociationMatchers::RequiredMatcher
- Defined in:
- lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb
Instance Attribute Summary collapse
-
#missing_option ⇒ Object
readonly
Returns the value of attribute missing_option.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(attribute_name, required) ⇒ RequiredMatcher
constructor
A new instance of RequiredMatcher.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(attribute_name, required) ⇒ RequiredMatcher
Returns a new instance of RequiredMatcher.
9 10 11 12 13 14 15 16 |
# File 'lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb', line 9 def initialize(attribute_name, required) @attribute_name = attribute_name @required = required @submatcher = ActiveModel::DisallowValueMatcher.new(nil). for(attribute_name). () @missing_option = '' end |
Instance Attribute Details
#missing_option ⇒ Object (readonly)
Returns the value of attribute missing_option.
7 8 9 |
# File 'lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb', line 7 def missing_option @missing_option end |
Instance Method Details
#description ⇒ Object
18 19 20 |
# File 'lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb', line 18 def description "required: #{required}" end |
#matches?(subject) ⇒ Boolean
22 23 24 25 26 27 28 29 30 |
# File 'lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb', line 22 def matches?(subject) if submatcher_passes?(subject) true else @missing_option = build_missing_option false end end |