From 31eb270c3a5d6f4cbad23b3e5da03610479d806a Mon Sep 17 00:00:00 2001 From: Xavier Shay Date: Wed, 30 Mar 2011 21:03:19 +1100 Subject: [PATCH] atom_feed: Allow updated to be set on entries in the same manner that it is for the entire feed. This follows the principle of least surprise. --- .../lib/action_view/helpers/atom_feed_helper.rb | 5 +++ actionpack/test/template/atom_feed_helper_test.rb | 27 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_view/helpers/atom_feed_helper.rb b/actionpack/lib/action_view/helpers/atom_feed_helper.rb index db9d7a0..87cde42 100644 --- a/actionpack/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionpack/lib/action_view/helpers/atom_feed_helper.rb @@ -130,6 +130,11 @@ module ActionView def initialize(xml) @xml = xml end + + # Accepts a Date or Time object and inserts it in the proper format. + def updated(date_or_time) + @xml.updated(date_or_time.xmlschema) + end private # Delegate to xml builder, first wrapping the element in a xhtml diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb index 36102bb..d38377d 100644 --- a/actionpack/test/template/atom_feed_helper_test.rb +++ b/actionpack/test/template/atom_feed_helper_test.rb @@ -177,6 +177,24 @@ class ScrollsController < ActionController::Base end end EOT + FEEDS["updated_in_entry"] = <<-EOT + atom_feed(:schema_date => '2008') do |feed| + feed.title("My great blog!") + feed.updated((@scrolls.first.created_at)) + + for scroll in @scrolls + feed.entry(scroll) do |entry| + entry.title(scroll.title) + entry.updated(Time.utc(2007, 1, scroll.id)) + entry.content(scroll.body, :type => 'html') + + entry.author do |author| + author.name("DHH") + end + end + end + end + EOT def index @scrolls = [ Scroll.new(1, "1", "Hello One", "Something COOL!", Time.utc(2007, 12, 12, 15), Time.utc(2007, 12, 12, 15)), @@ -239,6 +257,15 @@ class AtomFeedTest < ActionController::TestCase end end + def test_entry_with_explicit_updated_is_formatted_correctly + with_restful_routing(:scrolls) do + get :index, :id => "updated_in_entry" + + assert_select "updated", Time.utc(2007, 1, 1).xmlschema + assert_select "updated", Time.utc(2007, 1, 2).xmlschema + end + end + def test_self_url_should_default_to_current_request_url with_restful_routing(:scrolls) do get :index, :id => "defaults" -- 1.7.3.1