Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Mentors and contributors are notified when an iteration is created
Browse files Browse the repository at this point in the history
Addresses #207
  • Loading branch information
jdudley1123 committed Nov 26, 2019
1 parent 2e1ee0a commit 16f307e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
2 changes: 2 additions & 0 deletions app/controllers/iterations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def create
@iteration = authorize @project.iterations.new(iteration_params)

if @iteration.save
NotificationsMailer.iteration_added(@iteration, current_user).deliver_now
redirect_to project_iteration_url(@project, @iteration), notice: msg(@iteration.draftable?)
else
render :new
Expand All @@ -33,6 +34,7 @@ def update
@iteration = authorize @project.iterations.find_by(id: params[:id])

if @iteration.update(iteration_params)
NotificationsMailer.iteration_added(@iteration, current_user).deliver_now
redirect_to project_iteration_url(@project, @iteration), notice: msg(@iteration.draftable?)
else
render :edit
Expand Down
8 changes: 8 additions & 0 deletions app/mailers/notifications_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ def debrief_overdue(iteration)
emails = emails_by_role(iteration, %w[contributor mentor])
mail to: emails, subject: 'Debrief overdue!'
end

def iteration_added(iteration, user)
@iteration = iteration
@project = @iteration.project
@user = user
emails = emails_by_role(@iteration, %w[contributor mentor])
mail to: emails, subject: "#{@user.full_name} has added an interation for #{@project.title}"
end

private

Expand Down
5 changes: 5 additions & 0 deletions app/views/notifications_mailer/iteration_added.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Iteration Added</h1>

<p><%= @user.full_name %> has added an iteration for <%= @project.title %> on Fusebox.</p>

<p><%= link_to 'View iteration', project_iteration_url(@project, @iteration) %></p>
2 changes: 1 addition & 1 deletion test/system/debriefs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DebriefsTest < ApplicationSystemTestCase
assert_text('Debrief')
end

test 'mentors and contributors are notified when a debrief is completed' do
test 'mentors, contributors and stakeholders are notified when a debrief is completed' do
Membership.last.update(role: :contributor)
@contributor = @user
@mentor = create(:user, projects: [@project])
Expand Down
49 changes: 40 additions & 9 deletions test/system/iterations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@ class IterationsTest < ApplicationSystemTestCase
end

test 'can commit to iteration' do
click_on 'New iteration'
fill_in :iteration_title, with: 'Title'
click_link 'Add outcome'
fill_in 'What are we going to learn or prove?', with: 'Title'
fill_in "As a minimum, we'll know we've learnt or proved this when...", with: 'Success criteria'
fill_in :iteration_start_date, with: Time.zone.today
fill_in :iteration_planned_debrief_date, with: 6.weeks.since
page.accept_confirm { click_on 'Commit to iteration' }

submit_iteration
assert_equal(project_iteration_path(@project, Iteration.last), current_path)
assert_text 'Iteration saved.'
end

Expand Down Expand Up @@ -89,6 +82,29 @@ class IterationsTest < ApplicationSystemTestCase
visit new_project_iteration_path(@project, iteration)
assert_text('New iteration')
end

test 'mentors and contributors are notified when an iteration is added' do
Membership.last.update(role: :contributor)
@contributor = @user
@mentor = create(:user, projects: [@project])
Membership.last.update(role: :mentor)

submit_iteration
assert_equal(project_iteration_path(@project, Iteration.last), current_path)

mail = ActionMailer::Base.deliveries.last

recipients = [
@contributor.email,
@mentor.email
]

assert_equal("#{@user.full_name} has added an interation for #{@project.title}", mail.subject)

mail.to.each do |recipient|
assert_includes(recipients, recipient)
end
end

test 'contributors can edit iterations' do
Membership.last.update(role: :contributor)
Expand Down Expand Up @@ -211,4 +227,19 @@ class IterationsTest < ApplicationSystemTestCase
visit edit_project_iteration_path(@project, iteration)
assert_text("Sorry, you don't have access to that")
end

private

def submit_iteration
click_on 'New iteration'
fill_in :iteration_title, with: 'Title'
click_link 'Add outcome'
fill_in 'What are we going to learn or prove?', with: 'Title'
fill_in "As a minimum, we'll know we've learnt or proved this when...", with: 'Success criteria'
fill_in :iteration_start_date, with: Time.zone.today
fill_in :iteration_planned_debrief_date, with: 6.weeks.since
page.accept_confirm { click_on 'Commit to iteration' }
sleep 1
end

end

0 comments on commit 16f307e

Please sign in to comment.