diff --git a/app/controllers/iterations_controller.rb b/app/controllers/iterations_controller.rb index 17cf84e..e1a943d 100644 --- a/app/controllers/iterations_controller.rb +++ b/app/controllers/iterations_controller.rb @@ -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 @@ -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 diff --git a/app/mailers/notifications_mailer.rb b/app/mailers/notifications_mailer.rb index 8e28bda..e632d06 100644 --- a/app/mailers/notifications_mailer.rb +++ b/app/mailers/notifications_mailer.rb @@ -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 diff --git a/app/views/notifications_mailer/iteration_added.html.erb b/app/views/notifications_mailer/iteration_added.html.erb new file mode 100644 index 0000000..1bebbf2 --- /dev/null +++ b/app/views/notifications_mailer/iteration_added.html.erb @@ -0,0 +1,5 @@ +
<%= @user.full_name %> has added an iteration for <%= @project.title %> on Fusebox.
+ +<%= link_to 'View iteration', project_iteration_url(@project, @iteration) %>
\ No newline at end of file diff --git a/test/system/debriefs_test.rb b/test/system/debriefs_test.rb index f870acc..2b6194b 100644 --- a/test/system/debriefs_test.rb +++ b/test/system/debriefs_test.rb @@ -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]) diff --git a/test/system/iterations_test.rb b/test/system/iterations_test.rb index bee9bd8..4bc3473 100644 --- a/test/system/iterations_test.rb +++ b/test/system/iterations_test.rb @@ -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 @@ -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) @@ -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