Class: RiotRails::ActiveRecord::AllowsValuesForMacro
- Inherits:
-
ValidationAssertionMacro
- Object
- Riot::AssertionMacro
- ValidationAssertionMacro
- RiotRails::ActiveRecord::AllowsValuesForMacro
- Defined in:
- lib/riot/active_record/validation_macros.rb
Overview
An ActiveRecord assertion that expects to pass with a given value or set of values for a given attribute.
rails_context User do
asserts_topic.allows_values_for :email, "a@b.cd"
asserts_topic.allows_values_for :email, "a@b.cd", "e@f.gh"
end
Instance Method Summary (collapse)
Instance Method Details
- (Object) evaluate(actual, attribute, *values)
31 32 33 34 35 36 37 |
# File 'lib/riot/active_record/validation_macros.rb', line 31 def evaluate(actual, attribute, *values) bad_values = [] values.each do |value| bad_values << value if errors_from_writing_value?(actual, attribute, value) end bad_values.empty? ? pass : fail((attribute).to_allow_values(bad_values)) end |