Skip to content

Commit

Permalink
Merge pull request #39 from substancelab/verify_rules_are_in_addition_to
Browse files Browse the repository at this point in the history
Clarify how rules work
  • Loading branch information
koppen authored Dec 3, 2024
2 parents 6965446 + 2cfc794 commit b216ddb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions test/test_active_model_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b216ddb

Please sign in to comment.