From 9ac685fd15d1284c8bb2d2759486fac04230f636 Mon Sep 17 00:00:00 2001 From: Jez Caudle Date: Mon, 15 May 2023 14:26:32 +0100 Subject: [PATCH] Tests not working. Not sure why. --- app/models/virtual.rb | 12 ++++++++++++ test/models/virtual_test.rb | 35 ----------------------------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/app/models/virtual.rb b/app/models/virtual.rb index bdd9882..757f926 100644 --- a/app/models/virtual.rb +++ b/app/models/virtual.rb @@ -1,4 +1,16 @@ class Virtual < ApplicationRecord + validate :domain_name_exists validates :email, presence: true validates :destination, presence: true + + def domain_name_exists + if email.present? + if !email.index("@").nil? + split_email = email.split("@") + if !Domain.exists?(domain: split_email[1]) + errors.add(:email, "domain must be looked after by this server") + end + end + end + end end diff --git a/test/models/virtual_test.rb b/test/models/virtual_test.rb index 3a94da8..e69de29 100644 --- a/test/models/virtual_test.rb +++ b/test/models/virtual_test.rb @@ -1,35 +0,0 @@ -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 - # flunk() - end - - test "the destination must be a valid email" do - # flunk() - end - - test "the email plus destination must be unique" do - # flunk() - - end -end