From 82f863b7ffddd54a5e860743d37b7df9b1992b96 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 3 Jun 2025 06:32:19 +0300 Subject: [PATCH] Move profile location editing to location page --- .../profiles/descriptions_controller.rb | 4 -- .../profiles/locations_controller.rb | 4 ++ app/views/profiles/descriptions/show.html.erb | 22 -------- app/views/profiles/locations/show.html.erb | 23 ++++++++ config/locales/en.yml | 11 ++-- .../profiles/locations_controller_test.rb | 53 +++++++++++++++++++ test/system/user_location_change_test.rb | 7 ++- 7 files changed, 91 insertions(+), 33 deletions(-) diff --git a/app/controllers/profiles/descriptions_controller.rb b/app/controllers/profiles/descriptions_controller.rb index 6a6b9a99f..84a865b72 100644 --- a/app/controllers/profiles/descriptions_controller.rb +++ b/app/controllers/profiles/descriptions_controller.rb @@ -25,10 +25,6 @@ module Profiles current_user.company = params[:user][:company] - current_user.home_lat = params[:user][:home_lat] - current_user.home_lon = params[:user][:home_lon] - current_user.home_location_name = params[:user][:home_location_name] - current_user.save end end diff --git a/app/controllers/profiles/locations_controller.rb b/app/controllers/profiles/locations_controller.rb index a4e6e997c..7e971ecd1 100644 --- a/app/controllers/profiles/locations_controller.rb +++ b/app/controllers/profiles/locations_controller.rb @@ -3,6 +3,10 @@ module Profiles private def update_profile + current_user.home_lat = params[:user][:home_lat] + current_user.home_lon = params[:user][:home_lon] + current_user.home_location_name = params[:user][:home_location_name] + current_user.save end end diff --git a/app/views/profiles/descriptions/show.html.erb b/app/views/profiles/descriptions/show.html.erb index 8a053e61e..34d00da3e 100644 --- a/app/views/profiles/descriptions/show.html.erb +++ b/app/views/profiles/descriptions/show.html.erb @@ -9,8 +9,6 @@ <%= render :partial => "navigation" %> <% end %> -<%= render :partial => "layouts/control_icons", :locals => { :icons => %w[zoomin zoomout geolocate] } %> - <%= bootstrap_form_for current_user, :url => { :action => :update }, :html => { :multipart => true, :autocomplete => :off } do |f| %> <%= f.richtext_field :description, :cols => 80, :rows => 20 %> @@ -73,26 +71,6 @@ <%= f.text_field :company, :id => "company" %> -
- <%= t ".home location" -%> -

<%= t ".no home location" %>

-
- <%= f.text_field :home_lat, :wrapper_class => "col-sm-4 d-flex flex-column", :class => "mt-auto", :id => "home_lat" %> - <%= f.text_field :home_lon, :wrapper_class => "col-sm-4 d-flex flex-column", :class => "mt-auto", :id => "home_lon" %> -
- - - -
-
- <%= f.text_field :home_location_name, :wrapper_class => "my-2 col-sm-4 pe-3", :class => "mt-auto", :id => "home_location_name" %> -
- checked <% end %> id="updatehome" /> - -
- <%= tag.div "", :id => "map", :class => "content_map border border-secondary-subtle rounded z-0" %> -
- <%= f.primary t(".save") %> <%= link_to t(".cancel"), current_user, :class => "btn btn-link" %> <% end %> diff --git a/app/views/profiles/locations/show.html.erb b/app/views/profiles/locations/show.html.erb index a63e38f56..9d18226ff 100644 --- a/app/views/profiles/locations/show.html.erb +++ b/app/views/profiles/locations/show.html.erb @@ -1,3 +1,7 @@ +<% content_for :head do %> + <%= javascript_include_tag "user" %> +<% end %> + <% content_for :heading_class, "pb-0" %> <% content_for :heading do %> @@ -5,7 +9,26 @@ <%= render :partial => "navigation" %> <% end %> +<%= render :partial => "layouts/control_icons", :locals => { :icons => %w[zoomin zoomout geolocate] } %> + <%= bootstrap_form_for current_user, :url => { :action => :update } do |f| %> +

<%= t ".no home location" %>

+
+ <%= f.text_field :home_lat, :wrapper_class => "col-sm-4 d-flex flex-column", :class => "mt-auto", :id => "home_lat" %> + <%= f.text_field :home_lon, :wrapper_class => "col-sm-4 d-flex flex-column", :class => "mt-auto", :id => "home_lon" %> +
+ + + +
+
+ <%= f.text_field :home_location_name, :wrapper_class => "my-2 col-sm-4 pe-3", :class => "mt-auto", :id => "home_location_name" %> +
+ checked <% end %> id="updatehome" /> + +
+ <%= tag.div "", :id => "map", :class => "content_map border border-secondary-subtle rounded z-0" %> + <%= f.primary t(".save") %> <%= link_to t(".cancel"), current_user, :class => "btn btn-link" %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 5dcabb3c0..e19bf6ee2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2013,12 +2013,6 @@ en: delete image: "Remove the current image" replace image: "Replace the current image" image size hint: "(square images at least 100x100 work best)" - home location: "Home Location" - no home location: "You have not entered your home location." - update home location on click: "Update home location when I click on the map?" - show: "Show" - delete: "Delete" - undelete: "Undo delete" social_links: title: Social Profile Links remove: Remove @@ -2031,6 +2025,11 @@ en: title: Edit Profile save: Update Profile cancel: Cancel + no home location: "You have not entered your home location." + update home location on click: "Update home location when I click on the map?" + show: "Show" + delete: "Delete" + undelete: "Undo delete" update: success: Profile updated. failure: Couldn't update profile. diff --git a/test/controllers/profiles/locations_controller_test.rb b/test/controllers/profiles/locations_controller_test.rb index b1bbf141f..6d713d7f4 100644 --- a/test/controllers/profiles/locations_controller_test.rb +++ b/test/controllers/profiles/locations_controller_test.rb @@ -30,5 +30,58 @@ module Profiles assert_redirected_to login_path(:referer => profile_location_path) end + + def test_update + user = create(:user) + session_for(user) + + put profile_location_path, :params => { :user => { :home_lat => 60, :home_lon => 30, :home_location_name => "Лисий Нос" } } + + assert_redirected_to user_path(user) + follow_redirect! + assert_response :success + assert_template :show + assert_dom ".alert-success", :text => "Profile updated." + + user.reload + assert_equal 60, user.home_lat + assert_equal 30, user.home_lon + assert_equal "Лисий Нос", user.home_location_name + assert_equal 3543348019, user.home_tile + end + + def test_update_lat_out_of_range + user = create(:user) + session_for(user) + + put profile_location_path, :params => { :user => { :home_lat => 91, :home_lon => 30, :home_location_name => "Лисий Нос" } } + + assert_response :success + assert_template :show + assert_dom ".alert-danger", :text => "Couldn't update profile." + + user.reload + assert_nil user.home_lat + assert_nil user.home_lon + assert_nil user.home_location_name + assert_nil user.home_tile + end + + def test_update_lon_out_of_range + user = create(:user) + session_for(user) + + put profile_location_path, :params => { :user => { :home_lat => 60, :home_lon => 181, :home_location_name => "Лисий Нос" } } + + assert_response :success + assert_template :show + assert_dom ".alert-danger", :text => "Couldn't update profile." + + user.reload + assert_nil user.home_lat + assert_nil user.home_lon + assert_nil user.home_location_name + assert_nil user.home_tile + end end end diff --git a/test/system/user_location_change_test.rb b/test/system/user_location_change_test.rb index c302c5cad..c4056c9bf 100644 --- a/test/system/user_location_change_test.rb +++ b/test/system/user_location_change_test.rb @@ -15,7 +15,12 @@ class UserLocationChangeTest < ApplicationSystemTestCase assert_no_text :all, "Home location" end - visit profile_description_path + within_content_body do + click_on "Edit Profile" + end + within_content_heading do + click_on "Location" + end within_content_body do fill_in "Home Location Name", :with => "Test Place" -- 2.39.5