Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions app/controllers/volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def edit

def update
authorize @volunteer

@volunteer.skip_reconfirmation!

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

Expand Down
2 changes: 1 addition & 1 deletion app/views/volunteers/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
type: "submit",
class: "main-btn primary-btn btn-hover btn-sm my-1"
) do %>
<i class="lni lni-checkmark-circle mr-5"></i> Submit
<i class="lni lni-checkmark-circle mr-5"></i> Update
<% end %>
</div>
<% end %>
Expand Down
16 changes: 9 additions & 7 deletions spec/requests/volunteers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,20 @@
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 sending a confirmation email" do
old_email = volunteer.email
new_email = "newemail@example.com"

patch volunteer_path(volunteer), params: {
volunteer: {email: "newemail@gmail.com"}
volunteer: {email: new_email}
}
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("You can confirm your account email through the link below:")

expect(volunteer.email).to eq(new_email)
expect(volunteer.old_emails).to eq([old_email])
expect(volunteer.unconfirmed_email).to eq(nil)
end
end

Expand Down
57 changes: 18 additions & 39 deletions spec/system/volunteers/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
fill_in "volunteer_display_name", with: "Kamisato Ayato"
fill_in "volunteer_phone_number", with: "+14163248967"
fill_in "volunteer_date_of_birth", with: Date.new(1998, 7, 1)
click_on "Submit"
click_on "Update"

expect(page).to have_text "Volunteer was successfully updated."
end
Expand All @@ -31,7 +31,7 @@
visit edit_volunteer_path(volunteer)

fill_in "volunteer_phone_number", with: "+141632489"
click_on "Submit"
click_on "Update"
expect(page).to have_text "Phone number must be 10 digits or 12 digits including country code (+1)"
end

Expand All @@ -44,7 +44,7 @@
visit edit_volunteer_path(volunteer)

fill_in "volunteer_phone_number", with: "+141632180923"
click_on "Submit"
click_on "Update"

expect(page).to have_text "Phone number must be 10 digits or 12 digits including country code (+1)"
end
Expand All @@ -58,7 +58,7 @@
visit edit_volunteer_path(volunteer)

fill_in "volunteer_phone_number", with: "+141632u809o"
click_on "Submit"
click_on "Update"

expect(page).to have_text "Phone number must be 10 digits or 12 digits including country code (+1)"
end
Expand All @@ -72,7 +72,7 @@
visit edit_volunteer_path(volunteer)

fill_in "volunteer_phone_number", with: "+24163218092"
click_on "Submit"
click_on "Update"

expect(page).to have_text "Phone number must be 10 digits or 12 digits including country code (+1)"
end
Expand All @@ -86,7 +86,7 @@
visit edit_volunteer_path(volunteer)

fill_in "volunteer_date_of_birth", with: 5.days.from_now
click_on "Submit"
click_on "Update"

expect(page).to have_text "Date of birth must be in the past."
end
Expand All @@ -104,7 +104,7 @@
fill_in "volunteer_display_name", with: "Kamisato Ayato"
fill_in "volunteer_email", with: admin.email
fill_in "volunteer_display_name", with: "Mickey Mouse"
click_on "Submit"
click_on "Update"

expect(page).to have_text "already been taken"
end
Expand All @@ -120,7 +120,7 @@

fill_in "volunteer_email", with: ""
fill_in "volunteer_display_name", with: ""
click_on "Submit"
click_on "Update"

expect(page).to have_text "can't be blank"
end
Expand All @@ -129,48 +129,27 @@

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 volunteer email without sending a confirmaiton email" 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

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("You can confirm your account email through the link below:")

expect(page).to have_text "Volunteer was successfully updated. Confirmation Email Sent."
expect(page).to have_field("Email", with: old_email)
expect(volunteer.unconfirmed_email).to eq("newemail@example.com")
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
new_email = "newemail@example.com"

sign_in admin
visit edit_volunteer_path(volunteer)

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

visit edit_volunteer_path(volunteer)
volunteer.reload

expect(page).to have_field("Email", with: "newemail@example.com")
expect(page).not_to have_field("Email", with: old_email)
expect(page).to have_text "Volunteer was successfully updated."
expect(page).to have_field("Email", with: new_email)
expect(volunteer.email).to eq(new_email)
expect(volunteer.old_emails).to eq([old_email])
expect(volunteer.unconfirmed_email).to eq(nil)
end
end
end
Expand Down Expand Up @@ -734,7 +713,7 @@
visit edit_volunteer_path(volunteer)

fill_in "volunteer_address_attributes_content", with: "123 Main St"
click_on "Submit"
click_on "Update"
expect(page).to have_text "Volunteer was successfully updated."
expect(page).to have_selector("input[value='123 Main St']")
end
Expand Down
Loading