-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1400 from alphagov/related-links-header-response
Use request header for related links to determine response header
- Loading branch information
Showing
5 changed files
with
55 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module RequestHelper | ||
def self.get_header(header_name, request_headers) | ||
request_headers[headerise(header_name)] | ||
end | ||
|
||
def self.headerise(header_name) | ||
"HTTP_#{header_name.upcase.tr('-', '_')}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'test_helper' | ||
|
||
class RequestHelperTest < ActiveSupport::TestCase | ||
test 'get_header returns nil when header does not exist' do | ||
header_val = RequestHelper.get_header('Govuk-Example-Header', {}) | ||
|
||
assert_equal nil, header_val | ||
end | ||
|
||
test 'get_header returns header when header exists' do | ||
header_val = RequestHelper.get_header('Govuk-Example-Header', 'HTTP_GOVUK_EXAMPLE_HEADER' => 'this_is_a_test') | ||
|
||
assert_equal 'this_is_a_test', header_val | ||
end | ||
|
||
test 'headerise returns header with HTTP prefix, no dashes and all uppercase' do | ||
header_name = 'Govuk-Example-Header' | ||
|
||
transformed_header_name = RequestHelper.headerise(header_name) | ||
|
||
assert_equal 'HTTP_GOVUK_EXAMPLE_HEADER', transformed_header_name | ||
end | ||
end |