Skip to content

Commit 9e19c9a

Browse files
committed
Send Notification Email when task gets edited
1 parent 7e64cf7 commit 9e19c9a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

app/controllers/tasks_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def create
2222
def update
2323
if @task.update(task_params.merge({assigned_to_date: calc_expiry_date}))
2424
redirect_to user_entries_path(@task.assigned_to_user), notice: 'Task was successfully updated.'
25+
TaskNotifier.task_assigned(@task).deliver_now
2526
else
2627
render :edit
2728
end

spec/controllers/tasks_controller_spec.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@
5151
post :create, task: attributes_for(:task)
5252
expect(response).to redirect_to(user_entries_path(Task.last.assigned_to_user))
5353
end
54-
it 'redirects to user_entries of assigned user' do
55-
post :create, task: attributes_for(:task)
56-
expect(response).to redirect_to(user_entries_path(Task.last.assigned_to_user))
57-
end
5854
end
5955

6056
context 'with invalid params' do
@@ -86,8 +82,13 @@
8682
end
8783

8884
it 'redirects to user_entries of assigned user' do
89-
put :update, id: task.to_param, task: attributes_for(:task, assigned_to_date: Date.today + 1.month)
90-
expect(response).to redirect_to(user_entries_path(Task.last.assigned_to_user))
85+
put :update, id: task.to_param, task: attributes_for(:task, assigned_to_user: editor.id)
86+
expect(response).to redirect_to(user_entries_path(editor))
87+
end
88+
89+
it 'sends an info-mail to assigned user' do
90+
put :update, id: task.to_param, task: attributes_for(:task, assigned_to_user: editor.id)
91+
expect(ActionMailer::Base.deliveries.last.to).to eq([editor.email])
9192
end
9293
end
9394
context 'update user_id in assigned entry' do

0 commit comments

Comments
 (0)