From e1d0df918f8bd011d94ab8fd8bbe6682628e7297 Mon Sep 17 00:00:00 2001 From: Kevin Dew Date: Wed, 11 Dec 2024 17:11:12 +0000 Subject: [PATCH 1/3] Helper method for search_component We intend to use the conditional for which search component we use in two places now: the search results page and the search entry form. To facilitate this without requiring code to be copied I have moved the logic for this into a helper method. --- app/controllers/finders_controller.rb | 5 ----- app/helpers/application_helper.rb | 6 ++++++ .../finders/show_all_content_finder.html.erb | 2 +- spec/helpers/application_helper_spec.rb | 21 +++++++++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 spec/helpers/application_helper_spec.rb diff --git a/app/controllers/finders_controller.rb b/app/controllers/finders_controller.rb index 19ab425cc..d5c6f7554 100644 --- a/app/controllers/finders_controller.rb +++ b/app/controllers/finders_controller.rb @@ -58,7 +58,6 @@ def show_page_variables @sort_presenter = sort_presenter @pagination = pagination_presenter @spelling_suggestion_presenter = spelling_suggestion_presenter - @search_component = use_autocomplete? ? "search_with_autocomplete" : "search" end private @@ -387,8 +386,4 @@ def filter_query_array(arr) arr.reject { |v| v == "all" }.compact.presence end end - - def use_autocomplete? - true unless ENV["GOVUK_DISABLE_SEARCH_AUTOCOMPLETE"] - end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 09d85d0b1..d7ee19b4e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,4 +2,10 @@ module ApplicationHelper def absolute_url_for(path) URI.join(Plek.new.website_root, path) end + + def search_component + use_autocomplete = true unless ENV["GOVUK_DISABLE_SEARCH_AUTOCOMPLETE"] + + use_autocomplete ? "search_with_autocomplete" : "search" + end end diff --git a/app/views/finders/show_all_content_finder.html.erb b/app/views/finders/show_all_content_finder.html.erb index b0a8a6e63..beec63ad2 100644 --- a/app/views/finders/show_all_content_finder.html.erb +++ b/app/views/finders/show_all_content_finder.html.erb @@ -53,7 +53,7 @@