Commit 2e7abbd66c1e68eaf6cd227ce7e26e2d9a3d4180

Authored by Dmitriy Zaporozhets
1 parent 065d9c22

Move repo rename email to notification service

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/models/project.rb
... ... @@ -270,9 +270,7 @@ class Project &lt; ActiveRecord::Base
270 270 end
271 271  
272 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 274 end
277 275  
278 276 def owner
... ...
app/services/notification_service.rb
... ... @@ -157,6 +157,15 @@ class NotificationService
157 157 mailer.group_access_granted_email(users_group.id)
158 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 169 protected
161 170  
162 171 # Get project users with WATCH notification level
... ...
spec/services/notification_service_spec.rb
... ... @@ -233,6 +233,31 @@ describe NotificationService do
233 233 end
234 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 261 def build_team(project)
237 262 @u_watcher = create(:user, notification_level: Notification::N_WATCH)
238 263 @u_participating = create(:user, notification_level: Notification::N_PARTICIPATING)
... ...