From 3c96d1f0e1fa1264250c0f93fbd0c26a0dbb1330 Mon Sep 17 00:00:00 2001 From: Alex Denisov <1101.debian@gmail.com> Date: Mon, 27 Aug 2012 00:32:03 +0300 Subject: [PATCH] Send notification on update UserProject relation (access changed) --- app/observers/users_project_observer.rb | 4 ++++ config/application.rb | 2 +- spec/observers/users_project_observer_spec.rb | 17 +++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/observers/users_project_observer.rb b/app/observers/users_project_observer.rb index cb33eb3f..763b2c87 100644 --- a/app/observers/users_project_observer.rb +++ b/app/observers/users_project_observer.rb @@ -2,4 +2,8 @@ class UsersProjectObserver < ActiveRecord::Observer def after_create(users_project) Notify.project_access_granted_email(users_project.id).deliver end + + def after_update(users_project) + Notify.project_access_granted_email(users_project.id).deliver + end end diff --git a/config/application.rb b/config/application.rb index ecd88b15..ad41f196 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,7 +23,7 @@ module Gitlab # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # Activate observers that should always be running. - config.active_record.observers = :mailer_observer, :activity_observer, :project_observer, :key_observer, :issue_observer, :user_observer, :system_hook_observer + config.active_record.observers = :mailer_observer, :activity_observer, :project_observer, :key_observer, :issue_observer, :user_observer, :system_hook_observer, :users_project_observer # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. diff --git a/spec/observers/users_project_observer_spec.rb b/spec/observers/users_project_observer_spec.rb index 37de9e51..3e392040 100644 --- a/spec/observers/users_project_observer_spec.rb +++ b/spec/observers/users_project_observer_spec.rb @@ -6,8 +6,8 @@ describe UsersProjectObserver do code: "Fuu", path: "Fuu" ) } let(:users_project) { Factory.create(:users_project, - project: project, - user: user )} + project: project, + user: user )} subject { UsersProjectObserver.instance } describe "#after_create" do @@ -24,4 +24,17 @@ describe UsersProjectObserver do subject.after_create(users_project) end end + + describe "#after_update" do + it "should called when UsersProject updated" do + subject.should_receive(:after_update) + 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) + end + end end