Refactor profile location handling: remove location field from forms and update tests

This commit is contained in:
Brenda Wallace committed 2026-11-02 08:19:14 +13:00
1 parent d94cc87983
commit 3cfcf58324
5 files changed
+48 -7

No files matched your search

+2 -2
View File
@@ -77,7 +77,7 @@ class ApplicationController < ActionController::Base
# terms of service
:tos_agreement,
# profile stuff
:bio, :location, :latitude, :longitude,
:bio,
# email settings
:show_email, :send_notification_email, :send_planting_reminder, :send_harvest_reminder)
end
@@ -88,7 +88,7 @@ class ApplicationController < ActionController::Base
# terms of service
:tos_agreement,
# profile stuff
:bio, :location, :latitude, :longitude,
:bio,
:website_url, :instagram_handle, :facebook_handle, :bluesky_handle, :other_url,
# email settings
:show_email, :send_notification_email, :send_planting_reminder, :send_harvest_reminder,
@@ -4,11 +4,19 @@
%br/
= render 'devise/shared/error_messages', resource: resource
-# Only places we found can be saved, so the location is set in its dialog,
-# not typed here. Choosing a place saves it and reloads the page.
.row.mb-3
= f.label :location, 'Your location', class: 'col-form-label col-md-2'
%span.col-form-label.col-md-2 Your location
.col-md-8
= f.text_field :location, autocomplete: "off", class: 'form-control'
%span.form-text This will be displayed on a map. You can be as detailed or vague as you like.
- link = 'btn btn-link p-0 align-baseline'
%p.mb-0
- if resource.location.present?
%strong= resource.location
= render 'home/dashboard/location_picker', label: 'Change', button_class: link
- else
= render 'home/dashboard/location_picker', label: 'Set your location', button_class: link
%span.form-text Pick from the places we find, so you're in the right spot on the map. A region is fine.
.row.mb-3
= f.label :bio, class: 'col-form-label col-md-2'
@@ -3,6 +3,10 @@
- content_for :breadcrumbs do
%li.breadcrumb-item= link_to 'My Profile', member_path(current_member)
-# The location link opens a dialog, which is a React island.
- content_for :scripts do
= javascript_include_tag 'react_islands', defer: true
%h1
= member_icon
Settings for #{current_member.login_name}
@@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
describe RegistrationsController, '#update' do
let(:member) { create(:member, bio: 'Hello') }
before do
sign_in member
put member_registration_path, params: { member: { bio: 'Hello again', location: 'somewhere over the rainbow' } }
end
it 'saves the rest of the profile' do
expect(member.reload.bio).to eq('Hello again')
end
it 'does not take a location typed in' do
expect(member.reload.location).to be_blank
end
end
+11 -2
View File
@@ -50,8 +50,17 @@ describe 'devise/registrations/edit.html.haml', type: "view" do
assert_select "textarea[id=member_bio]"
end
it 'shows location field' do
assert_select "input[id=member_location][type=text]"
it 'has no location text field' do
assert_select "input[id=member_location]", count: 0
end
it 'loads the script that makes the location link work' do
render
expect(view.content_for(:scripts)).to include('react_islands')
end
it 'has a link to set the location in its dialog' do
assert_select "[data-react-component=LocationPicker]"
end
end