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