From 0040234bc6ee357ab66296e95694c7d2e8932d30 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 3 Jun 2025 17:40:09 +0300 Subject: [PATCH] Move profile company editing to company page --- app/controllers/profiles/companies_controller.rb | 2 ++ .../profiles/descriptions_controller.rb | 2 -- app/views/profiles/companies/show.html.erb | 2 ++ app/views/profiles/descriptions/show.html.erb | 6 +----- .../profiles/companies_controller_test.rb | 16 ++++++++++++++++ .../profiles/descriptions_controller_test.rb | 10 ---------- test/system/user_company_test.rb | 2 +- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/controllers/profiles/companies_controller.rb b/app/controllers/profiles/companies_controller.rb index 001759a1b..de9a3d189 100644 --- a/app/controllers/profiles/companies_controller.rb +++ b/app/controllers/profiles/companies_controller.rb @@ -3,6 +3,8 @@ module Profiles private def update_profile + current_user.company = params[:user][:company] + current_user.save end end diff --git a/app/controllers/profiles/descriptions_controller.rb b/app/controllers/profiles/descriptions_controller.rb index 84a865b72..1419c6df3 100644 --- a/app/controllers/profiles/descriptions_controller.rb +++ b/app/controllers/profiles/descriptions_controller.rb @@ -23,8 +23,6 @@ module Profiles current_user.image_use_gravatar = true end - current_user.company = params[:user][:company] - current_user.save end end diff --git a/app/views/profiles/companies/show.html.erb b/app/views/profiles/companies/show.html.erb index a63e38f56..876f0564a 100644 --- a/app/views/profiles/companies/show.html.erb +++ b/app/views/profiles/companies/show.html.erb @@ -6,6 +6,8 @@ <% end %> <%= bootstrap_form_for current_user, :url => { :action => :update } do |f| %> + <%= f.text_field :company %> + <%= f.primary t(".save") %> <%= link_to t(".cancel"), current_user, :class => "btn btn-link" %> <% end %> diff --git a/app/views/profiles/descriptions/show.html.erb b/app/views/profiles/descriptions/show.html.erb index 34d00da3e..956dc5d33 100644 --- a/app/views/profiles/descriptions/show.html.erb +++ b/app/views/profiles/descriptions/show.html.erb @@ -67,10 +67,6 @@ -
- <%= f.text_field :company, :id => "company" %> -
- <%= f.primary t(".save") %> - <%= link_to t(".cancel"), current_user, :class => "btn btn-link" %> + <%= link_to t(".cancel"), current_user, :class => "btn btn-link" %> <% end %> diff --git a/test/controllers/profiles/companies_controller_test.rb b/test/controllers/profiles/companies_controller_test.rb index 5b9b2b0ef..7a8bfa0e5 100644 --- a/test/controllers/profiles/companies_controller_test.rb +++ b/test/controllers/profiles/companies_controller_test.rb @@ -30,5 +30,21 @@ module Profiles assert_redirected_to login_path(:referer => profile_company_path) end + + def test_update + user = create(:user) + session_for(user) + + put profile_company_path, :params => { :user => { :company => "new company", :description => user.description } } + + 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 "new company", user.company + end end end diff --git a/test/controllers/profiles/descriptions_controller_test.rb b/test/controllers/profiles/descriptions_controller_test.rb index 09d98db02..7cda7396a 100644 --- a/test/controllers/profiles/descriptions_controller_test.rb +++ b/test/controllers/profiles/descriptions_controller_test.rb @@ -90,16 +90,6 @@ module Profiles assert_template :show assert_select ".alert-success", /^Profile updated./ assert_select "a", "test.com/test" - - # Updating the company name should work - put profile_description_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./ - user.reload - assert_equal "new company", user.company end def test_update_empty_social_link diff --git a/test/system/user_company_test.rb b/test/system/user_company_test.rb index 3d0ae5367..2acea4d7a 100644 --- a/test/system/user_company_test.rb +++ b/test/system/user_company_test.rb @@ -11,7 +11,7 @@ class UserCompanyTest < ApplicationSystemTestCase assert_no_text :all, "Company" end - visit profile_description_path + visit profile_company_path within_content_body do fill_in "Company", :with => "Test Co." -- 2.39.5