Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/controllers/all_casa_admins/casa_admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ def edit

def update
@casa_admin = CasaAdmin.find(params[:id])
@casa_admin.skip_reconfirmation!
if @casa_admin.update(all_casa_admin_params)
notice = check_unconfirmed_email_notice(@casa_admin)

@casa_admin.filter_old_emails!(@casa_admin.email)
redirect_to edit_all_casa_admins_casa_org_casa_admin_path(@casa_org), notice: notice
redirect_to edit_all_casa_admins_casa_org_casa_admin_path(@casa_org), notice: "Casa admin was successfully updated."
else
render :edit, status: :unprocessable_content
end
Expand Down
8 changes: 0 additions & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,4 @@ def unsupported_media_type
end
end
end

def check_unconfirmed_email_notice(user)
notice = "#{user.role} was successfully updated."
if user.saved_changes.include?("unconfirmed_email")
notice += " Confirmation Email Sent."
end
notice
end
end
5 changes: 2 additions & 3 deletions app/controllers/casa_admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ def edit

def update
authorize @casa_admin
@casa_admin.skip_reconfirmation!
if @casa_admin.update(update_casa_admin_params)
notice = check_unconfirmed_email_notice(@casa_admin)

@casa_admin.filter_old_emails!(@casa_admin.email)
respond_to do |format|
format.html { redirect_to edit_casa_admin_path(@casa_admin), notice: notice }
format.html { redirect_to edit_casa_admin_path(@casa_admin), notice: "Casa Admin was successfully updated." }
format.json { render json: @casa_admin, status: :ok }
end
else
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/supervisors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ def edit

def update
authorize @supervisor
@supervisor.skip_reconfirmation!
if @supervisor.update(update_supervisor_params)
notice = check_unconfirmed_email_notice(@supervisor)

@supervisor.filter_old_emails!(@supervisor.email)
redirect_to edit_supervisor_path(@supervisor), notice: notice
redirect_to edit_supervisor_path(@supervisor), notice: "Supervisor was successfully updated."
else
render :edit, status: :unprocessable_content
end
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ def edit

def update
authorize @volunteer
@volunteer.skip_reconfirmation!
if @volunteer.update(update_volunteer_params)
notice = check_unconfirmed_email_notice(@volunteer)

@volunteer.filter_old_emails!(@volunteer.email)
redirect_to edit_volunteer_path(@volunteer), notice: notice
redirect_to edit_volunteer_path(@volunteer), notice: "Volunteer was successfully updated."
else
render :edit, status: :unprocessable_content
end
Expand Down
12 changes: 5 additions & 7 deletions spec/requests/all_casa_admins/casa_admins_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,19 @@
context "with valid parameters" do
let(:params) { {all_casa_admin: {email: "casa_admin@example.com"}} }

it "allows current user to begin to update other casa admin's email and send a confirmation email" do
it "allows current user to update other casa admin's email immediately, without requiring confirmation" do
subject
casa_admin.reload
expect(casa_admin.unconfirmed_email).to eq("casa_admin@example.com")
expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message)
expect(ActionMailer::Base.deliveries.first.body.encoded)
.to match("Click here to confirm your email")
expect(casa_admin.email).to eq("casa_admin@example.com")
expect(casa_admin.unconfirmed_email).to be_nil
expect(ActionMailer::Base.deliveries.count).to eq(0)
end

it { is_expected.to redirect_to edit_all_casa_admins_casa_org_casa_admin_path(casa_org, casa_admin) }

it "shows correct flash message" do
subject
expect(flash[:notice]).to eq("Casa Admin was successfully updated. Confirmation Email Sent.")
expect(flash[:notice]).to eq("Casa Admin was successfully updated.")
end
end

Expand Down
20 changes: 5 additions & 15 deletions spec/system/casa_admins/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,14 @@
admin.reload
end

it "sends a confirmation email upon submission and does not change the user's displayed email" do
expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message)
expect(ActionMailer::Base.deliveries.first.body.encoded)
.to match("Click here to confirm your email")

expect(page).to have_text "Admin was successfully updated. Confirmation Email Sent."
expect(page).to have_field("Email", with: @old_email)
admin.reload
expect(admin.unconfirmed_email).to eq("new_admin_email@example.com")
end

it "succesfully updates the user email once the user confirms the changes" do
admin.confirm
visit edit_casa_admin_path(admin)
it "updates the email immediately without requiring confirmation" do
expect(ActionMailer::Base.deliveries.count).to eq(0)

expect(page).to have_text "Casa Admin was successfully updated."
expect(page).to have_field("Email", with: "new_admin_email@example.com")
admin.reload
expect(admin.email).to eq("new_admin_email@example.com")
expect(admin.unconfirmed_email).to be_nil
expect(admin.old_emails).to eq([@old_email])
end
end
Expand Down
22 changes: 6 additions & 16 deletions spec/system/supervisors/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,14 @@
@supervisor.reload
end

it "sends a confirmation email to the supervisor and displays current email" do
expect(page).to have_text "Supervisor was successfully updated. Confirmation Email Sent."
expect(page).to have_field("Email", with: @old_email)
expect(@supervisor.unconfirmed_email).to eq("new_supervisor_email@example.com")

expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message)
expect(ActionMailer::Base.deliveries.first.body.encoded)
.to match("Click here to confirm your email")
end

it "correctly updates the supervisor email once confirmed" do
@supervisor.confirm
@supervisor.reload
visit edit_supervisor_path(@supervisor)

it "updates the email immediately without requiring confirmation" do
expect(page).to have_text "Supervisor was successfully updated."
expect(page).to have_field("Email", with: "new_supervisor_email@example.com")
expect(@supervisor.email).to eq("new_supervisor_email@example.com")
expect(@supervisor.unconfirmed_email).to be_nil
expect(@supervisor.old_emails).to match([@old_email])

expect(ActionMailer::Base.deliveries.count).to eq(0)
end
end

Expand Down
34 changes: 6 additions & 28 deletions spec/system/volunteers/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@

describe "updating a volunteer's email" do
context "with a valid email" do
it "sends volunteer a confirmation email and does not change the displayed email" do
it "updates the email immediately without requiring confirmation" do
organization = create(:casa_org)
admin = create(:casa_admin, casa_org: organization)
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization)
Expand All @@ -141,35 +141,13 @@
fill_in "Email", with: "newemail@example.com"
click_on "Submit"

expect(page).to have_text "Volunteer was successfully updated. Confirmation Email Sent."
expect(page).to have_field("Email", with: old_email)
expect(volunteer.reload.unconfirmed_email).to eq("newemail@example.com")

expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message)
expect(ActionMailer::Base.deliveries.first.body.encoded)
.to match("Click here to confirm your email")
end

it "succesfully displays the new email once the user confirms" do
organization = create(:casa_org)
admin = create(:casa_admin, casa_org: organization)
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization)
old_email = volunteer.email

sign_in admin
visit edit_volunteer_path(volunteer)

fill_in "Email", with: "newemail@example.com"
click_on "Submit"
volunteer.reload
volunteer.confirm

visit edit_volunteer_path(volunteer)

expect(page).to have_text "Volunteer was successfully updated."
expect(page).to have_field("Email", with: "newemail@example.com")
expect(page).not_to have_field("Email", with: old_email)
expect(volunteer.reload.email).to eq("newemail@example.com")
expect(volunteer.unconfirmed_email).to be_nil
expect(volunteer.old_emails).to eq([old_email])

expect(ActionMailer::Base.deliveries.count).to eq(0)
end
end
end
Expand Down
Loading