From 0143e64ff6f03f25fe176af9f466d5a2e6e08bf9 Mon Sep 17 00:00:00 2001 From: mmeest Date: Thu, 27 Aug 2026 15:55:41 +0300 Subject: [PATCH 1/2] Sort admin registrar dropdowns alphabetically. Co-authored-by: Cursor --- app/helpers/application_helper.rb | 4 + .../account_activities/_search_form.html.erb | 2 +- .../admin/accounts/_search_form.html.erb | 2 +- app/views/admin/contacts/index.haml | 2 +- app/views/admin/domain_versions/archive.haml | 2 +- app/views/admin/domains/_search_form.html.erb | 2 +- app/views/admin/epp_logs/index.haml | 2 +- app/views/admin/invoices/new.haml | 2 +- .../invoices/partials/_search_form.html.erb | 2 +- app/views/admin/repp_logs/index.haml | 2 +- test/helpers/application_helper_test.rb | 12 +++ .../registrar_select_options_test.rb | 77 +++++++++++++++++++ test/models/registrar_test.rb | 11 +++ 13 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 test/integration/admin_area/registrar_select_options_test.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e57205a14c..7692f2e715 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -107,4 +107,8 @@ def db_hint_options end result end + + def registrar_options(value: :id) + Registrar.ordered.map { |registrar| [registrar.name, registrar.public_send(value)] } + end end diff --git a/app/views/admin/account_activities/_search_form.html.erb b/app/views/admin/account_activities/_search_form.html.erb index bf353a9361..7623d736c2 100644 --- a/app/views/admin/account_activities/_search_form.html.erb +++ b/app/views/admin/account_activities/_search_form.html.erb @@ -5,7 +5,7 @@
<%= f.label t(:registrar_name) %> - <%= f.select :account_registrar_id_in, Registrar.all.map { |x| [x, x.id] }, {}, class: 'form-control js-combobox', placeholder: t(:choose), multiple: true %> + <%= f.select :account_registrar_id_in, registrar_options, {}, class: 'form-control js-combobox', placeholder: t(:choose), multiple: true %>
diff --git a/app/views/admin/accounts/_search_form.html.erb b/app/views/admin/accounts/_search_form.html.erb index 9a0a835218..f35b864c7c 100644 --- a/app/views/admin/accounts/_search_form.html.erb +++ b/app/views/admin/accounts/_search_form.html.erb @@ -5,7 +5,7 @@
<%= f.label t(:registrar_name) %> - <%= f.select :registrar_id_in, Registrar.all.map { |x| [x, x.id] }, {}, class: 'form-control js-combobox', placeholder: t(:choose), multiple: true %> + <%= f.select :registrar_id_in, registrar_options, {}, class: 'form-control js-combobox', placeholder: t(:choose), multiple: true %>
diff --git a/app/views/admin/contacts/index.haml b/app/views/admin/contacts/index.haml index b5bfa89f18..597b013bd4 100644 --- a/app/views/admin/contacts/index.haml +++ b/app/views/admin/contacts/index.haml @@ -37,7 +37,7 @@ .col-md-3 .form-group = f.label t(:registrar_name) - = f.select :registrar_id_eq, Registrar.all.map { |x| [x, x.id] }, { include_blank: true }, class: 'form-control', placeholder: t(:choose) + = f.select :registrar_id_eq, registrar_options, { include_blank: true }, class: 'form-control', placeholder: t(:choose) .col-md-3 .form-group = f.label t(:created_at_from) diff --git a/app/views/admin/domain_versions/archive.haml b/app/views/admin/domain_versions/archive.haml index 1b80c59c76..46a4796896 100644 --- a/app/views/admin/domain_versions/archive.haml +++ b/app/views/admin/domain_versions/archive.haml @@ -15,7 +15,7 @@ .col-md-3 .form-group = label_tag t(:registrar_name) - = select_tag '[q][registrar]', options_for_select(Registrar.all.map { |r| [r.name] }, selected: params[:q][:registrar]), { include_blank: true, class: 'form-control', placeholder: t('.registrant')} + = select_tag '[q][registrar]', options_for_select(registrar_options(value: :name), selected: params[:q][:registrar]), { include_blank: true, class: 'form-control', placeholder: t('.registrant')} .col-md-3 .form-group = label_tag :action diff --git a/app/views/admin/domains/_search_form.html.erb b/app/views/admin/domains/_search_form.html.erb index 871f1364c4..18e22d12a0 100644 --- a/app/views/admin/domains/_search_form.html.erb +++ b/app/views/admin/domains/_search_form.html.erb @@ -29,7 +29,7 @@
<%= f.label :registrar_name, for: nil %> - <%= select_tag 'q[registrar_id_eq]', options_for_select(Registrar.all.map { |x| [x, x.id] }, params[:q][:registrar_id_eq]), { include_blank:true, class: 'form-control' } %> + <%= select_tag 'q[registrar_id_eq]', options_for_select(registrar_options, params[:q][:registrar_id_eq]), { include_blank:true, class: 'form-control' } %>
diff --git a/app/views/admin/epp_logs/index.haml b/app/views/admin/epp_logs/index.haml index 01e63dfcbc..b0b5b03bf8 100644 --- a/app/views/admin/epp_logs/index.haml +++ b/app/views/admin/epp_logs/index.haml @@ -27,7 +27,7 @@ .col-md-3 .form-group = f.label :registrar - = f.select :api_user_registrar_matches, Registrar.all.map { |x| [x, x.name] }, { include_blank: true }, class: 'form-control', placeholder: t(:choose) + = f.select :api_user_registrar_matches, registrar_options(value: :name), { include_blank: true }, class: 'form-control', placeholder: t(:choose) .col-md-3 .form-group = f.label t(:created_after) diff --git a/app/views/admin/invoices/new.haml b/app/views/admin/invoices/new.haml index f688cfe046..3d375b3793 100644 --- a/app/views/admin/invoices/new.haml +++ b/app/views/admin/invoices/new.haml @@ -12,7 +12,7 @@ .col-md-4.control-label = f.label :registrar_id, class: 'required' .col-md-8 - = select_tag 'deposit[registrar_id]', options_for_select(Registrar.all.map { |r| [r.name, r.id] }), { prompt: t(:choose), required: true, class: 'form-control js-combobox' } + = select_tag 'deposit[registrar_id]', options_for_select(registrar_options), { prompt: t(:choose), required: true, class: 'form-control js-combobox' } .form-group .col-md-4.control-label diff --git a/app/views/admin/invoices/partials/_search_form.html.erb b/app/views/admin/invoices/partials/_search_form.html.erb index 8dbbea00a6..760cbf8c48 100644 --- a/app/views/admin/invoices/partials/_search_form.html.erb +++ b/app/views/admin/invoices/partials/_search_form.html.erb @@ -36,7 +36,7 @@
<%= f.label "Registrar" %> - <%= f.select :buyer_id_in, Registrar.all.map { |x| [x, x.id] }, {}, class: 'form-control js-combobox', placeholder: t(:choose), multiple: true %> + <%= f.select :buyer_id_in, registrar_options, {}, class: 'form-control js-combobox', placeholder: t(:choose), multiple: true %>
diff --git a/app/views/admin/repp_logs/index.haml b/app/views/admin/repp_logs/index.haml index e90881645c..a3b6a22d1e 100644 --- a/app/views/admin/repp_logs/index.haml +++ b/app/views/admin/repp_logs/index.haml @@ -25,7 +25,7 @@ .col-md-3 .form-group = f.label :registrar - = f.select :api_user_registrar_matches, Registrar.all.map { |x| [x, x.name] }, { include_blank: true }, class: 'form-control', placeholder: t(:choose) + = f.select :api_user_registrar_matches, registrar_options(value: :name), { include_blank: true }, class: 'form-control', placeholder: t(:choose) .col-md-3 .form-group = f.label t(:created_after) diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 3edd614b42..3df9a61b3b 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -11,4 +11,16 @@ def test_creator_link ApplicationController.helpers.updator_link(model) end end + + def test_registrar_options_are_sorted_by_name + registrars(:bestnames).update_columns(name: 'Zulu Names') + registrars(:goodnames).update_columns(name: 'Alpha Names') + + options = registrar_options + names = options.map(&:first).reject(&:blank?) + + assert_equal names.sort, names + assert_equal 'Alpha Names', names.first + assert_equal registrars(:goodnames).id, options.find { |name, _id| name == 'Alpha Names' }.last + end end diff --git a/test/integration/admin_area/registrar_select_options_test.rb b/test/integration/admin_area/registrar_select_options_test.rb new file mode 100644 index 0000000000..96240d719f --- /dev/null +++ b/test/integration/admin_area/registrar_select_options_test.rb @@ -0,0 +1,77 @@ +require 'test_helper' + +class AdminAreaRegistrarSelectOptionsTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers + + setup do + sign_in users(:admin) + registrars(:bestnames).update_columns(name: 'Zulu Names') + registrars(:goodnames).update_columns(name: 'Alpha Names') + end + + def test_admin_domains_registrar_dropdown_is_sorted_alphabetically + get admin_domains_path + assert_response :success + assert_registrar_options_sorted '#q_registrar_id_eq' + end + + def test_admin_contacts_registrar_dropdown_is_sorted_alphabetically + get admin_contacts_path + assert_response :success + assert_registrar_options_sorted '#q_registrar_id_eq' + end + + def test_admin_invoices_registrar_dropdown_is_sorted_alphabetically + get admin_invoices_path + assert_response :success + assert_registrar_options_sorted '#q_buyer_id_in' + end + + def test_admin_new_invoice_registrar_dropdown_is_sorted_alphabetically + get new_admin_invoice_path + assert_response :success + assert_registrar_options_sorted '#deposit_registrar_id' + end + + def test_admin_accounts_registrar_dropdown_is_sorted_alphabetically + get admin_accounts_path + assert_response :success + assert_registrar_options_sorted '#q_registrar_id_in' + end + + def test_admin_account_activities_registrar_dropdown_is_sorted_alphabetically + get admin_account_activities_path, params: { created_after: 'today' } + assert_response :success + assert_registrar_options_sorted '#q_account_registrar_id_in' + end + + def test_admin_domain_versions_registrar_dropdown_is_sorted_alphabetically + get admin_domain_versions_path + assert_response :success + assert_registrar_options_sorted '#_q_registrar' + end + + def test_admin_epp_logs_registrar_dropdown_is_sorted_alphabetically + get admin_epp_logs_path + assert_response :success + assert_registrar_options_sorted '#q_api_user_registrar_matches' + end + + def test_admin_repp_logs_registrar_dropdown_is_sorted_alphabetically + get admin_repp_logs_path + assert_response :success + assert_registrar_options_sorted '#q_api_user_registrar_matches' + end + + private + + def assert_registrar_options_sorted(select_css) + expected = Registrar.ordered.map(&:name).reject(&:blank?) + names = css_select("#{select_css} option").map { |option| option.text.strip } + registrar_names = names.select { |name| expected.include?(name) } + + assert_equal expected, registrar_names + assert_equal 'Alpha Names', registrar_names.first + assert_equal 'Zulu Names', registrar_names.last + end +end diff --git a/test/models/registrar_test.rb b/test/models/registrar_test.rb index da9eeed9a4..4b14848356 100644 --- a/test/models/registrar_test.rb +++ b/test/models/registrar_test.rb @@ -310,6 +310,17 @@ def test_legal_doc_is_not_mandatory_globally Setting.legal_document_is_mandatory = old_value end + def test_ordered_returns_registrars_sorted_by_name + registrars(:bestnames).update_columns(name: 'Zulu Names') + registrars(:goodnames).update_columns(name: 'Alpha Names') + + ordered_names = Registrar.ordered.pluck(:name).reject(&:blank?) + + assert_equal ordered_names.sort, ordered_names + assert_equal 'Alpha Names', ordered_names.first + assert_equal 'Zulu Names', ordered_names.last + end + private def valid_registrar From d0948c6a836162044cd17d6499d651515490c8b1 Mon Sep 17 00:00:00 2001 From: mmeest Date: Thu, 27 Aug 2026 16:14:39 +0300 Subject: [PATCH 2/2] Tighten registrar dropdown tests with a shared assertion helper. Co-authored-by: Cursor --- .../registrar_select_options_test.rb | 47 +++++++------------ 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/test/integration/admin_area/registrar_select_options_test.rb b/test/integration/admin_area/registrar_select_options_test.rb index 96240d719f..d67f43090c 100644 --- a/test/integration/admin_area/registrar_select_options_test.rb +++ b/test/integration/admin_area/registrar_select_options_test.rb @@ -10,63 +10,52 @@ class AdminAreaRegistrarSelectOptionsTest < ActionDispatch::IntegrationTest end def test_admin_domains_registrar_dropdown_is_sorted_alphabetically - get admin_domains_path - assert_response :success - assert_registrar_options_sorted '#q_registrar_id_eq' + assert_registrar_dropdown_sorted admin_domains_path, '#q_registrar_id_eq' end def test_admin_contacts_registrar_dropdown_is_sorted_alphabetically - get admin_contacts_path - assert_response :success - assert_registrar_options_sorted '#q_registrar_id_eq' + assert_registrar_dropdown_sorted admin_contacts_path, '#q_registrar_id_eq' end def test_admin_invoices_registrar_dropdown_is_sorted_alphabetically - get admin_invoices_path - assert_response :success - assert_registrar_options_sorted '#q_buyer_id_in' + assert_registrar_dropdown_sorted admin_invoices_path, '#q_buyer_id_in' end def test_admin_new_invoice_registrar_dropdown_is_sorted_alphabetically - get new_admin_invoice_path - assert_response :success - assert_registrar_options_sorted '#deposit_registrar_id' + assert_registrar_dropdown_sorted new_admin_invoice_path, '#deposit_registrar_id' end def test_admin_accounts_registrar_dropdown_is_sorted_alphabetically - get admin_accounts_path - assert_response :success - assert_registrar_options_sorted '#q_registrar_id_in' + assert_registrar_dropdown_sorted admin_accounts_path, '#q_registrar_id_in' end def test_admin_account_activities_registrar_dropdown_is_sorted_alphabetically - get admin_account_activities_path, params: { created_after: 'today' } - assert_response :success - assert_registrar_options_sorted '#q_account_registrar_id_in' + assert_registrar_dropdown_sorted( + admin_account_activities_path, + '#q_account_registrar_id_in', + params: { created_after: 'today' } + ) end def test_admin_domain_versions_registrar_dropdown_is_sorted_alphabetically - get admin_domain_versions_path - assert_response :success - assert_registrar_options_sorted '#_q_registrar' + assert_registrar_dropdown_sorted admin_domain_versions_path, '#_q_registrar' end def test_admin_epp_logs_registrar_dropdown_is_sorted_alphabetically - get admin_epp_logs_path - assert_response :success - assert_registrar_options_sorted '#q_api_user_registrar_matches' + assert_registrar_dropdown_sorted admin_epp_logs_path, '#q_api_user_registrar_matches' end def test_admin_repp_logs_registrar_dropdown_is_sorted_alphabetically - get admin_repp_logs_path - assert_response :success - assert_registrar_options_sorted '#q_api_user_registrar_matches' + assert_registrar_dropdown_sorted admin_repp_logs_path, '#q_api_user_registrar_matches' end private - def assert_registrar_options_sorted(select_css) - expected = Registrar.ordered.map(&:name).reject(&:blank?) + def assert_registrar_dropdown_sorted(path, select_css, params: {}) + get path, params: params + assert_response :success + + expected = Registrar.ordered.filter_map { |registrar| registrar.name.presence } names = css_select("#{select_css} option").map { |option| option.text.strip } registrar_names = names.select { |name| expected.include?(name) }