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 13 # Relations
14 14 #
15 15 belongs_to :user
16   -
  16 +
17 17 #
18 18 # Validations
19 19 #
20 20 validates :user_id, presence: true
21 21 validates :email, presence: true, email: { strict_mode: true }, uniqueness: true
22 22 validate :unique_email, if: ->(email) { email.email_changed? }
23   -
  23 +
  24 + after_create :notify
24 25 before_validation :cleanup_email
25 26  
26 27 def cleanup_email
... ... @@ -30,4 +31,8 @@ class Email &lt; ActiveRecord::Base
30 31 def unique_email
31 32 self.errors.add(:email, 'has already been taken') if User.exists?(email: self.email)
32 33 end
33   -end
34 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   -class EmailObserver < BaseObserver
2   - def after_create(email)
3   - notification.new_email(email)
4   - end
5   -end