Class: Shoulda::Matchers::ActiveModel::RequireAValidIdentityMatcher
- Inherits:
-
ValidationMatcher
- Object
- ValidationMatcher
- Shoulda::Matchers::ActiveModel::RequireAValidIdentityMatcher
- Defined in:
- lib/shoulda/matchers/active_model/require_a_valid_identity_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(identity, identity_type, type) ⇒ RequireAValidIdentityMatcher
constructor
A new instance of RequireAValidIdentityMatcher.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(identity, identity_type, type) ⇒ RequireAValidIdentityMatcher
Returns a new instance of RequireAValidIdentityMatcher.
13 14 15 16 17 |
# File 'lib/shoulda/matchers/active_model/require_a_valid_identity_matcher.rb', line 13 def initialize(identity, identity_type, type) super(identity) @identity_type = identity_type @type = type end |
Instance Method Details
#description ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/shoulda/matchers/active_model/require_a_valid_identity_matcher.rb', line 19 def description case @type when :person then 'require a valid person identity' when :legal then 'require a valid legal identity' else 'require a valid identity' end end |
#failure_message ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/shoulda/matchers/active_model/require_a_valid_identity_matcher.rb', line 27 def case @type when :person then 'does not require a valid person identity' when :legal then 'does not require a valid legal identity' else 'expected to require a valid identity' end end |
#matches?(subject) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/shoulda/matchers/active_model/require_a_valid_identity_matcher.rb', line 35 def matches?(subject) super(subject) result = [] allowed_values.each do |identity_type, values| subject.send("#{@identity_type}=", identity_type) values.each do |value| result << allows_value_of(value) end end disallowed_values.each do |identity_type, values| subject.send("#{@identity_type}=", identity_type) values.each do |value| result << disallows_value_of(value) end end result.inject(:&) end |