class Shoulda::Matchers::ActiveModel::Validator
@private
Attributes
Public Class Methods
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 8 def initialize(record, attribute, options = {}) @record = record @attribute = attribute @context = options[:context] @expects_strict = options[:expects_strict] @expected_message = options[:expected_message] @_validation_result = nil @captured_validation_exception = false @captured_range_error = false end
Public Instance Methods
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 36 def all_formatted_validation_error_messages format_validation_errors(all_validation_errors) end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 20 def call !messages_match? && !captured_range_error? end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 28 def captured_validation_exception? @captured_validation_exception end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 24 def has_messages? messages.any? end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 32 def type_of_message_matched? expects_strict? == captured_validation_exception? end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 40 def validation_exception_message validation_result[:validation_exception_message] end
Private Instance Methods
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 80 def all_validation_errors validation_result[:all_validation_errors] end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 76 def captured_range_error? !!@captured_range_error end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 50 def expects_strict? @expects_strict end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 68 def matched_messages if @expected_message messages.grep(@expected_message) else messages end end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 60 def messages if expects_strict? [validation_exception_message] else validation_error_messages end end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 54 def messages_match? has_messages? && type_of_message_matched? && matched_messages.compact.any? end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 92 def perform_validation if context record.valid?(context) else record.valid? end all_validation_errors = record.errors.dup validation_error_messages = record.errors[attribute] { all_validation_errors: all_validation_errors, validation_error_messages: validation_error_messages, validation_exception_message: nil, } rescue ::ActiveModel::StrictValidationFailed => e @captured_validation_exception = true { all_validation_errors: nil, validation_error_messages: [], validation_exception_message: e.message, } end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 84 def validation_error_messages validation_result[:validation_error_messages] end
Source
# File lib/shoulda/matchers/active_model/validator.rb, line 88 def validation_result @_validation_result ||= perform_validation end