Commit 3c96d1f0e1fa1264250c0f93fbd0c26a0dbb1330
1 parent
aaeb3741
Exists in
master
and in
4 other branches
Send notification on update UserProject relation (access changed)
Showing
3 changed files
with
20 additions
and
3 deletions
Show diff stats
app/observers/users_project_observer.rb
| @@ -2,4 +2,8 @@ class UsersProjectObserver < ActiveRecord::Observer | @@ -2,4 +2,8 @@ class UsersProjectObserver < ActiveRecord::Observer | ||
| 2 | def after_create(users_project) | 2 | def after_create(users_project) |
| 3 | Notify.project_access_granted_email(users_project.id).deliver | 3 | Notify.project_access_granted_email(users_project.id).deliver |
| 4 | end | 4 | end |
| 5 | + | ||
| 6 | + def after_update(users_project) | ||
| 7 | + Notify.project_access_granted_email(users_project.id).deliver | ||
| 8 | + end | ||
| 5 | end | 9 | end |
config/application.rb
| @@ -23,7 +23,7 @@ module Gitlab | @@ -23,7 +23,7 @@ module Gitlab | ||
| 23 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] | 23 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] |
| 24 | 24 | ||
| 25 | # Activate observers that should always be running. | 25 | # Activate observers that should always be running. |
| 26 | - config.active_record.observers = :mailer_observer, :activity_observer, :project_observer, :key_observer, :issue_observer, :user_observer, :system_hook_observer | 26 | + config.active_record.observers = :mailer_observer, :activity_observer, :project_observer, :key_observer, :issue_observer, :user_observer, :system_hook_observer, :users_project_observer |
| 27 | 27 | ||
| 28 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. | 28 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. |
| 29 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. | 29 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. |
spec/observers/users_project_observer_spec.rb
| @@ -6,8 +6,8 @@ describe UsersProjectObserver do | @@ -6,8 +6,8 @@ describe UsersProjectObserver do | ||
| 6 | code: "Fuu", | 6 | code: "Fuu", |
| 7 | path: "Fuu" ) } | 7 | path: "Fuu" ) } |
| 8 | let(:users_project) { Factory.create(:users_project, | 8 | let(:users_project) { Factory.create(:users_project, |
| 9 | - project: project, | ||
| 10 | - user: user )} | 9 | + project: project, |
| 10 | + user: user )} | ||
| 11 | subject { UsersProjectObserver.instance } | 11 | subject { UsersProjectObserver.instance } |
| 12 | 12 | ||
| 13 | describe "#after_create" do | 13 | describe "#after_create" do |
| @@ -24,4 +24,17 @@ describe UsersProjectObserver do | @@ -24,4 +24,17 @@ describe UsersProjectObserver do | ||
| 24 | subject.after_create(users_project) | 24 | subject.after_create(users_project) |
| 25 | end | 25 | end |
| 26 | end | 26 | end |
| 27 | + | ||
| 28 | + describe "#after_update" do | ||
| 29 | + it "should called when UsersProject updated" do | ||
| 30 | + subject.should_receive(:after_update) | ||
| 31 | + UsersProject.observers.enable :users_project_observer do | ||
| 32 | + users_project.update_attribute(:project_access, 40) | ||
| 33 | + end | ||
| 34 | + end | ||
| 35 | + it "should send email to user" do | ||
| 36 | + Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true)) | ||
| 37 | + subject.after_update(users_project) | ||
| 38 | + end | ||
| 39 | + end | ||
| 27 | end | 40 | end |