Skip to content

Commit

Permalink
Merge pull request #31 from cs169/feature/187044317-add-email-resend-…
Browse files Browse the repository at this point in the history
…flash-message

Feature/187044317 add email resend flash message
  • Loading branch information
ArushC authored Feb 26, 2024
2 parents 4862e0b + 3aefd1e commit 928c57b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/teachers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +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!"
else
flash[:alert] = "Error resending welcome email. \
Please ensure that your account has been validated by an administrator."
end
redirect_to edit_teacher_path(@teacher)
end

def import
Expand Down
19 changes: 19 additions & 0 deletions spec/controllers/teachers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,23 @@
expect(Teacher.find_by(email: "valid_example@valid_example.edu").not_reviewed?).to be true
end
end

context "flash a message after resend_welcome_email" do
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")
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))
end

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")
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))
end
end
end

0 comments on commit 928c57b

Please sign in to comment.