There will be many validations required for various string formats, and as a result, there will be a lot of duplicate code.
Solution
Add a custom StringFormatValidator along with a custom assertion assert_validates_format_rules to use in model tests with those validations.
How it's Used
In use, you might have a test for a model Foo and want to check that certain validations exist on it's :bar property.
class FooTest < ActiveSupport::TestCase
test 'bar attribute validates with the expected rules' do
expected_rules = [:starts_with_non_whitespace, :has_only_printable_characters]
assert_validates_format_rules expected_rules, Foo, :bar
end
end
Problem
There will be many validations required for various string formats, and as a result, there will be a lot of duplicate code.
Solution
Add a custom
StringFormatValidator
along with a custom assertionassert_validates_format_rules
to use in model tests with those validations.How it's Used
In use, you might have a test for a model
Foo
and want to check that certain validations exist on it's:bar
property.