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
9 changes: 9 additions & 0 deletions app/controllers/volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def edit

def update
authorize @volunteer
skip_volunteer_email_reconfirmation

if @volunteer.update(update_volunteer_params)
notice = check_unconfirmed_email_notice(@volunteer)

Expand Down Expand Up @@ -224,6 +226,13 @@ def update_volunteer_params
.without_active
end

def skip_volunteer_email_reconfirmation
return unless update_volunteer_params[:email].present?
return if update_volunteer_params[:email] == @volunteer.email

@volunteer.skip_reconfirmation!
end

def volunteers_phone_number
authorize @volunteer
@volunteers_phone_number = @volunteer.phone_number
Expand Down
10 changes: 4 additions & 6 deletions spec/requests/volunteers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,16 @@
expect(volunteer.phone_number).to eq "15463457898"
end

it "sends the volunteer a confirmation email upon email change" do
it "updates the volunteer email without requiring reconfirmation" do
patch volunteer_path(volunteer), params: {
volunteer: {email: "newemail@gmail.com"}
}
expect(response).to have_http_status(:redirect)

volunteer.reload
expect(volunteer.unconfirmed_email).to eq("newemail@gmail.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("Confirm my email")
expect(volunteer.email).to eq("newemail@gmail.com")
expect(volunteer.unconfirmed_email).to be_nil
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
end

Expand Down
32 changes: 5 additions & 27 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 volunteer email immediately" 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("Confirm my 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