Skip to content

Commit

Permalink
Improve request link formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
lizconlan committed Aug 23, 2018
1 parent 336b828 commit e0aa4b5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/controllers/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def hidden_user_explanation
locals: {
name_to: info_request.user_name.html_safe,
info_request: info_request, :reason => params[:reason],
info_request_url: 'http://' + AlaveteliConfiguration.domain + request_path(info_request),
info_request_url: request_link(request_path(info_request)),
site_name: site_name.html_safe }
end

Expand Down Expand Up @@ -115,4 +115,14 @@ def ask_the_eu_link
%q(<a href="http://asktheeu.org">Ask The EU</a>)
end

def request_link(request_path)
protocol =
if AlaveteliConfiguration.force_ssl
"https://"
else
"http://"
end
"#{protocol}#{AlaveteliConfiguration.domain}#{request_path}"
end

end
20 changes: 20 additions & 0 deletions spec/controllers/services_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@
expect(response.body).to match(/Yours,\n\nThe A&B Test team/)
end

describe 'constructing the request link' do

it 'uses http if force_ssl is false' do
allow(AlaveteliConfiguration).
to receive(:force_ssl).and_return(false)
get :hidden_user_explanation, info_request_id: info_request.id
expect(response.body).
to match "http://test.host/request/#{info_request.url_title}"
end

it 'uses https if force_ssl is true' do
allow(AlaveteliConfiguration).
to receive(:force_ssl).and_return(true)
get :hidden_user_explanation, info_request_id: info_request.id
expect(response.body).
to match "https://test.host/request/#{info_request.url_title}"
end

end

end

end

0 comments on commit e0aa4b5

Please sign in to comment.