Skip to content

Commit

Permalink
Update controller to atom feeds
Browse files Browse the repository at this point in the history
The atom tests have been removed completely as no other format renders
and atom feed.

Also updates the controller tests to remove travel advice examples
  • Loading branch information
leenagupte committed Nov 18, 2024
1 parent 993357a commit d26026a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 56 deletions.
6 changes: 0 additions & 6 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def show
elsif is_history_page?
show_history_page
else
set_access_control_allow_origin_header if request.format.atom?
set_guide_draft_access_token if @content_item.is_a?(GuidePresenter)
render_template
end
Expand Down Expand Up @@ -191,18 +190,13 @@ def render_template

respond_to do |format|
format.html
format.atom
end

with_locale do
render content_item_template
end
end

def set_access_control_allow_origin_header
response.headers["Access-Control-Allow-Origin"] = "*"
end

def set_expiry
expires_in(
@content_item.cache_control_max_age(request.format),
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

get "*path(.:locale)(.:format)" => "content_items#show",
constraints: {
format: /atom/,
locale: /\w{2}(-[\d\w]{2,3})?/,
}

Expand Down
54 changes: 5 additions & 49 deletions test/controllers/content_items_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,6 @@ class ContentItemsControllerTest < ActionController::TestCase
end
end

test "routing handles paths with just format" do
assert_routing(
"/government/news/statement-the-status-of-eu-nationals-in-the-uk.atom",
controller: "content_items",
action: "show",
path: "government/news/statement-the-status-of-eu-nationals-in-the-uk",
format: "atom",
)
end

test "routing handles paths with format and locale" do
assert_routing(
"/government/news/statement-the-status-of-eu-nationals-in-the-uk.es.atom",
controller: "content_items",
action: "show",
path: "government/news/statement-the-status-of-eu-nationals-in-the-uk",
format: "atom",
locale: "es",
)
end

test "routing handles paths with print variant" do
assert_routing(
"/government/news/statement-the-status-of-eu-nationals-in-the-uk/print",
Expand All @@ -57,7 +36,7 @@ class ContentItemsControllerTest < ActionController::TestCase
end

test "redirects route with invalid parts to base path" do
content_item = content_store_has_schema_example("travel_advice", "full-country")
content_item = content_store_has_schema_example("guide", "guide")
invalid_part_path = "#{path_for(content_item)}/not-a-valid-part"

# The content store performs a 301 to the base path when requesting a content item
Expand Down Expand Up @@ -88,7 +67,7 @@ class ContentItemsControllerTest < ActionController::TestCase

test "returns HTML when an unspecific accepts header is requested (eg by IE8 and below)" do
request.headers["Accept"] = "*/*"
content_item = content_store_has_schema_example("travel_advice", "full-country")
content_item = content_store_has_schema_example("guide", "guide")

get :show,
params: {
Expand Down Expand Up @@ -172,14 +151,6 @@ class ContentItemsControllerTest < ActionController::TestCase
assert_equal "max-age=20, public", @response.headers["Cache-Control"]
end

test "sets a longer cache-control header for travel advice atom feeds" do
content_item = content_store_has_schema_example("travel_advice", "full-country")
get :show, params: { path: path_for(content_item), format: "atom" }

assert_response :success
assert_equal "max-age=300, public", @response.headers["Cache-Control"]
end

test "honours cache-control private items" do
content_item = content_store_has_schema_example("case_study", "case_study")
stub_content_store_has_item(content_item["base_path"], content_item, private: true)
Expand All @@ -200,21 +171,13 @@ class ContentItemsControllerTest < ActionController::TestCase
assert_select "title", %r{#{translated_schema_name}}
end

test "renders atom feeds" do
content_item = content_store_has_schema_example("travel_advice", "full-country")
get :show, params: { path: path_for(content_item), format: "atom" }

assert_response :success
assert_select "feed title", "Travel Advice Summary"
end

test "renders print variants" do
content_item = content_store_has_schema_example("travel_advice", "full-country")
content_item = content_store_has_schema_example("guide", "guide")
get :show, params: { path: path_for(content_item), variant: "print" }

assert_response :success
assert_equal request.variant, [:print]
assert_select "#travel-advice-print"
assert_select "#guide-print"
end

test "gets item from content store even when url contains multi-byte UTF8 character" do
Expand All @@ -229,7 +192,7 @@ class ContentItemsControllerTest < ActionController::TestCase
end

test "returns 404 for invalid url" do
path = "foreign-travel-advice/egypt]"
path = "government/case-studies/electric-cars]"

stub_content_store_does_not_have_item("/#{path}")

Expand Down Expand Up @@ -296,13 +259,6 @@ class ContentItemsControllerTest < ActionController::TestCase
assert_redirected_to "https://www.test.gov.uk/new-406-beacons-destination/to-preserve"
end

test "sets the Access-Control-Allow-Origin header for atom pages" do
content_store_has_schema_example("travel_advice", "full-country")
get :show, params: { path: "foreign-travel-advice/albania", format: "atom" }

assert_equal response.headers["Access-Control-Allow-Origin"], "*"
end

test "sets GOVUK-Account-Session-Flash in the Vary header" do
content_item = content_store_has_schema_example("case_study", "case_study")
get :show, params: { path: path_for(content_item) }
Expand Down

0 comments on commit d26026a

Please sign in to comment.