Pārlūkot izejas kodu

Added email validation

Andrew Kane 7 gadi atpakaļ
vecāks
revīzija
211e1ee155
1 mainītis faili ar 7 papildinājumiem un 0 dzēšanām
  1. 7 0
      app/models/blazer/check.rb

+ 7 - 0
app/models/blazer/check.rb

@@ -4,6 +4,7 @@ module Blazer
     belongs_to :query
 
     validates :query_id, presence: true
+    validate :validate_emails
 
     before_validation :set_state
     before_validation :fix_emails
@@ -74,5 +75,11 @@ module Blazer
         # but we know what they mean, so let's fix it
         self.emails = emails.gsub(";", ",") if emails.present?
       end
+
+      def validate_emails
+        unless split_emails.all? { |e| e =~ /\A.+@.+\..+\z/ }
+          errors.add(:base, "Invalid emails")
+        end
+      end
   end
 end