From bed106bd7f6f641b74c908e76678337132ff7642 Mon Sep 17 00:00:00 2001 From: farahTW Date: Wed, 11 Oct 2023 12:19:28 +0100 Subject: [PATCH] Removed keyword slug from search via title. --- ...ection_group_document_search_controller.rb | 4 +-- ...slug.html.erb => search_by_title.html.erb} | 0 .../search_options.html.erb | 2 +- config/routes.rb | 2 +- ...n_group_document_search_controller_test.rb | 36 +++++++++---------- ...n_group_document_search_controller_test.rb | 4 +-- 6 files changed, 24 insertions(+), 24 deletions(-) rename app/views/admin/document_collection_group_document_search/{search_title_slug.html.erb => search_by_title.html.erb} (100%) diff --git a/app/controllers/admin/document_collection_group_document_search_controller.rb b/app/controllers/admin/document_collection_group_document_search_controller.rb index 1778c9596386..fd35347f6f8c 100644 --- a/app/controllers/admin/document_collection_group_document_search_controller.rb +++ b/app/controllers/admin/document_collection_group_document_search_controller.rb @@ -11,10 +11,10 @@ def search flash.now[:alert] = "Please select a search option" render :search_options end - redirect_to(action: :search_title_slug, document_collection_id: @collection, group_id: @group) if params[:search_option] == "title-or-slug" + redirect_to(action: :search_by_title, document_collection_id: @collection, group_id: @group) if params[:search_option] == "title" end - def search_title_slug + def search_by_title flash.now[:alert] = "Please enter a search query" if params[:title] && params[:title].empty? if params[:title].present? filter diff --git a/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb b/app/views/admin/document_collection_group_document_search/search_by_title.html.erb similarity index 100% rename from app/views/admin/document_collection_group_document_search/search_title_slug.html.erb rename to app/views/admin/document_collection_group_document_search/search_by_title.html.erb diff --git a/app/views/admin/document_collection_group_document_search/search_options.html.erb b/app/views/admin/document_collection_group_document_search/search_options.html.erb index f28c6a9e4998..9309b095e8a6 100644 --- a/app/views/admin/document_collection_group_document_search/search_options.html.erb +++ b/app/views/admin/document_collection_group_document_search/search_options.html.erb @@ -15,7 +15,7 @@ text: "Search via URL", }, { - value: "title-or-slug", + value: "title", text: "Search via title", }, ] diff --git a/config/routes.rb b/config/routes.rb index b9561830fd86..236301de4c14 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -34,7 +34,7 @@ def redirect(path, options = { prefix: Whitehall.router_prefix }) resources :document_collection_groups, as: :groups, path: "groups" do get :search_options, to: "document_collection_group_document_search#search_options" post :search_options, to: "document_collection_group_document_search#search" - get :search_title_slug, to: "document_collection_group_document_search#search_title_slug" + get :search_by_title, to: "document_collection_group_document_search#search_by_title" member { get :confirm_destroy } resource :document_collection_group_membership, as: :members, path: "members", only: [:destroy] resources :document_collection_group_memberships, path: "members", only: %i[index destroy] do diff --git a/test/functional/admin/document_collection_group_document_search_controller_test.rb b/test/functional/admin/document_collection_group_document_search_controller_test.rb index 8bf99c0ec4a5..853ce182f7aa 100644 --- a/test/functional/admin/document_collection_group_document_search_controller_test.rb +++ b/test/functional/admin/document_collection_group_document_search_controller_test.rb @@ -38,46 +38,46 @@ class Admin::DocumentCollectionGroupDocumentSearchControllerTest < ActionControl assert_template nil end - test "POST #search redirects to #search_title_slug if search option passed is title-or-slug" do - @request_params[:search_option] = "title-or-slug" + test "POST #search redirects to #search_by_title if search option passed is title" do + @request_params[:search_option] = "title" post :search, params: @request_params - assert_redirected_to admin_document_collection_group_search_title_slug_path(@collection, @group) + assert_redirected_to admin_document_collection_group_search_by_title_path(@collection, @group) end - test "GET #search_title_slug without query renders search for title & slug page with no results section" do - get :search_title_slug, params: @request_params - assert_template "document_collection_group_document_search/search_title_slug" + test "GET #search_by_title without query renders search for title page with no results section" do + get :search_by_title, params: @request_params + assert_template "document_collection_group_document_search/search_by_title" assert_select ".app-view-document-collection-document-search-results", count: 0 end - test "GET :search_title_slug with search value passes title and default params to filter" do + test "GET :search_by_title with search value passes title and default params to filter" do edition_scope = Edition.with_translations(I18n.locale) default_filter_params_with_title = @default_filter_params.merge(title: "Something") Admin::EditionFilter.expects(:new).with(edition_scope, @user, default_filter_params_with_title) @request_params[:title] = "Something" - get :search_title_slug, params: @request_params - assert_template "document_collection_group_document_search/search_title_slug" + get :search_by_title, params: @request_params + assert_template "document_collection_group_document_search/search_by_title" end - view_test "GET #search_title_slug with a query that returns no results renders empty results list" do + view_test "GET #search_by_title with a query that returns no results renders empty results list" do editions = [] stub_filter = stub_edition_filter({ editions:, options: { per_page: 15 } }) Admin::EditionFilter.stubs(:new).returns(stub_filter) @request_params[:title] = "Something " - get :search_title_slug, params: @request_params - assert_template "document_collection_group_document_search/search_title_slug" + get :search_by_title, params: @request_params + assert_template "document_collection_group_document_search/search_by_title" assert_select ".govuk-body", text: /No results found. Search again using the full URL./ end - view_test "GET #search_title_slug with an empty query string shows an alert flash" do + view_test "GET #search_by_title with an empty query string shows an alert flash" do @request_params[:title] = "" - get :search_title_slug, params: @request_params - assert_template "document_collection_group_document_search/search_title_slug" + get :search_by_title, params: @request_params + assert_template "document_collection_group_document_search/search_by_title" assert_select ".gem-c-error-alert__message", text: /Please enter a search query/ end - view_test "GET :search_title with search value renders paginated results" do + view_test "GET :search_by_title with search value renders paginated results" do editions = [] edition = build(:news_article, title: "Something", document: build(:document, slug: "something")) 16.times { editions << edition } @@ -86,9 +86,9 @@ class Admin::DocumentCollectionGroupDocumentSearchControllerTest < ActionControl Admin::EditionFilter.stubs(:new).returns(stub_filter) @request_params[:title] = "Something " - get :search_title_slug, params: @request_params + get :search_by_title, params: @request_params assert_response :success - assert_template "document_collection_group_document_search/search_title_slug" + assert_template "document_collection_group_document_search/search_by_title" assert_select "input[name='title']" assert_select ".govuk-heading-s", "16 documents" assert_select ".govuk-table" do diff --git a/test/functional/admin/legacy_document_collection_group_document_search_controller_test.rb b/test/functional/admin/legacy_document_collection_group_document_search_controller_test.rb index 29fab6a5e978..fd289c53a561 100644 --- a/test/functional/admin/legacy_document_collection_group_document_search_controller_test.rb +++ b/test/functional/admin/legacy_document_collection_group_document_search_controller_test.rb @@ -20,8 +20,8 @@ class Admin::LegacyDocumentCollectionGroupDocumentSearchControllerTest < ActionC assert_template :forbidden end - test "GET #search_title_slug blocks out users with no permissions" do - get :search_title_slug, params: @request_params + test "GET #search_title blocks out users with no permissions" do + get :search_title, params: @request_params assert_template :forbidden end end