lib/generators/dry_crud/templates/test/custom_assertions.rb
# Asserts that the given active model record is not valid.
# If you provide a set of invalid attribute symbols, all of and only these
# attributes are expected to have errors. If no invalid attributes are
# specified, only the invalidity of the record is asserted.
Asserts that the given active model record is not valid.
If you provide a set of invalid attribute symbols, all of and only these
attributes are expected to have errors. If no invalid attributes are
specified, only the invalidity of the record is asserted.
Asserts that the given active model record is not valid . If you provide a set of invalid attribute symbols all of and only these attributes are expected to have errors . If no invalid attributes are specified only the invalidity of the record is asserted .
def assert_not_valid(record, *invalid_attrs)
    message = build_message("", "? expected to be invalid, but is valid.", record.to_s)
    assert_block(message) { !record.valid? }
    invalid_attrs.each do |a|
      message = build_message("", "Attribute <?> expected to be invalid, but is valid.", a.to_s)
      assert_block(message) { record.errors[a].present? }
    end
    if invalid_attrs.present?
      record.errors.each do |a, error|
        message = build_message("", "Attribute <?> not declared as invalid attribute, but has the following error: \n?.", a.to_s, error)
        assert_block(message) { invalid_attrs.include?(a) }
      end
    end
  end
def assert_not_valid ( record , * invalid_attrs ) message = build_message ( "" , "? expected to be invalid, but is valid." , record . to_s ) assert_block ( message ) { ! record . valid? } invalid_attrs . each do | a | message = build_message ( "" , "Attribute <?> expected to be invalid, but is valid." , a . to_s ) assert_block ( message ) { record . errors [ a ] . present? } end if invalid_attrs . present? record . errors . each do | a , error | message = build_message ( "" , "Attribute <?> not declared as invalid attribute, but has the following error: \n?." , a . to_s , error ) assert_block ( message ) { invalid_attrs . include? ( a ) } end end end
Asserts that the given active model record is not valid.
Asserts that the given active model record is not valid .
# assert that the given attributes have errors. # assert that no other than the invalid attributes have errors.
record
invalid_attrs