class Shoulda::Matchers::ActiveModel::ValidationMessageFinder
@private
Public Class Methods
Source
# File lib/shoulda/matchers/active_model/validation_message_finder.rb, line 8 def initialize(instance, attribute, context = nil) @instance = instance @attribute = attribute @context = context end
Public Instance Methods
Source
# File lib/shoulda/matchers/active_model/validation_message_finder.rb, line 14 def allow_description(allowed_values) "allow #{@attribute} to be set to #{allowed_values}" end
Source
# File lib/shoulda/matchers/active_model/validation_message_finder.rb, line 18 def expected_message_from(attribute_message) attribute_message end
Source
# File lib/shoulda/matchers/active_model/validation_message_finder.rb, line 22 def has_messages? errors.present? end
Source
# File lib/shoulda/matchers/active_model/validation_message_finder.rb, line 38 def messages Array(messages_for_attribute) end
Source
# File lib/shoulda/matchers/active_model/validation_message_finder.rb, line 30 def messages_description if errors.empty? ' no errors' else " errors:\n#{pretty_error_messages(validated_instance)}" end end
Source
# File lib/shoulda/matchers/active_model/validation_message_finder.rb, line 26 def source_description 'errors' end
Private Instance Methods
Source
# File lib/shoulda/matchers/active_model/validation_message_finder.rb, line 48 def errors validated_instance.errors end
Source
# File lib/shoulda/matchers/active_model/validation_message_finder.rb, line 44 def messages_for_attribute errors[@attribute] end
Source
# File lib/shoulda/matchers/active_model/validation_message_finder.rb, line 56 def validate_instance @instance.valid?(*@context) @instance end
Source
# File lib/shoulda/matchers/active_model/validation_message_finder.rb, line 52 def validated_instance @_validated_instance ||= validate_instance end