Commit 1f1c8094 authored by Alex Denisov's avatar Alex Denisov

After commit instead of after_update

parent c7cfe3d8
class UsersProjectObserver < ActiveRecord::Observer class UsersProjectObserver < ActiveRecord::Observer
def after_create(users_project) #def after_create(users_project)
Notify.project_access_granted_email(users_project.id).deliver #Notify.project_access_granted_email(users_project.id).deliver
end #end
#def after_update(users_project)
#Notify.project_access_granted_email(users_project.id).deliver
#end
def after_update(users_project) def after_commit(users_project)
Notify.project_access_granted_email(users_project.id).deliver Notify.project_access_granted_email(users_project.id).deliver
end end
end end
...@@ -12,7 +12,7 @@ describe UsersProjectObserver do ...@@ -12,7 +12,7 @@ describe UsersProjectObserver do
describe "#after_create" do describe "#after_create" do
it "should called when UsersProject created" 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 UsersProject.observers.enable :users_project_observer do
Factory.create(:users_project, Factory.create(:users_project,
project: project, project: project,
...@@ -21,20 +21,20 @@ describe UsersProjectObserver do ...@@ -21,20 +21,20 @@ describe UsersProjectObserver do
end end
it "should send email to user" do it "should send email to user" do
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true)) 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
end end
describe "#after_update" do describe "#after_update" do
it "should called when UsersProject updated" 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 UsersProject.observers.enable :users_project_observer do
users_project.update_attribute(:project_access, 40) users_project.update_attribute(:project_access, 40)
end end
end end
it "should send email to user" do it "should send email to user" do
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true)) 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 end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment