diff --git a/app/controllers/teachers_controller.rb b/app/controllers/teachers_controller.rb index 12214763..d6f0a5a1 100644 --- a/app/controllers/teachers_controller.rb +++ b/app/controllers/teachers_controller.rb @@ -160,13 +160,12 @@ def destroy def resend_welcome_email if @teacher.validated? || @is_admin - TeacherMailer.welcome_email(@teacher).deliver_now flash[:success] = "Welcome email resent successfully!" + TeacherMailer.welcome_email(@teacher).deliver_now else - flash[:alert] = "Error resending welcome email. \ - Please ensure that your account has been validated by an administrator." + flash[:alert] = "Error resending welcome email. Please ensure that your account has been validated by an administrator." end - redirect_to edit_teacher_path(@teacher) + redirect_back(fallback_location: dashboard_path) end def import diff --git a/spec/controllers/teachers_controller_spec.rb b/spec/controllers/teachers_controller_spec.rb index 99a91370..56bf3b17 100644 --- a/spec/controllers/teachers_controller_spec.rb +++ b/spec/controllers/teachers_controller_spec.rb @@ -188,6 +188,7 @@ it "succeeds when teacher is validated, sets success" do ApplicationController.any_instance.stub(:current_user).and_return(Teacher.find_by(first_name: "Validated")) validated_teacher = Teacher.find_by(first_name: "Validated") + request.env["HTTP_REFERER"] = edit_teacher_path(validated_teacher.id) post :resend_welcome_email, params: { id: validated_teacher.id } expect(flash[:success]).to eq("Welcome email resent successfully!") expect(response).to redirect_to(edit_teacher_path(validated_teacher.id)) @@ -196,10 +197,10 @@ it "fails when teacher is not validated, sets alert" do ApplicationController.any_instance.stub(:current_user).and_return(Teacher.find_by(first_name: "Short")) nonvalidated_teacher = Teacher.find_by(first_name: "Short") + request.env["HTTP_REFERER"] = teacher_path(nonvalidated_teacher.id) post :resend_welcome_email, params: { id: nonvalidated_teacher.id } - expect(flash[:alert]).to eq("Error resending welcome email. \ - Please ensure that your account has been validated by an administrator.") - expect(response).to redirect_to(edit_teacher_path(nonvalidated_teacher.id)) + expect(flash[:alert]).to eq("Error resending welcome email. Please ensure that your account has been validated by an administrator.") + expect(response).to redirect_to(teacher_path(nonvalidated_teacher.id)) end end end