Class: Katalyst::GoogleApis::Matchers::ValidateRecaptchaForMatcher
- Inherits:
-
Shoulda::Matchers::ActiveModel::ValidationMatcher
- Object
- Shoulda::Matchers::ActiveModel::ValidationMatcher
- Katalyst::GoogleApis::Matchers::ValidateRecaptchaForMatcher
- Defined in:
- lib/katalyst/google_apis/matchers/validate_recaptcha_for_matcher.rb
Instance Method Summary collapse
- #example_response(subject) ⇒ Object
- #example_value ⇒ Object
-
#initialize(attribute, expected:) ⇒ ValidateRecaptchaForMatcher
constructor
A new instance of ValidateRecaptchaForMatcher.
- #matches?(subject) ⇒ Boolean
- #simple_description ⇒ Object
Constructor Details
#initialize(attribute, expected:) ⇒ ValidateRecaptchaForMatcher
Returns a new instance of ValidateRecaptchaForMatcher.
19 20 21 22 23 |
# File 'lib/katalyst/google_apis/matchers/validate_recaptcha_for_matcher.rb', line 19 def initialize(attribute, expected:) super(attribute) @expected_message = expected end |
Instance Method Details
#example_response(subject) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/katalyst/google_apis/matchers/validate_recaptcha_for_matcher.rb', line 47 def example_response(subject) case @expected_message when :recaptcha_invalid { valid?: false } when :recaptcha_action_mismatch { valid?: true, action: "mismatch" } when :recaptcha_suspicious { valid?: true, action: subject.class.model_name.param_key, score: 0.1 } else { valid?: true, action: subject.class.model_name.param_key, score: 0.9 } end end |
#example_value ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/katalyst/google_apis/matchers/validate_recaptcha_for_matcher.rb', line 39 def example_value { recaptcha_invalid: "<invalid-token>", recaptcha_action_mismatch: "<action-mismatch-token>", recaptcha_suspicious: "<suspicious-token>", }[@expected_message] end |
#matches?(subject) ⇒ Boolean
25 26 27 28 29 30 31 32 33 |
# File 'lib/katalyst/google_apis/matchers/validate_recaptcha_for_matcher.rb', line 25 def matches?(subject) Katalyst::GoogleApis.config.recaptcha.test_mode = false super disallows_value_of(example_value, @expected_message) ensure Katalyst::GoogleApis.config.recaptcha.test_mode = true end |
#simple_description ⇒ Object
35 36 37 |
# File 'lib/katalyst/google_apis/matchers/validate_recaptcha_for_matcher.rb', line 35 def simple_description "validate that :#{@attribute} includes reCAPTCHA validation" end |