4bbd93ded1
Adding the .ruby-verison file triggered previously un-run cops, specifically: This cop is designed to help upgrade to Ruby 3.0. It will add the comment `# frozen_string_literal: true` to the top of files to enable frozen string literals. Frozen string literals will be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+. More info on rubocop [Automatic-Corrections](https://github.com/bbatsov/rubocop/wiki/Automatic-Corrections)
37 lines
1000 B
Ruby
37 lines
1000 B
Ruby
# frozen_string_literal: true
|
|
require 'test_helper'
|
|
|
|
class EmailFormatValidatorTest < ActiveSupport::TestCase
|
|
test "tld length" do
|
|
obj = EmailValidatable.new
|
|
|
|
obj.email = "me@no.yes.x"
|
|
refute obj.valid?, 'allowed single length tld'
|
|
|
|
obj.email = "me@no.yes.co"
|
|
assert obj.valid?, 'did not allow tld length 2'
|
|
|
|
obj.email = "me@no.yes.com"
|
|
assert obj.valid?, 'did not allow tld length 3'
|
|
|
|
obj.email = "me@no.yes.commets"
|
|
assert obj.valid?, 'did not allow tld length > 3'
|
|
end
|
|
|
|
test "can handle comma seperated addresses" do
|
|
obj = EmailValidatable.new
|
|
obj.email = "me@no.yes, me@yes.no"
|
|
|
|
assert obj.valid?, 'did not allow multiple address [comma seperated]'
|
|
end
|
|
|
|
test "provides proper error message" do
|
|
obj = EmailValidatable.new
|
|
obj.email = "this is a bad email address"
|
|
obj.valid?
|
|
|
|
refute obj.errors.messages.empty?, 'needs an error message'
|
|
assert_match(/not formatted properly/, obj.errors.messages[:email].join)
|
|
end
|
|
end
|