Commit 599344583bcf57eff46b36d68e6536188d41c906
1 parent
3faa14e7
Exists in
spb-stable
and in
3 other branches
Remove EmailsObserver
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
2 changed files
with
8 additions
and
8 deletions
Show diff stats
app/models/email.rb
@@ -13,14 +13,15 @@ class Email < ActiveRecord::Base | @@ -13,14 +13,15 @@ class Email < 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 < ActiveRecord::Base | @@ -30,4 +31,8 @@ class Email < 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 |