Skip to content
Permalink
Browse files

Show the 10 most recent documents in the home page atom feed.

Re-applying commit fe98112 but
including a slight change to
`HomeControllerTest#create_published_documents` to ensure the test is
deterministic.

* There was a flaw in the controller action and in the test so that
previously we were showing the 10 *oldest* documents by "published_at".

* Using `Edition#in_reverse_chronological_order` and
`Edition#timestamp_for_sorting` brings this feed into line with most of
the rest of the site. This sorts by `Edition#first_published_at` for
most document types, but `Publication#publication_date` and
`Speech#delivered_on` as special cases.

* Using `Edition#timestamp_for_sorting` for the atom feed entry
"published" attribute should mean that we only show documents that are
genuinely recent i.e. not just ones that have been *added* to the system
recently. This is important given that we will be adding "legacy"
documents for new departments in batches in the future.

* It seems most consistent to use the latest `timestamp_for_sorting` for
the overall feed "updated" attribute. And using `Edition#published_at`
for each entry's "updated" at seems as good as anything.

* See https://www.pivotaltracker.com/story/show/38882917 for further
details.
  • Loading branch information...
floehopper committed Nov 9, 2012
1 parent 1aca16a commit 4f7976f122eb3aa528e0f6963d262b34d631e053
Showing with 11 additions and 11 deletions.
  1. +1 −1 app/controllers/home_controller.rb
  2. +2 −2 app/views/home/feed.atom.builder
  3. +8 −8 test/functional/home_controller_test.rb
@@ -3,7 +3,7 @@ class HomeController < PublicFacingController
before_filter :set_search_path_home, only: [:sunset]

def feed
@recently_updated = Edition.published.by_published_at.includes(:document, :organisations).limit(10)
@recently_updated = Edition.published.in_reverse_chronological_order.includes(:document, :organisations).limit(10)
end

def sunset
@@ -4,10 +4,10 @@ atom_feed language: 'en-GB', url: atom_feed_url(format: :atom), root_url: root_u
feed.author do |author|
author.name 'HM Government'
end
feed.updated @recently_updated.first.published_at
feed.updated @recently_updated.first.timestamp_for_sorting

@recently_updated.each do |document|
feed.entry(document, url: public_document_url(document), published: document.first_published_at, updated: document.published_at) do |entry|
feed.entry(document, url: public_document_url(document), published: document.timestamp_for_sorting, updated: document.published_at) do |entry|
entry.title document.title
entry.content govspeak_edition_to_html(document), type: 'html'
end
@@ -39,16 +39,16 @@ class HomeControllerTest < ActionController::TestCase

get :feed, format: :atom

documents = Edition.published.by_published_at
documents = Edition.published.in_reverse_chronological_order
recent_documents = documents[0...10]
older_documents = documents[10..-1]

assert_select_atom_feed do
assert_select 'feed > updated', text: documents.map(&:published_at).max.iso8601
assert_select 'feed > updated', text: documents.map(&:timestamp_for_sorting).max.iso8601

assert_select 'feed > entry' do |entries|
entries.zip(recent_documents) do |entry, document|
assert_select entry, 'entry > published', text: document.first_published_at.iso8601
assert_select entry, 'entry > published', text: document.timestamp_for_sorting.iso8601
assert_select entry, 'entry > updated', text: document.published_at.iso8601
assert_select entry, 'entry > link[rel=?][type=?][href=?]', 'alternate', 'text/html', public_document_url(document)
assert_select entry, 'entry > title', text: document.title
@@ -67,11 +67,11 @@ class HomeControllerTest < ActionController::TestCase

def create_published_documents
5.downto(1) do |x|
create(:published_policy, published_at: x.days.ago)
create(:published_news_article, published_at: x.days.ago)
create(:published_speech, published_at: x.days.ago)
create(:published_publication, published_at: x.days.ago)
create(:published_consultation, published_at: x.days.ago)
create(:published_policy, first_published_at: x.days.ago + 1.hour)
create(:published_news_article, first_published_at: x.days.ago + 2.hours)
create(:published_speech, delivered_on: x.days.ago + 3.hours)
create(:published_publication, publication_date: x.days.ago + 4.hours)
create(:published_consultation, first_published_at: x.days.ago + 5.hours)
end
end

0 comments on commit 4f7976f

Please sign in to comment.
You can’t perform that action at this time.