Commit 1fc42d9934fbf511db2a28e980b298c019a217a7
Exists in
spb-stable
and in
3 other branches
Merge branch 'improve/notification' of /home/git/repositories/gitlab/gitlabhq
Showing
3 changed files
with
35 additions
and
3 deletions
Show diff stats
app/models/project.rb
| @@ -270,9 +270,7 @@ class Project < ActiveRecord::Base | @@ -270,9 +270,7 @@ class Project < ActiveRecord::Base | ||
| 270 | end | 270 | end |
| 271 | 271 | ||
| 272 | def send_move_instructions | 272 | def send_move_instructions |
| 273 | - team.members.each do |user| | ||
| 274 | - Notify.delay.project_was_moved_email(self.id, user.id) | ||
| 275 | - end | 273 | + NotificationService.new.project_was_moved(self) |
| 276 | end | 274 | end |
| 277 | 275 | ||
| 278 | def owner | 276 | def owner |
app/services/notification_service.rb
| @@ -157,6 +157,15 @@ class NotificationService | @@ -157,6 +157,15 @@ class NotificationService | ||
| 157 | mailer.group_access_granted_email(users_group.id) | 157 | mailer.group_access_granted_email(users_group.id) |
| 158 | end | 158 | end |
| 159 | 159 | ||
| 160 | + def project_was_moved(project) | ||
| 161 | + recipients = project.team.members | ||
| 162 | + recipients = reject_muted_users(recipients, project) | ||
| 163 | + | ||
| 164 | + recipients.each do |recipient| | ||
| 165 | + mailer.project_was_moved_email(project.id, recipient.id) | ||
| 166 | + end | ||
| 167 | + end | ||
| 168 | + | ||
| 160 | protected | 169 | protected |
| 161 | 170 | ||
| 162 | # Get project users with WATCH notification level | 171 | # Get project users with WATCH notification level |
spec/services/notification_service_spec.rb
| @@ -233,6 +233,31 @@ describe NotificationService do | @@ -233,6 +233,31 @@ describe NotificationService do | ||
| 233 | end | 233 | end |
| 234 | end | 234 | end |
| 235 | 235 | ||
| 236 | + describe 'Projects' do | ||
| 237 | + let(:project) { create :project } | ||
| 238 | + | ||
| 239 | + before do | ||
| 240 | + build_team(project) | ||
| 241 | + end | ||
| 242 | + | ||
| 243 | + describe :project_was_moved do | ||
| 244 | + it do | ||
| 245 | + should_email(@u_watcher.id) | ||
| 246 | + should_email(@u_participating.id) | ||
| 247 | + should_not_email(@u_disabled.id) | ||
| 248 | + notification.project_was_moved(project) | ||
| 249 | + end | ||
| 250 | + | ||
| 251 | + def should_email(user_id) | ||
| 252 | + Notify.should_receive(:project_was_moved_email).with(project.id, user_id) | ||
| 253 | + end | ||
| 254 | + | ||
| 255 | + def should_not_email(user_id) | ||
| 256 | + Notify.should_not_receive(:project_was_moved_email).with(project.id, user_id) | ||
| 257 | + end | ||
| 258 | + end | ||
| 259 | + end | ||
| 260 | + | ||
| 236 | def build_team(project) | 261 | def build_team(project) |
| 237 | @u_watcher = create(:user, notification_level: Notification::N_WATCH) | 262 | @u_watcher = create(:user, notification_level: Notification::N_WATCH) |
| 238 | @u_participating = create(:user, notification_level: Notification::N_PARTICIPATING) | 263 | @u_participating = create(:user, notification_level: Notification::N_PARTICIPATING) |