Class: RiotRails::ActiveRecord::DoesNotAllowValuesForMacro

Inherits:
ValidationAssertionMacro show all
Defined in:
lib/riot/active_record/validation_macros.rb

Overview

An ActiveRecord assertion that expects to fail with a given value or set of values for a given attribute.

rails_context User do
  asserts_topic.does_not_allow_values_for :email, "a"
  asserts_topic.does_not_allow_values_for :email, "a@b", "e f@g.h"
end

Instance Method Summary collapse

Instance Method Details

#evaluate(actual, attribute, *values) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/riot/active_record/validation_macros.rb', line 49

def evaluate(actual, attribute, *values)
  good_values = []
  values.each do |value|
    good_values << value unless errors_from_writing_value?(actual, attribute, value)
  end
  good_values.empty? ? pass : fail(expected_message(attribute).not_to_allow_values(good_values))
end