From 19c107961a4cb372cca49fd3300ea2698a9546f6 Mon Sep 17 00:00:00 2001 From: Matt Rayner Date: Mon, 1 Oct 2018 12:33:31 +0100 Subject: [PATCH] [HOTFIX] Add search_action to SearchFormComponents serialiser --- .../search_form_component_serializer.rb | 5 ++++- .../header_components_partial_serializer.rb | 2 +- .../controllers/home_controller/index/fixture.yml | 1 + .../index/fixture.yml | 1 + .../show/fixture.yml | 1 + .../statutory_instruments_controller/index/fixture.yml | 1 + .../statutory_instruments_controller/show/fixture.yml | 1 + .../with_search_action.yml | 8 ++++++++ .../page_serializer/home_page_serializer/fixture.yml | 1 + .../laid_thing_show_page_serializer/fixture.yml | 1 + .../laid_thing_missing_data.yml | 1 + .../fixture.yml | 1 + .../fixture.yml | 1 + .../si_missing_data.yml | 1 + .../fixture.yml | 1 + .../fixture.yml | 1 + .../si_missing_data.yml | 1 + .../header_components_partial_serializer/fixture.yml | 1 + .../search_form_component_serializer_spec.rb | 9 +++++++++ 19 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/serializers/component_serializer/search_form_component_serializer/with_search_action.yml diff --git a/app/serializers/component_serializer/search_form_component_serializer.rb b/app/serializers/component_serializer/search_form_component_serializer.rb index de97bad1..28d1ca39 100644 --- a/app/serializers/component_serializer/search_form_component_serializer.rb +++ b/app/serializers/component_serializer/search_form_component_serializer.rb @@ -5,16 +5,18 @@ class SearchFormComponentSerializer < ComponentSerializer::BaseComponentSerializ # @param [String] query string to passed in as the value attribute of the input element. # @param [Array] components components that are intended to be part of the search form. # @param [Boolean] global a boolean to determine if the global tags are added in te dust file. + # @param [String] search_action a path which is used as the action parameter on the search form. # # @example Initialising a search form component # query_nil_unless_rendering_results_page = nil # an_icon_componet = ComponentSerializer::SearchIconComponentSerializer.new().to_h # nil_unless_search_used_in_header = nil # ComponentSerializer::SearchFormComponentSerializer.new(query: query_nil_unless_rendering_results_page, components: [an_icon_componet], global: nil_unless_search_used_in_header).to_h - def initialize(query: nil, components: nil, global: nil) + def initialize(query: nil, components: nil, global: nil, search_action: nil) @query = query @components = components @global = global + @search_action = search_action end private @@ -29,6 +31,7 @@ def data hash[:global] = @global if @global hash[:label] = 'search.label' hash[:components] = @components + hash['search-action'] = @search_action if @search_action end end end diff --git a/app/serializers/partial_serializer/header_components_partial_serializer.rb b/app/serializers/partial_serializer/header_components_partial_serializer.rb index bcd634ff..ad9b24fb 100644 --- a/app/serializers/partial_serializer/header_components_partial_serializer.rb +++ b/app/serializers/partial_serializer/header_components_partial_serializer.rb @@ -73,7 +73,7 @@ def header_link end def header_search - ComponentSerializer::SearchFormComponentSerializer.new(components: [ComponentSerializer::SearchIconComponentSerializer.new.to_h], global: true).to_h + ComponentSerializer::SearchFormComponentSerializer.new(components: [ComponentSerializer::SearchIconComponentSerializer.new.to_h], global: true, search_action: search_path).to_h end def header_display_data diff --git a/spec/fixtures/controllers/home_controller/index/fixture.yml b/spec/fixtures/controllers/home_controller/index/fixture.yml index 6da798ea..74223441 100644 --- a/spec/fixtures/controllers/home_controller/index/fixture.yml +++ b/spec/fixtures/controllers/home_controller/index/fixture.yml @@ -62,6 +62,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: - name: hero data: diff --git a/spec/fixtures/controllers/proposed_negative_statutory_instruments_controller/index/fixture.yml b/spec/fixtures/controllers/proposed_negative_statutory_instruments_controller/index/fixture.yml index 32806686..eda9a8e5 100644 --- a/spec/fixtures/controllers/proposed_negative_statutory_instruments_controller/index/fixture.yml +++ b/spec/fixtures/controllers/proposed_negative_statutory_instruments_controller/index/fixture.yml @@ -85,6 +85,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: - name: section__primary data: diff --git a/spec/fixtures/controllers/proposed_negative_statutory_instruments_controller/show/fixture.yml b/spec/fixtures/controllers/proposed_negative_statutory_instruments_controller/show/fixture.yml index 922246f6..bbb79d12 100644 --- a/spec/fixtures/controllers/proposed_negative_statutory_instruments_controller/show/fixture.yml +++ b/spec/fixtures/controllers/proposed_negative_statutory_instruments_controller/show/fixture.yml @@ -85,6 +85,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: - name: section__primary data: diff --git a/spec/fixtures/controllers/statutory_instruments_controller/index/fixture.yml b/spec/fixtures/controllers/statutory_instruments_controller/index/fixture.yml index df38ed87..dfec27ac 100644 --- a/spec/fixtures/controllers/statutory_instruments_controller/index/fixture.yml +++ b/spec/fixtures/controllers/statutory_instruments_controller/index/fixture.yml @@ -85,6 +85,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: - name: section__primary data: diff --git a/spec/fixtures/controllers/statutory_instruments_controller/show/fixture.yml b/spec/fixtures/controllers/statutory_instruments_controller/show/fixture.yml index 6ba347d6..f107aa7d 100644 --- a/spec/fixtures/controllers/statutory_instruments_controller/show/fixture.yml +++ b/spec/fixtures/controllers/statutory_instruments_controller/show/fixture.yml @@ -85,6 +85,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: - name: section__primary data: diff --git a/spec/fixtures/serializers/component_serializer/search_form_component_serializer/with_search_action.yml b/spec/fixtures/serializers/component_serializer/search_form_component_serializer/with_search_action.yml new file mode 100644 index 00000000..bf4f8b01 --- /dev/null +++ b/spec/fixtures/serializers/component_serializer/search_form_component_serializer/with_search_action.yml @@ -0,0 +1,8 @@ +--- +name: form__search +data: + value: query + label: search.label + components: + - 1 + search-action: "/foo/search" diff --git a/spec/fixtures/serializers/page_serializer/home_page_serializer/fixture.yml b/spec/fixtures/serializers/page_serializer/home_page_serializer/fixture.yml index 6da798ea..74223441 100644 --- a/spec/fixtures/serializers/page_serializer/home_page_serializer/fixture.yml +++ b/spec/fixtures/serializers/page_serializer/home_page_serializer/fixture.yml @@ -62,6 +62,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: - name: hero data: diff --git a/spec/fixtures/serializers/page_serializer/laid_thing_show_page_serializer/fixture.yml b/spec/fixtures/serializers/page_serializer/laid_thing_show_page_serializer/fixture.yml index 3765cd7a..02a9a81d 100644 --- a/spec/fixtures/serializers/page_serializer/laid_thing_show_page_serializer/fixture.yml +++ b/spec/fixtures/serializers/page_serializer/laid_thing_show_page_serializer/fixture.yml @@ -70,6 +70,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: footer-components: - name: footer diff --git a/spec/fixtures/serializers/page_serializer/laid_thing_show_page_serializer/laid_thing_missing_data.yml b/spec/fixtures/serializers/page_serializer/laid_thing_show_page_serializer/laid_thing_missing_data.yml index 3765cd7a..02a9a81d 100644 --- a/spec/fixtures/serializers/page_serializer/laid_thing_show_page_serializer/laid_thing_missing_data.yml +++ b/spec/fixtures/serializers/page_serializer/laid_thing_show_page_serializer/laid_thing_missing_data.yml @@ -70,6 +70,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: footer-components: - name: footer diff --git a/spec/fixtures/serializers/page_serializer/proposed_negative_statutory_instruments_index_page_serializer/fixture.yml b/spec/fixtures/serializers/page_serializer/proposed_negative_statutory_instruments_index_page_serializer/fixture.yml index 84c24977..b749f3ec 100644 --- a/spec/fixtures/serializers/page_serializer/proposed_negative_statutory_instruments_index_page_serializer/fixture.yml +++ b/spec/fixtures/serializers/page_serializer/proposed_negative_statutory_instruments_index_page_serializer/fixture.yml @@ -70,6 +70,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: - name: section__primary data: diff --git a/spec/fixtures/serializers/page_serializer/proposed_negative_statutory_instruments_show_page_serializer/fixture.yml b/spec/fixtures/serializers/page_serializer/proposed_negative_statutory_instruments_show_page_serializer/fixture.yml index c49a8557..c90fa363 100644 --- a/spec/fixtures/serializers/page_serializer/proposed_negative_statutory_instruments_show_page_serializer/fixture.yml +++ b/spec/fixtures/serializers/page_serializer/proposed_negative_statutory_instruments_show_page_serializer/fixture.yml @@ -70,6 +70,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: - name: section__primary data: diff --git a/spec/fixtures/serializers/page_serializer/proposed_negative_statutory_instruments_show_page_serializer/si_missing_data.yml b/spec/fixtures/serializers/page_serializer/proposed_negative_statutory_instruments_show_page_serializer/si_missing_data.yml index f765536e..dcee11af 100644 --- a/spec/fixtures/serializers/page_serializer/proposed_negative_statutory_instruments_show_page_serializer/si_missing_data.yml +++ b/spec/fixtures/serializers/page_serializer/proposed_negative_statutory_instruments_show_page_serializer/si_missing_data.yml @@ -70,6 +70,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: - name: section__primary data: diff --git a/spec/fixtures/serializers/page_serializer/statutory_instruments_index_page_serializer/fixture.yml b/spec/fixtures/serializers/page_serializer/statutory_instruments_index_page_serializer/fixture.yml index be704331..bba82bbd 100644 --- a/spec/fixtures/serializers/page_serializer/statutory_instruments_index_page_serializer/fixture.yml +++ b/spec/fixtures/serializers/page_serializer/statutory_instruments_index_page_serializer/fixture.yml @@ -70,6 +70,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: - name: section__primary data: diff --git a/spec/fixtures/serializers/page_serializer/statutory_instruments_show_page_serializer/fixture.yml b/spec/fixtures/serializers/page_serializer/statutory_instruments_show_page_serializer/fixture.yml index 9ce5d1b8..e143e544 100644 --- a/spec/fixtures/serializers/page_serializer/statutory_instruments_show_page_serializer/fixture.yml +++ b/spec/fixtures/serializers/page_serializer/statutory_instruments_show_page_serializer/fixture.yml @@ -70,6 +70,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: - name: section__primary data: diff --git a/spec/fixtures/serializers/page_serializer/statutory_instruments_show_page_serializer/si_missing_data.yml b/spec/fixtures/serializers/page_serializer/statutory_instruments_show_page_serializer/si_missing_data.yml index e7c304bf..412577ce 100644 --- a/spec/fixtures/serializers/page_serializer/statutory_instruments_show_page_serializer/si_missing_data.yml +++ b/spec/fixtures/serializers/page_serializer/statutory_instruments_show_page_serializer/si_missing_data.yml @@ -70,6 +70,7 @@ header-components: components: - name: icon__search data: search.search-icon + search-action: "/search" main-components: - name: section__primary data: diff --git a/spec/fixtures/serializers/partial_serializer/header_components_partial_serializer/fixture.yml b/spec/fixtures/serializers/partial_serializer/header_components_partial_serializer/fixture.yml index 39e1937a..9f07860d 100644 --- a/spec/fixtures/serializers/partial_serializer/header_components_partial_serializer/fixture.yml +++ b/spec/fixtures/serializers/partial_serializer/header_components_partial_serializer/fixture.yml @@ -57,3 +57,4 @@ components: - name: icon__search data: search.search-icon + search-action: "/search" diff --git a/spec/serializers/component_serializer/search_form_component_serializer_spec.rb b/spec/serializers/component_serializer/search_form_component_serializer_spec.rb index 910e361d..98e94749 100644 --- a/spec/serializers/component_serializer/search_form_component_serializer_spec.rb +++ b/spec/serializers/component_serializer/search_form_component_serializer_spec.rb @@ -26,5 +26,14 @@ expect(serializer.to_yaml).to eq expected end + context 'with a search_action passed' do + it 'returns the expected JSON' do + serializer = described_class.new(query: 'query', components: [1], search_action: '/foo/search') + + expected = get_fixture('with_search_action') + + expect(serializer.to_yaml).to eq expected + end + end end end