class Shoulda::Matchers::ActiveModel::AllowValueMatcher
:nodoc:
def allowed_values
def allowed_values if @values_to_match.length > 1 "any of [#{@values_to_match.map(&:inspect).join(', ')}]" else @values_to_match.first.inspect end end
def default_attribute_message
def default_attribute_message default_error_message( @options[:expected_message], :model_name => model_name, :attribute => @attribute ) end
def default_expected_message
def default_expected_message message_finder.expected_message_from(default_attribute_message) end
def description
def description message_finder.allow_description(allowed_values) end
def error_description
def error_description message_finder.messages_description end
def error_source
def error_source message_finder.source_description end
def errors_for_attribute
def errors_for_attribute message_finder.messages end
def errors_for_attribute_match?
def errors_for_attribute_match? if expected_message @matched_error = errors_match_regexp? || errors_match_string? else errors_for_attribute.compact.any? end end
def errors_match?
def errors_match? has_messages? && errors_for_attribute_match? end
def errors_match_regexp?
def errors_match_regexp? if Regexp === expected_message errors_for_attribute.detect { |e| e =~ expected_message } end end
def errors_match_string?
def errors_match_string? if errors_for_attribute.include?(expected_message) expected_message end end
def expectation
def expectation includes_expected_message = expected_message ? "to include #{expected_message.inspect}" : '' [error_source, includes_expected_message, "when #{@attribute} is set to #{@value.inspect}"].join(' ') end
def expected_message
def expected_message if @options.key?(:expected_message) if Symbol === @options[:expected_message] default_expected_message else @options[:expected_message] end end end
def failure_message
def failure_message "Did not expect #{expectation}, got error: #{@matched_error}" end
def for(attribute)
def for(attribute) @attribute = attribute self end
def has_messages?
def has_messages? message_finder.has_messages? end
def initialize(*values)
def initialize(*values) @values_to_match = values @message_finder_factory = ValidationMessageFinder @options = {} end
def matches?(instance)
def matches?(instance) @instance = instance @values_to_match.none? do |value| @value = value @instance.send("#{@attribute}=", @value) errors_match? end end
def message_finder
def message_finder @message_finder_factory.new(@instance, @attribute) end
def model_name
def model_name @instance.class.to_s.underscore end
def negative_failure_message
def negative_failure_message "Expected #{expectation}, got #{error_description}" end
def strict
def strict @message_finder_factory = ExceptionMessageFinder self end
def with_message(message)
def with_message(message) @options[:expected_message] = message self end