Permalink
Browse files

Fix public_supporting_page_url to use the policy's slug instead of it…

…s ID

Also fix some tests that were asserting this broken behaviour.
  • Loading branch information...
1 parent 33a3b4c commit dbcbf31978deb08c348172ded7f199b80c1db216 @tomstuart tomstuart committed Jan 30, 2012
@@ -13,11 +13,17 @@ def public_document_url(document, options={})
end
end
- def public_supporting_page_url(document, supporting_document, options={})
+ def public_supporting_page_path(document, supporting_page, options = {})
+ options.merge!(model_name(document).foreign_key => document.document_identity)
+ polymorphic_path([model_name(document), supporting_page], options)
+ end
+
+ def public_supporting_page_url(document, supporting_page, options={})
+ options.merge!(model_name(document).foreign_key => document.document_identity)
if host = Whitehall.public_host_for(request.host)
- policy_supporting_page_url(document, supporting_document, options.merge(host: host))
+ polymorphic_url([model_name(document), supporting_page], options.merge(host: host))
else
- policy_supporting_page_path(document, supporting_document, options)
+ public_supporting_page_path(document, supporting_page, options)
end
end
@@ -156,7 +156,7 @@ class GovspeakHelperTest < ActionView::TestCase
policy = create(:published_policy)
supporting_page = create(:supporting_page, document: policy)
html = govspeak_to_html("this and [that](#{admin_supporting_page_url(supporting_page)}) yeah?")
- assert_govspeak %{<p>this and <a href="#{policy_supporting_page_path(policy, supporting_page)}">that</a> yeah?</p>}, html
+ assert_govspeak %{<p>this and <a href="#{public_supporting_page_path(policy, supporting_page)}">that</a> yeah?</p>}, html
end
test 'should rewrite admin link to an archived document with a published edition' do
@@ -195,7 +195,7 @@ class GovspeakHelperTest < ActionView::TestCase
policy = create(:published_policy)
supporting_page = create(:supporting_page, document: policy)
html = govspeak_to_html("this and [that](#{admin_supporting_page_url(supporting_page)}) yeah?")
- assert_govspeak %{<p>this and <a href="#{policy_supporting_page_url(policy, supporting_page, host: "www.preview.alphagov.co.uk")}">that</a> yeah?</p>}, html
+ assert_govspeak %{<p>this and <a href="#{public_supporting_page_url(policy, supporting_page, host: "www.preview.alphagov.co.uk")}">that</a> yeah?</p>}, html
end
test "should rewrite absolute links to admin previews of Speeches as their public document identity on production" do
@@ -211,7 +211,7 @@ class GovspeakHelperTest < ActionView::TestCase
policy = create(:published_policy)
supporting_page = create(:supporting_page, document: policy)
html = govspeak_to_html("this and [that](#{admin_supporting_page_url(supporting_page)}) yeah?")
- assert_govspeak %{<p>this and <a href="#{policy_supporting_page_url(policy, supporting_page, host: "www.gov.uk")}">that</a> yeah?</p>}, html
+ assert_govspeak %{<p>this and <a href="#{public_supporting_page_url(policy, supporting_page, host: "www.gov.uk")}">that</a> yeah?</p>}, html
end
test "should not link to SupportingPages whose documents are not published" do
@@ -42,6 +42,12 @@ class PublicDocumentRoutesHelperTest < ActionView::TestCase
assert_equal consultation_response_path(consultation_response.consultation.document_identity), public_document_path(consultation_response)
end
+ test 'uses the document identity to generate the supporting page route' do
+ policy = create(:policy)
+ supporting_page = create(:supporting_page, document: policy)
+ assert_equal policy_supporting_page_path(policy.document_identity, supporting_page), public_supporting_page_path(policy, supporting_page)
+ end
+
test 'returns public document URL including host in production environment' do
request.host = "whitehall.production.alphagov.co.uk"
document = create(:published_policy)

0 comments on commit dbcbf31

Please sign in to comment.