Skip to content

Commit

Permalink
Merge pull request #70 from mattrayner/master
Browse files Browse the repository at this point in the history
[HOTFIX] Add search_action to SearchFormComponents serialiser
  • Loading branch information
Christine-horrocks committed Oct 1, 2018
2 parents 242bd5b + 19c1079 commit e6e5cb6
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object>] 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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: hero
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: section__primary
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: section__primary
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: section__primary
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: section__primary
data:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: form__search
data:
value: query
label: search.label
components:
- 1
search-action: "/foo/search"
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: hero
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
footer-components:
- name: footer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
footer-components:
- name: footer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: section__primary
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: section__primary
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: section__primary
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: section__primary
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: section__primary
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ header-components:
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: section__primary
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e6e5cb6

Please sign in to comment.