Skip to content

Commit

Permalink
Merge pull request #4855 from alphagov/redirect-announcements-atom-feed
Browse files Browse the repository at this point in the history
Adds a redirect for announcements atom feed
  • Loading branch information
SamJamCul committed Jun 18, 2019
2 parents 638f1fe + 086c52a commit 59457dd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 51 deletions.
6 changes: 4 additions & 2 deletions app/controllers/announcements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def index
)
end
format.atom do
return redirect_to_news_and_communications(".atom") if is_english_locale?

@announcements = @filter.documents
end
end
Expand All @@ -43,8 +45,8 @@ def is_english_locale?
params[:locale].nil?
end

def redirect_to_news_and_communications
base_path = "#{Plek.new.website_root}/search/news-and-communications"
def redirect_to_news_and_communications(format = "")
base_path = "#{Plek.new.website_root}/search/news-and-communications#{format}"
redirect_to("#{base_path}?#{news_and_communications_query_string}")
end

Expand Down
78 changes: 29 additions & 49 deletions test/functional/announcements_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,35 @@ class AnnouncementsControllerTest < ActionController::TestCase
end
end

test "when locale is english it redirects and atom feed with params for finder-frontend" do
with_stubbed_rummager(@rummager, true) do
@rummager.expects(:search).returns('results' => [])

get :index, params: {
keywords: "one two",
taxons: %w[one],
subtaxons: %w[two],
people: %w[one two],
departments: %w[one two],
world_locations: %w[one two],
from_date: '01/01/2014',
to_date: '01/01/2014'
}, format: :atom

redirect_params_query = {
keywords: "one two",
level_one_taxon: 'one',
level_two_taxon: 'two',
people: %w[one two],
organisations: %w[one two],
world_locations: %w[one two],
public_timestamp: { from: '01/01/2014', to: '01/01/2014' }
}.to_query

assert_redirected_to "#{Plek.new.website_root}/search/news-and-communications.atom?#{redirect_params_query}"
end
end

view_test "index with locale shows a mix of news and speeches" do
news = create(:published_news_article, translated_into: [:fr])
speech = create(:published_speech, translated_into: [:fr])
Expand Down Expand Up @@ -231,55 +260,6 @@ def refute_select(hash)
end
end

view_test "index generates an atom feed with entries for announcements matching the current filter" do
with_stubbed_rummager(@rummager, true) do
location = create(:world_location, name: "beetlejuice")
create(:published_news_story, world_locations: [location], first_published_at: 1.week.ago)

@rummager.expects(:search).returns(search_results_from_rummager)

processed_rummager_documents = search_results_from_rummager['results'].map do |result|
RummagerDocumentPresenter.new(result)
end

get :index, params: { world_locations: [location.to_param] }, format: :atom

assert_select_atom_feed do
assert_select_atom_entries(processed_rummager_documents, false)
end
end
end

view_test "index generates an atom feed with the legacy announcement_type_option param set" do
with_stubbed_rummager(@rummager, true) do
create(:published_news_story, first_published_at: 1.week.ago)

@rummager.expects(:search).returns(search_results_from_rummager)

processed_rummager_documents = search_results_from_rummager['results'].map do |result|
RummagerDocumentPresenter.new(result)
end

get :index, params: { announcement_type_option: 'news-stories' }, format: :atom

assert_select_atom_feed do
assert_select_atom_entries(processed_rummager_documents, false)
end
end
end

view_test 'index atom feed should return a valid feed if there are no matching documents' do
with_stubbed_rummager(@rummager, true) do
@rummager.expects(:search).returns('results' => [])
get :index, format: :atom

assert_select_atom_feed do
assert_select 'feed > updated', text: Time.zone.now.iso8601
assert_select 'feed > entry', count: 0
end
end
end

view_test "index requested as JSON includes email signup path with organisation and topic parameters" do
with_stubbed_rummager(@rummager, true) do
@rummager.expects(:search).returns('results' => [])
Expand Down

0 comments on commit 59457dd

Please sign in to comment.