Skip to content

Commit

Permalink
edit redirect to use current path
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonXu33 committed Feb 27, 2024
1 parent d9d096d commit c64216f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 3 additions & 4 deletions app/controllers/teachers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions spec/controllers/teachers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

0 comments on commit c64216f

Please sign in to comment.