Commit 599344583bcf57eff46b36d68e6536188d41c906

Authored by Dmitriy Zaporozhets
1 parent 3faa14e7

Remove EmailsObserver

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/models/email.rb
@@ -13,14 +13,15 @@ class Email &lt; ActiveRecord::Base @@ -13,14 +13,15 @@ class Email &lt; ActiveRecord::Base
13 # Relations 13 # Relations
14 # 14 #
15 belongs_to :user 15 belongs_to :user
16 - 16 +
17 # 17 #
18 # Validations 18 # Validations
19 # 19 #
20 validates :user_id, presence: true 20 validates :user_id, presence: true
21 validates :email, presence: true, email: { strict_mode: true }, uniqueness: true 21 validates :email, presence: true, email: { strict_mode: true }, uniqueness: true
22 validate :unique_email, if: ->(email) { email.email_changed? } 22 validate :unique_email, if: ->(email) { email.email_changed? }
23 - 23 +
  24 + after_create :notify
24 before_validation :cleanup_email 25 before_validation :cleanup_email
25 26
26 def cleanup_email 27 def cleanup_email
@@ -30,4 +31,8 @@ class Email &lt; ActiveRecord::Base @@ -30,4 +31,8 @@ class Email &lt; ActiveRecord::Base
30 def unique_email 31 def unique_email
31 self.errors.add(:email, 'has already been taken') if User.exists?(email: self.email) 32 self.errors.add(:email, 'has already been taken') if User.exists?(email: self.email)
32 end 33 end
33 -end  
34 \ No newline at end of file 34 \ No newline at end of file
  35 +
  36 + def notify
  37 + NotificationService.new.new_email(self)
  38 + end
  39 +end
app/observers/email_observer.rb
@@ -1,5 +0,0 @@ @@ -1,5 +0,0 @@
1 -class EmailObserver < BaseObserver  
2 - def after_create(email)  
3 - notification.new_email(email)  
4 - end  
5 -end