2008-01-05 08:32:06 -05:00
|
|
|
require 'abstract_unit'
|
2007-09-21 18:17:35 -04:00
|
|
|
|
2009-07-19 11:27:04 -04:00
|
|
|
class Scroll < Struct.new(:id, :to_param, :title, :body, :updated_at, :created_at)
|
2009-07-21 01:51:57 -04:00
|
|
|
extend ActiveModel::Naming
|
|
|
|
include ActiveModel::Conversion
|
2009-07-19 11:27:04 -04:00
|
|
|
|
2010-02-21 05:09:21 -05:00
|
|
|
def persisted?
|
|
|
|
false
|
2009-07-19 11:27:04 -04:00
|
|
|
end
|
|
|
|
end
|
2007-09-21 18:17:35 -04:00
|
|
|
|
2007-09-21 19:42:59 -04:00
|
|
|
class ScrollsController < ActionController::Base
|
2007-09-21 18:17:35 -04:00
|
|
|
FEEDS = {}
|
|
|
|
FEEDS["defaults"] = <<-EOT
|
2008-01-02 14:45:53 -05:00
|
|
|
atom_feed(:schema_date => '2008') do |feed|
|
2007-09-21 18:17:35 -04:00
|
|
|
feed.title("My great blog!")
|
2015-05-13 17:22:49 -04:00
|
|
|
feed.updated(@scrolls.first.created_at)
|
2007-09-21 18:17:35 -04:00
|
|
|
|
2012-01-14 15:28:09 -05:00
|
|
|
@scrolls.each do |scroll|
|
2007-09-21 19:42:59 -04:00
|
|
|
feed.entry(scroll) do |entry|
|
|
|
|
entry.title(scroll.title)
|
|
|
|
entry.content(scroll.body, :type => 'html')
|
2007-09-21 18:17:35 -04:00
|
|
|
|
|
|
|
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!")
|
2015-05-13 17:22:49 -04:00
|
|
|
feed.updated(@scrolls.first.created_at)
|
2007-09-21 18:17:35 -04:00
|
|
|
|
2011-05-18 23:47:49 -04:00
|
|
|
@scrolls.each do |scroll|
|
2010-02-21 05:09:21 -05:00
|
|
|
feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param.to_s, :updated => Time.utc(2007, 1, scroll.id)) do |entry|
|
2007-09-21 19:42:59 -04:00
|
|
|
entry.title(scroll.title)
|
|
|
|
entry.content(scroll.body, :type => 'html')
|
2007-09-21 18:17:35 -04:00
|
|
|
|
|
|
|
entry.author do |author|
|
|
|
|
author.name("DHH")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOT
|
2012-04-01 13:07:34 -04:00
|
|
|
FEEDS["entry_type_options"] = <<-EOT
|
|
|
|
atom_feed(:schema_date => '2008') do |feed|
|
|
|
|
feed.title("My great blog!")
|
2015-05-13 17:22:49 -04:00
|
|
|
feed.updated(@scrolls.first.created_at)
|
2012-04-01 13:07:34 -04:00
|
|
|
|
|
|
|
@scrolls.each do |scroll|
|
|
|
|
feed.entry(scroll, :type => 'text/xml') do |entry|
|
|
|
|
entry.title(scroll.title)
|
|
|
|
entry.content(scroll.body, :type => 'html')
|
|
|
|
|
|
|
|
entry.author do |author|
|
|
|
|
author.name("DHH")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOT
|
2015-01-10 11:06:53 -05:00
|
|
|
FEEDS["entry_url_false_option"] = <<-EOT
|
|
|
|
atom_feed do |feed|
|
|
|
|
feed.title("My great blog!")
|
2015-05-13 17:22:49 -04:00
|
|
|
feed.updated(@scrolls.first.created_at)
|
2015-01-10 11:06:53 -05:00
|
|
|
|
|
|
|
@scrolls.each do |scroll|
|
|
|
|
feed.entry(scroll, :url => false) do |entry|
|
|
|
|
entry.title(scroll.title)
|
|
|
|
entry.content(scroll.body, :type => 'html')
|
|
|
|
|
|
|
|
entry.author do |author|
|
|
|
|
author.name("DHH")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOT
|
2008-01-02 14:45:53 -05:00
|
|
|
FEEDS["xml_block"] = <<-EOT
|
|
|
|
atom_feed do |feed|
|
|
|
|
feed.title("My great blog!")
|
2015-05-13 17:22:49 -04:00
|
|
|
feed.updated(@scrolls.first.created_at)
|
2007-09-21 18:17:35 -04:00
|
|
|
|
2008-01-02 14:45:53 -05:00
|
|
|
feed.author do |author|
|
|
|
|
author.name("DHH")
|
|
|
|
end
|
|
|
|
|
2011-05-18 23:47:49 -04:00
|
|
|
@scrolls.each do |scroll|
|
2010-02-21 05:09:21 -05:00
|
|
|
feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param.to_s, :updated => Time.utc(2007, 1, scroll.id)) do |entry|
|
2008-01-02 14:45:53 -05:00
|
|
|
entry.title(scroll.title)
|
|
|
|
entry.content(scroll.body, :type => 'html')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOT
|
2008-01-12 19:11:39 -05:00
|
|
|
FEEDS["feed_with_atomPub_namespace"] = <<-EOT
|
|
|
|
atom_feed({'xmlns:app' => 'http://www.w3.org/2007/app',
|
|
|
|
'xmlns:openSearch' => 'http://a9.com/-/spec/opensearch/1.1/'}) do |feed|
|
|
|
|
feed.title("My great blog!")
|
2015-05-13 17:22:49 -04:00
|
|
|
feed.updated(@scrolls.first.created_at)
|
2008-01-12 19:11:39 -05:00
|
|
|
|
2011-05-18 23:47:49 -04:00
|
|
|
@scrolls.each do |scroll|
|
2008-01-12 19:11:39 -05:00
|
|
|
feed.entry(scroll) do |entry|
|
|
|
|
entry.title(scroll.title)
|
|
|
|
entry.content(scroll.body, :type => 'html')
|
|
|
|
entry.tag!('app:edited', Time.now)
|
|
|
|
|
2008-06-25 06:15:26 -04:00
|
|
|
entry.author do |author|
|
|
|
|
author.name("DHH")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOT
|
|
|
|
FEEDS["feed_with_overridden_ids"] = <<-EOT
|
|
|
|
atom_feed({:id => 'tag:test.rubyonrails.org,2008:test/'}) do |feed|
|
|
|
|
feed.title("My great blog!")
|
2015-05-13 17:22:49 -04:00
|
|
|
feed.updated(@scrolls.first.created_at)
|
2008-06-25 06:15:26 -04:00
|
|
|
|
2011-05-18 23:47:49 -04:00
|
|
|
@scrolls.each do |scroll|
|
2008-06-25 06:15:26 -04:00
|
|
|
feed.entry(scroll, :id => "tag:test.rubyonrails.org,2008:"+scroll.id.to_s) do |entry|
|
|
|
|
entry.title(scroll.title)
|
|
|
|
entry.content(scroll.body, :type => 'html')
|
|
|
|
entry.tag!('app:edited', Time.now)
|
|
|
|
|
2008-09-10 02:37:36 -04:00
|
|
|
entry.author do |author|
|
|
|
|
author.name("DHH")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOT
|
|
|
|
FEEDS["feed_with_xml_processing_instructions"] = <<-EOT
|
|
|
|
atom_feed(:schema_date => '2008',
|
|
|
|
:instruct => {'xml-stylesheet' => { :href=> 't.css', :type => 'text/css' }}) do |feed|
|
|
|
|
feed.title("My great blog!")
|
2015-05-13 17:22:49 -04:00
|
|
|
feed.updated(@scrolls.first.created_at)
|
2008-09-10 02:37:36 -04:00
|
|
|
|
2011-05-18 23:47:49 -04:00
|
|
|
@scrolls.each do |scroll|
|
2008-09-10 02:37:36 -04:00
|
|
|
feed.entry(scroll) do |entry|
|
|
|
|
entry.title(scroll.title)
|
|
|
|
entry.content(scroll.body, :type => 'html')
|
|
|
|
|
|
|
|
entry.author do |author|
|
|
|
|
author.name("DHH")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOT
|
|
|
|
FEEDS["feed_with_xml_processing_instructions_duplicate_targets"] = <<-EOT
|
|
|
|
atom_feed(:schema_date => '2008',
|
|
|
|
:instruct => {'target1' => [{ :a => '1', :b => '2' }, { :c => '3', :d => '4' }]}) do |feed|
|
|
|
|
feed.title("My great blog!")
|
2015-05-13 17:22:49 -04:00
|
|
|
feed.updated(@scrolls.first.created_at)
|
2008-09-10 02:37:36 -04:00
|
|
|
|
2011-05-18 23:47:49 -04:00
|
|
|
@scrolls.each do |scroll|
|
2008-09-10 02:37:36 -04:00
|
|
|
feed.entry(scroll) do |entry|
|
|
|
|
entry.title(scroll.title)
|
|
|
|
entry.content(scroll.body, :type => 'html')
|
|
|
|
|
2008-10-13 13:52:37 -04:00
|
|
|
entry.author do |author|
|
|
|
|
author.name("DHH")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOT
|
|
|
|
FEEDS["feed_with_xhtml_content"] = <<-'EOT'
|
|
|
|
atom_feed do |feed|
|
|
|
|
feed.title("My great blog!")
|
2015-05-13 17:22:49 -04:00
|
|
|
feed.updated(@scrolls.first.created_at)
|
2008-10-13 13:52:37 -04:00
|
|
|
|
2011-05-18 23:47:49 -04:00
|
|
|
@scrolls.each do |scroll|
|
2008-10-13 13:52:37 -04:00
|
|
|
feed.entry(scroll) do |entry|
|
|
|
|
entry.title(scroll.title)
|
|
|
|
entry.summary(:type => 'xhtml') do |xhtml|
|
|
|
|
xhtml.p "before #{scroll.id}"
|
|
|
|
xhtml.p {xhtml << scroll.body}
|
|
|
|
xhtml.p "after #{scroll.id}"
|
|
|
|
end
|
|
|
|
entry.tag!('app:edited', Time.now)
|
|
|
|
|
2008-01-12 19:11:39 -05:00
|
|
|
entry.author do |author|
|
|
|
|
author.name("DHH")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOT
|
2009-08-08 21:07:50 -04:00
|
|
|
FEEDS["provide_builder"] = <<-'EOT'
|
|
|
|
# we pass in the new_xml to the helper so it doesn't
|
|
|
|
# call anything on the original builder
|
|
|
|
new_xml = Builder::XmlMarkup.new(:target=>'')
|
|
|
|
atom_feed(:xml => new_xml) do |feed|
|
|
|
|
feed.title("My great blog!")
|
2015-05-13 17:22:49 -04:00
|
|
|
feed.updated(@scrolls.first.created_at)
|
2009-08-08 21:07:50 -04:00
|
|
|
|
2011-05-18 23:47:49 -04:00
|
|
|
@scrolls.each do |scroll|
|
2009-08-08 21:07:50 -04:00
|
|
|
feed.entry(scroll) do |entry|
|
|
|
|
entry.title(scroll.title)
|
|
|
|
entry.content(scroll.body, :type => 'html')
|
|
|
|
|
|
|
|
entry.author do |author|
|
|
|
|
author.name("DHH")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOT
|
2007-09-21 18:17:35 -04:00
|
|
|
def index
|
2007-09-21 19:42:59 -04:00
|
|
|
@scrolls = [
|
|
|
|
Scroll.new(1, "1", "Hello One", "Something <i>COOL!</i>", Time.utc(2007, 12, 12, 15), Time.utc(2007, 12, 12, 15)),
|
|
|
|
Scroll.new(2, "2", "Hello Two", "Something Boring", Time.utc(2007, 12, 12, 15)),
|
2007-09-21 18:17:35 -04:00
|
|
|
]
|
2008-06-25 06:15:26 -04:00
|
|
|
|
2007-09-21 18:17:35 -04:00
|
|
|
render :inline => FEEDS[params[:id]], :type => :builder
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-07 15:42:34 -05:00
|
|
|
class AtomFeedTest < ActionController::TestCase
|
|
|
|
tests ScrollsController
|
2007-09-21 18:17:35 -04:00
|
|
|
|
2008-11-07 15:42:34 -05:00
|
|
|
def setup
|
2009-04-08 20:33:06 -04:00
|
|
|
super
|
2007-09-21 18:17:35 -04:00
|
|
|
@request.host = "www.nextangle.com"
|
|
|
|
end
|
2008-06-25 06:15:26 -04:00
|
|
|
|
2007-09-21 18:17:35 -04:00
|
|
|
def test_feed_should_use_default_language_if_none_is_given
|
2007-09-21 19:42:59 -04:00
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: "defaults" }
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(%r{xml:lang="en-US"}, @response.body)
|
2007-09-21 18:17:35 -04:00
|
|
|
end
|
|
|
|
end
|
2008-06-25 06:15:26 -04:00
|
|
|
|
2007-09-21 18:17:35 -04:00
|
|
|
def test_feed_should_include_two_entries
|
2007-09-21 19:42:59 -04:00
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: "defaults" }
|
2007-09-21 18:17:35 -04:00
|
|
|
assert_select "entry", 2
|
|
|
|
end
|
|
|
|
end
|
2008-06-25 06:15:26 -04:00
|
|
|
|
2007-09-21 18:17:35 -04:00
|
|
|
def test_entry_should_only_use_published_if_created_at_is_present
|
2007-09-21 19:42:59 -04:00
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: "defaults" }
|
2007-09-21 18:17:35 -04:00
|
|
|
assert_select "published", 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-08 21:07:50 -04:00
|
|
|
def test_providing_builder_to_atom_feed
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: "provide_builder" }
|
2009-08-08 21:07:50 -04:00
|
|
|
# because we pass in the non-default builder, the content generated by the
|
|
|
|
# helper should go 'nowhere'. Leaving the response body blank.
|
2013-01-05 11:59:36 -05:00
|
|
|
assert @response.body.blank?
|
2009-08-08 21:07:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-09-21 18:17:35 -04:00
|
|
|
def test_entry_with_prefilled_options_should_use_those_instead_of_querying_the_record
|
2007-09-21 19:42:59 -04:00
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: "entry_options" }
|
2007-09-21 18:17:35 -04:00
|
|
|
|
|
|
|
assert_select "updated", Time.utc(2007, 1, 1).xmlschema
|
|
|
|
assert_select "updated", Time.utc(2007, 1, 2).xmlschema
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-01-02 14:45:53 -05:00
|
|
|
def test_self_url_should_default_to_current_request_url
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: "defaults" }
|
2013-07-22 16:25:54 -04:00
|
|
|
assert_select "link[rel=self][href=\"http://www.nextangle.com/scrolls?id=defaults\"]"
|
2008-01-02 14:45:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_feed_id_should_be_a_valid_tag
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: "defaults" }
|
2008-01-02 14:45:53 -05:00
|
|
|
assert_select "id", :text => "tag:www.nextangle.com,2008:/scrolls?id=defaults"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_entry_id_should_be_a_valid_tag
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: "defaults" }
|
2008-01-02 14:45:53 -05:00
|
|
|
assert_select "entry id", :text => "tag:www.nextangle.com,2008:Scroll/1"
|
|
|
|
assert_select "entry id", :text => "tag:www.nextangle.com,2008:Scroll/2"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_feed_should_allow_nested_xml_blocks
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: "xml_block" }
|
2008-01-02 14:45:53 -05:00
|
|
|
assert_select "author name", :text => "DHH"
|
|
|
|
end
|
|
|
|
end
|
2007-09-21 18:17:35 -04:00
|
|
|
|
2008-01-12 19:11:39 -05:00
|
|
|
def test_feed_should_include_atomPub_namespace
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: "feed_with_atomPub_namespace" }
|
2008-01-12 19:11:39 -05:00
|
|
|
assert_match %r{xml:lang="en-US"}, @response.body
|
|
|
|
assert_match %r{xmlns="http://www.w3.org/2005/Atom"}, @response.body
|
|
|
|
assert_match %r{xmlns:app="http://www.w3.org/2007/app"}, @response.body
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-25 06:15:26 -04:00
|
|
|
def test_feed_should_allow_overriding_ids
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: "feed_with_overridden_ids" }
|
2008-06-25 06:15:26 -04:00
|
|
|
assert_select "id", :text => "tag:test.rubyonrails.org,2008:test/"
|
|
|
|
assert_select "entry id", :text => "tag:test.rubyonrails.org,2008:1"
|
|
|
|
assert_select "entry id", :text => "tag:test.rubyonrails.org,2008:2"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-09-10 02:37:36 -04:00
|
|
|
def test_feed_xml_processing_instructions
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: 'feed_with_xml_processing_instructions' }
|
2008-11-07 17:45:10 -05:00
|
|
|
assert_match %r{<\?xml-stylesheet [^\?]*type="text/css"}, @response.body
|
|
|
|
assert_match %r{<\?xml-stylesheet [^\?]*href="t.css"}, @response.body
|
2008-09-10 02:37:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_feed_xml_processing_instructions_duplicate_targets
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: 'feed_with_xml_processing_instructions_duplicate_targets' }
|
2008-09-10 02:37:36 -04:00
|
|
|
assert_match %r{<\?target1 (a="1" b="2"|b="2" a="1")\?>}, @response.body
|
|
|
|
assert_match %r{<\?target1 (c="3" d="4"|d="4" c="3")\?>}, @response.body
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-13 13:52:37 -04:00
|
|
|
def test_feed_xhtml
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: "feed_with_xhtml_content" }
|
2008-10-13 13:52:37 -04:00
|
|
|
assert_match %r{xmlns="http://www.w3.org/1999/xhtml"}, @response.body
|
2014-07-15 13:42:36 -04:00
|
|
|
assert_select "summary", :text => /Something Boring/
|
|
|
|
assert_select "summary", :text => /after 2/
|
2008-10-13 13:52:37 -04:00
|
|
|
end
|
|
|
|
end
|
2009-12-08 17:52:26 -05:00
|
|
|
|
2012-04-01 13:07:34 -04:00
|
|
|
def test_feed_entry_type_option_default_to_text_html
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: 'defaults' }
|
2013-07-22 16:25:54 -04:00
|
|
|
assert_select "entry link[rel=alternate][type=\"text/html\"]"
|
2012-04-01 13:07:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_feed_entry_type_option_specified
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: 'entry_type_options' }
|
2013-07-22 16:25:54 -04:00
|
|
|
assert_select "entry link[rel=alternate][type=\"text/xml\"]"
|
2012-04-01 13:07:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-10 11:06:53 -05:00
|
|
|
def test_feed_entry_url_false_option_adds_no_link
|
|
|
|
with_restful_routing(:scrolls) do
|
2015-01-31 11:24:33 -05:00
|
|
|
get :index, params: { id: 'entry_url_false_option' }
|
2015-01-10 11:06:53 -05:00
|
|
|
assert_select "entry link", false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-12-08 17:52:26 -05:00
|
|
|
private
|
2007-09-21 18:17:35 -04:00
|
|
|
def with_restful_routing(resources)
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2009-12-08 17:52:26 -05:00
|
|
|
resources(resources)
|
2007-09-21 18:17:35 -04:00
|
|
|
end
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
2008-01-02 14:45:53 -05:00
|
|
|
end
|