Module: EvelpidonTestHelpers::ActiveModel::AttributeValidations::Assertions

Included in:
ActiveSupport::TestCase
Defined in:
lib/evelpidon_test_helpers/active_model/attribute_validations.rb

Instance Method Summary collapse

Instance Method Details

#assert_invalid_attribute(object, attribute, message = "") ⇒ Object

Asserts that the given attribute on the given ActiveModel contains at least one error.



16
17
18
19
20
21
22
# File 'lib/evelpidon_test_helpers/active_model/attribute_validations.rb', line 16

def assert_invalid_attribute(object, attribute, message = "")
  object.valid?
  errors_on_attribute = object.errors[attribute].length
  error_messages = object.errors[attribute].join(',')
  message << "\nExpected at least one error on #{attribute} but got #{errors_on_attribute} :\n#{error_messages}"
  assert errors_on_attribute > 0, message
end

#assert_valid_attribute(object, attribute, message = "") ⇒ Object

Asserts that the given attribute on the given ActiveModel contains no errors. If not, the error message is the joint string of the errors on this attribute.



7
8
9
10
11
12
13
# File 'lib/evelpidon_test_helpers/active_model/attribute_validations.rb', line 7

def assert_valid_attribute(object, attribute, message = "")
  object.valid?
  errors_on_attribute = object.errors[attribute].length
  error_messages = object.errors[attribute].join(',')
  message << "\nExpected zero errors on #{attribute} but got #{errors_on_attribute} :\n#{error_messages}"
  assert_equal 0, errors_on_attribute, message
end