From 1f1c8094fe342feb851c681dcde25459b82faff0 Mon Sep 17 00:00:00 2001 From: Alex Denisov <1101.debian@gmail.com> Date: Mon, 3 Sep 2012 20:48:38 +0300 Subject: [PATCH] After commit instead of after_update --- app/observers/users_project_observer.rb | 12 ++++++++---- spec/observers/users_project_observer_spec.rb | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/observers/users_project_observer.rb b/app/observers/users_project_observer.rb index 763b2c87f63..e2fa1676661 100644 --- a/app/observers/users_project_observer.rb +++ b/app/observers/users_project_observer.rb @@ -1,9 +1,13 @@ class UsersProjectObserver < ActiveRecord::Observer - def after_create(users_project) - Notify.project_access_granted_email(users_project.id).deliver - end + #def after_create(users_project) + #Notify.project_access_granted_email(users_project.id).deliver + #end - def after_update(users_project) + #def after_update(users_project) + #Notify.project_access_granted_email(users_project.id).deliver + #end + + def after_commit(users_project) Notify.project_access_granted_email(users_project.id).deliver end end diff --git a/spec/observers/users_project_observer_spec.rb b/spec/observers/users_project_observer_spec.rb index 3e3920407cb..68fbcc4f8c6 100644 --- a/spec/observers/users_project_observer_spec.rb +++ b/spec/observers/users_project_observer_spec.rb @@ -12,7 +12,7 @@ describe UsersProjectObserver do describe "#after_create" do it "should called when UsersProject created" do - subject.should_receive(:after_create) + subject.should_receive(:after_commit) UsersProject.observers.enable :users_project_observer do Factory.create(:users_project, project: project, @@ -21,20 +21,20 @@ describe UsersProjectObserver do end it "should send email to user" do Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true)) - subject.after_create(users_project) + subject.after_commit(users_project) end end describe "#after_update" do it "should called when UsersProject updated" do - subject.should_receive(:after_update) + subject.should_receive(:after_commit) UsersProject.observers.enable :users_project_observer do users_project.update_attribute(:project_access, 40) end end it "should send email to user" do Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true)) - subject.after_update(users_project) + subject.after_commit(users_project) end end end