diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-21 22:17:35 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-21 22:17:35 +0000 |
commit | 8b2439e5e42fa8fa8e74538938eed186a0258b4a (patch) | |
tree | 508634a386a05e7629a6fa306f21f9ca5a4a7b8e /actionpack/test | |
parent | 9b468f4cd7daa9f1e8122938e6c2c5b8bf235a5f (diff) | |
download | rails-8b2439e5e42fa8fa8e74538938eed186a0258b4a.tar.gz rails-8b2439e5e42fa8fa8e74538938eed186a0258b4a.tar.bz2 rails-8b2439e5e42fa8fa8e74538938eed186a0258b4a.zip |
Added AtomFeedHelper (slightly improved from the atom_feed_helper plugin) [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7529 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/template/atom_feed_helper_test.rb | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb new file mode 100644 index 0000000000..45b1cae7c2 --- /dev/null +++ b/actionpack/test/template/atom_feed_helper_test.rb @@ -0,0 +1,101 @@ +require "#{File.dirname(__FILE__)}/../abstract_unit" + +Post = Struct.new(:id, :to_param, :title, :body, :updated_at, :created_at) + +class PostsController < ActionController::Base + FEEDS = {} + FEEDS["defaults"] = <<-EOT + atom_feed do |feed| + feed.title("My great blog!") + feed.updated((@posts.first.created_at)) + + for post in @posts + feed.entry(post) do |entry| + entry.title(post.title) + entry.content(post.body, :type => 'html') + + entry.author do |author| + author.name("DHH") + end + end + end + end + EOT + FEEDS["entry_options"] = <<-EOT + atom_feed do |feed| + feed.title("My great blog!") + feed.updated((@posts.first.created_at)) + + for post in @posts + feed.entry(post, :url => "/otherstuff/" + post.to_param, :updated => Time.utc(2007, 1, post.id)) do |entry| + entry.title(post.title) + entry.content(post.body, :type => 'html') + + entry.author do |author| + author.name("DHH") + end + end + end + end + EOT + + def index + @posts = [ + Post.new(1, "1", "Hello One", "Something <i>COOL!</i>", Time.utc(2007, 12, 12, 15), Time.utc(2007, 12, 12, 15)), + Post.new(2, "2", "Hello Two", "Something Boring", Time.utc(2007, 12, 12, 15)), + ] + + render :inline => FEEDS[params[:id]], :type => :builder + end +end + +class RenderTest < Test::Unit::TestCase + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @controller = PostsController.new + + @request.host = "www.nextangle.com" + end + + def test_feed_should_use_default_language_if_none_is_given + with_restful_routing(:posts) do + get :index, :id => "defaults" + assert_match %r{xml:lang="en-US"}, @response.body + end + end + + def test_feed_should_include_two_entries + with_restful_routing(:posts) do + get :index, :id => "defaults" + assert_select "entry", 2 + end + end + + def test_entry_should_only_use_published_if_created_at_is_present + with_restful_routing(:posts) do + get :index, :id => "defaults" + assert_select "published", 1 + end + end + + def test_entry_with_prefilled_options_should_use_those_instead_of_querying_the_record + with_restful_routing(:posts) do + get :index, :id => "entry_options" + + assert_select "updated", Time.utc(2007, 1, 1).xmlschema + assert_select "updated", Time.utc(2007, 1, 2).xmlschema + end + end + + + private + def with_restful_routing(resources) + with_routing do |set| + set.draw do |map| + map.resources(resources) + end + yield + end + end +end
\ No newline at end of file |