From 35cc26cb6ad172ab85eb49c484199cc87dadc2f7 Mon Sep 17 00:00:00 2001 From: nertc Date: Thu, 29 May 2025 11:40:25 +0400 Subject: [PATCH] Company Name on Profile Page --- app/controllers/profiles_controller.rb | 2 ++ app/models/user.rb | 1 + app/views/profiles/show.html.erb | 4 +++ app/views/users/show.html.erb | 10 +++++++ config/locales/en.yml | 3 +++ .../20250506052030_add_company_to_users.rb | 5 ++++ db/structure.sql | 4 ++- test/controllers/profiles_controller_test.rb | 9 +++++++ test/system/user_company_test.rb | 27 +++++++++++++++++++ 9 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20250506052030_add_company_to_users.rb create mode 100644 test/system/user_company_test.rb diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 8270916bf..b24a9f2b3 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -32,6 +32,8 @@ class ProfilesController < ApplicationController current_user.image_use_gravatar = true end + 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] diff --git a/app/models/user.rb b/app/models/user.rb index 3dcbddf89..e7a886029 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -34,6 +34,7 @@ # diary_comments_count :integer default(0) # note_comments_count :integer default(0) # creation_address :inet +# company :string # # Indexes # diff --git a/app/views/profiles/show.html.erb b/app/views/profiles/show.html.erb index d09242024..ae87a7b06 100644 --- a/app/views/profiles/show.html.erb +++ b/app/views/profiles/show.html.erb @@ -58,6 +58,10 @@ +
+ <%= f.text_field :company, :id => "company" %> +
+
<%= t ".home location" -%>

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

diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index e9809fed1..8f2681035 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -152,6 +152,16 @@
<%= @user.home_location_name %>
<% end %> + <% if @user.company&.strip.present? %> +
+ + + <%= t ".company" %> + + +
+
"><%= @user.company %>
+ <% end %>
<%= t ".mapper since" %>
<%= l @user.created_at.to_date, :format => :long %>
<%= t ".last map edit" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 32d577db7..7f3f4b7db 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -150,6 +150,7 @@ en: active: "Active" display_name: "Display Name" description: Profile Description + company: Company home_lat: Latitude home_lon: Longitude languages: Preferred Languages @@ -2939,6 +2940,8 @@ en: mapper since: "Mapper since:" last map edit: "Last map edit:" home location: "Home location" + company: "Company" + company tooltip: "The company affiliation is self-reported and not verified" no activity yet: "No activity yet" uid: "User id:" ct status: "Contributor terms:" diff --git a/db/migrate/20250506052030_add_company_to_users.rb b/db/migrate/20250506052030_add_company_to_users.rb new file mode 100644 index 000000000..d62a7aeca --- /dev/null +++ b/db/migrate/20250506052030_add_company_to_users.rb @@ -0,0 +1,5 @@ +class AddCompanyToUsers < ActiveRecord::Migration[8.0] + def change + add_column :users, :company, :string + end +end diff --git a/db/structure.sql b/db/structure.sql index c04b56ca4..f50e9cfb6 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1552,7 +1552,8 @@ CREATE TABLE public.users ( diary_comments_count integer DEFAULT 0, note_comments_count integer DEFAULT 0, creation_address inet, - home_location_name character varying + home_location_name character varying, + company character varying ); @@ -3513,6 +3514,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('23'), ('22'), ('21'), +('20250506052030'), ('20250304172798'), ('20250304172758'), ('20250217140049'), diff --git a/test/controllers/profiles_controller_test.rb b/test/controllers/profiles_controller_test.rb index 849d1e099..c31a46798 100644 --- a/test/controllers/profiles_controller_test.rb +++ b/test/controllers/profiles_controller_test.rb @@ -70,5 +70,14 @@ class ProfilesControllerTest < ActionDispatch::IntegrationTest assert_template :show assert_select ".alert-success", /^Profile updated./ assert_select "a", "test.com/test" + + # Updating the company name should work + put profile_path, :params => { :user => { :company => "new company", :description => user.description } } + assert_redirected_to user_path(user) + follow_redirect! + assert_response :success + assert_template :show + assert_select ".alert-success", /^Profile updated./ + assert_select "dd", "new company" end end diff --git a/test/system/user_company_test.rb b/test/system/user_company_test.rb new file mode 100644 index 000000000..ad23f16bc --- /dev/null +++ b/test/system/user_company_test.rb @@ -0,0 +1,27 @@ +require "application_system_test_case" + +class UserCompanyTest < ApplicationSystemTestCase + test "User can change company" do + user = create(:user) + sign_in_as(user) + company = "Test Company" + + visit user_path(user) + + within_content_heading do + assert_no_selector ".bi.bi-suitcase-lg-fill" + end + + visit profile_path + + assert_text I18n.t("activerecord.attributes.user.company") + + fill_in "Company", :with => company + click_on I18n.t("profiles.show.save") + + assert_text I18n.t("profiles.update.success") + within_content_heading do + assert_text company + end + end +end -- 2.39.5