diff --git a/README.md b/README.md index eb883da..055a0ae 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,17 @@ Or you could go beyound simple matching and validate that all email adresses bel :with => proc { |address| address.end_with?("@substancelab.com") } } +You can even match against multiple rules, in which case all rules must pass: + + validates :email, :email_address => { + :with => [ + proc { |address| address.match(/.+@.+\..+/) }, + proc { |address| !address.end_with?("@outlook.com") }, + ] + } + +Do note that supplying your own rules means that the default email address validation isn't run - you're on your own, basically. + ### Verify domain (still to be done - pull request, anybody?) This also checks that the domain actually has an MX record. Note this might take a while because of DNS lookups. diff --git a/test/test_active_model_integration.rb b/test/test_active_model_integration.rb index 9825637..4a1710c 100644 --- a/test/test_active_model_integration.rb +++ b/test/test_active_model_integration.rb @@ -69,6 +69,16 @@ def test_validates_with_multiple_procs reject("bob", subject) end + def test_rules_overwrite_default_rule + subject = build_model_with_validations( + email: {email_address: { + with: proc { |address| true } + }} + ) + + accept("anything", subject) + end + private def accept(email_address, subject)