Skip to content

Commit

Permalink
What happens when email is already used
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Oct 14, 2024
1 parent 6de85c9 commit 086c349
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/controllers/alerts/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ def create
super do
# We're attaching the alert to the unconfirmed user now so that we don't have to pass around the alert
# through the registration process which would involve doing unspeakable horrors to devise.
alert = Alert.new(
@alert = Alert.new(
user: resource,
address: params[:user][:address],
radius_meters: params[:user][:radius_meters]
)
# TODO: Check that we're actually allowed to create an alert
# Ensures the address is normalised into a consistent form
alert.geocode_from_address
# TODO: Handle error state
alert.save!

if resource.persisted?
# TODO: Check that we're actually allowed to create an alert
# Ensures the address is normalised into a consistent form
@alert.geocode_from_address
# TODO: Handle error state
@alert.save!
end
end
end

Expand Down
45 changes: 45 additions & 0 deletions spec/features/sign_up_for_alerts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,51 @@
expect(page).to have_content("you added a new alert for 24 Bruce Rd, Glenbrook")
end

it "when via the homepage not registered in the alternate flow but email already used" do
use_ab_test logged_out_alert_flow_order: "create_alert_sign_in"

create(:geocoded_application, address: "26 Bruce Rd, Glenbrook NSW 2773", lat: -33.772812, lng: 150.624252, lonlat: RGeo::Geographic.spherical_factory(srid: 4326).point(150.624252, -33.772812))
user = create(:confirmed_user, email: "[email protected]", password: "mypassword")
sign_in user
visit root_path
sign_out user

visit root_path
fill_in("Street address", with: "24 Bruce Rd, Glenbrook")
within("form") do
click_on("Search")
end

expect(page).to have_content("Search results")
expect(page).to have_content("Save this search as an email alert")
click_on("Save", match: :first)

expect(page).to have_content("You'll receive email alerts when new applications match this search")
click_on("Create an account")

expect(page).to have_content("Create an account to save this search")
expect(page).to have_content("Applications within 2 km of 24 Bruce Rd, Glenbrook")

fill_in("Email", with: "[email protected]")
fill_in("Create a password", with: "mypassword")
click_on("Create account and save")

expect(page).to have_content("You already have an account with that email address")
fill_in("Email", with: "[email protected]")
fill_in("Create a password", with: "mypassword")
click_on("Create account and save")

open_email("[email protected]")
expect(current_email).to have_subject("PlanningAlerts: Confirmation instructions")
expect(current_email.default_part_body.to_s).to include("Thanks for getting onboard!")

click_email_link_matching(/confirmation/)

expect(page).to have_content("Your email address has been successfully confirmed")
expect(page).to have_content("you are now logged in")
expect(page).to have_content("you added a new alert for 24 Bruce Rd, Glenbrook")
end

it "when via the homepage but not yet have an account" do
create(:geocoded_application, address: "26 Bruce Rd, Glenbrook NSW 2773", lat: -33.772812, lng: 150.624252, lonlat: RGeo::Geographic.spherical_factory(srid: 4326).point(150.624252, -33.772812))

Expand Down

0 comments on commit 086c349

Please sign in to comment.