all model tests now pass
This commit is contained in:
parent
9ac685fd15
commit
2fe142ed86
@ -1,2 +1,5 @@
|
||||
class Credential < ApplicationRecord
|
||||
validates :email, presence: true
|
||||
validates :email, uniqueness: true
|
||||
validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i , message: "email must be valid"}
|
||||
end
|
||||
|
||||
@ -2,6 +2,9 @@ class Virtual < ApplicationRecord
|
||||
validate :domain_name_exists
|
||||
validates :email, presence: true
|
||||
validates :destination, presence: true
|
||||
validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i , message: "email must be valid"}
|
||||
validates :destination, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i , message: "destination must be valid"}
|
||||
validates :destination, uniqueness: {scope: :email, message: "a redirection pair must be unique"}
|
||||
|
||||
def domain_name_exists
|
||||
if email.present?
|
||||
|
||||
@ -1,7 +1,20 @@
|
||||
require "test_helper"
|
||||
|
||||
class CredentialTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
test "email must be present" do
|
||||
@c = Credential.new
|
||||
assert !@c.save
|
||||
end
|
||||
|
||||
test "email must be valid" do
|
||||
@c = Credential.new
|
||||
@c.email = "not on your nelly"
|
||||
assert !@c.save
|
||||
end
|
||||
|
||||
test "email must be unique" do
|
||||
@c = Credential.new
|
||||
@c.email = "bob@example.net"
|
||||
assert !@c.save
|
||||
end
|
||||
end
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
require "test_helper"
|
||||
|
||||
class VirtualTest < ActiveSupport::TestCase
|
||||
test "the email cant be blank" do
|
||||
@v = Virtual.new
|
||||
@v.destination = "davesmith@example.com"
|
||||
assert !@v.save
|
||||
end
|
||||
|
||||
test "the destination email cant be blank" do
|
||||
@v = Virtual.new
|
||||
@v.email = "davesmith@example.com"
|
||||
assert !@v.save
|
||||
end
|
||||
|
||||
test "the domain name of the email must be on this server" do
|
||||
@v = Virtual.new
|
||||
@v.email = "davesmith@notonthisserver.com"
|
||||
@v.destination = "bob@example.net"
|
||||
assert !@v.save
|
||||
end
|
||||
|
||||
test "the email must be a valid email" do
|
||||
@v = Virtual.new
|
||||
@v.email = "something not quiet right"
|
||||
assert !@v.save
|
||||
end
|
||||
|
||||
test "the destination must be a valid email" do
|
||||
@v = Virtual.new
|
||||
@v.destination = "this will never work"
|
||||
assert !@v.save
|
||||
end
|
||||
|
||||
test "the email plus destination must be unique" do
|
||||
@v = Virtual.new
|
||||
@v.email = "abuse@example.net"
|
||||
@v.destination ="bob@example.net"
|
||||
assert !@v.save
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user