mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-24 16:14:07 +01:00
Updated to svn tags/tracks-1.6
This commit is contained in:
parent
103fcb8049
commit
02496f2d44
2274 changed files with 0 additions and 0 deletions
85
vendor/plugins/resource_feeder/test/atom_feed_test.rb
vendored
Normal file
85
vendor/plugins/resource_feeder/test/atom_feed_test.rb
vendored
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
require File.dirname(__FILE__) + '/test_helper'
|
||||
class AtomFeedTest < Test::Unit::TestCase
|
||||
attr_reader :request
|
||||
|
||||
def setup
|
||||
@request = OpenStruct.new
|
||||
@request.host_with_port = 'example.com'
|
||||
@records = Array.new(5).fill(Post.new)
|
||||
@records.each &:save
|
||||
end
|
||||
|
||||
def test_default_atom_feed
|
||||
atom_feed_for @records
|
||||
|
||||
assert_select 'feed' do
|
||||
assert_select '>title', 'Posts'
|
||||
assert_select '>id', "tag:#{request.host_with_port}:Posts"
|
||||
assert_select '>link' do
|
||||
assert_select "[rel='alternate']"
|
||||
assert_select "[type='text/html']"
|
||||
assert_select "[href='http://example.com/posts']"
|
||||
end
|
||||
assert_select 'entry', 5 do
|
||||
assert_select 'title', :text => 'feed title (title)'
|
||||
assert_select "content[type='html']", '<p>feed description (description)</p>'
|
||||
assert_select 'id', "tag:#{request.host_with_port},#{@records.first.created_at.xmlschema}:#{'http://example.com/posts/1'}"
|
||||
assert_select 'published', @records.first.created_at.xmlschema
|
||||
assert_select 'updated', @records.first.created_at.xmlschema
|
||||
assert_select 'link' do
|
||||
assert_select "[rel='alternate']"
|
||||
assert_select "[type='text/html']"
|
||||
assert_select "[href='http://example.com/posts/1']"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_allow_custom_feed_options
|
||||
atom_feed_for @records, :feed => { :title => 'Custom Posts', :link => '/posts', :description => 'stuff', :self => '/posts.atom' }
|
||||
|
||||
assert_select 'feed>title', 'Custom Posts'
|
||||
assert_select "feed>link[href='/posts']"
|
||||
assert_select 'feed>subtitle', 'stuff'
|
||||
assert_select 'feed>link' do
|
||||
assert_select "[rel='self']"
|
||||
assert_select "[type='application/atom+xml']"
|
||||
assert_select "[href='/posts.atom']"
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_allow_custom_item_attributes
|
||||
atom_feed_for @records, :item => { :title => :name, :description => :body, :pub_date => :create_date, :link => :id }
|
||||
|
||||
assert_select 'entry', 5 do
|
||||
assert_select 'title', :text => 'feed title (name)'
|
||||
assert_select "content[type='html']", '<p>feed description (body)</p>'
|
||||
assert_select 'published', (@records.first.created_at - 5.minutes).xmlschema
|
||||
assert_select 'updated', (@records.first.created_at - 5.minutes).xmlschema
|
||||
assert_select 'id', "tag:#{request.host_with_port},#{(@records.first.created_at - 5.minutes).xmlschema}:1"
|
||||
assert_select 'link' do
|
||||
assert_select "[rel='alternate']"
|
||||
assert_select "[type='text/html']"
|
||||
assert_select "[href='1']"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_allow_custom_item_attribute_blocks
|
||||
atom_feed_for @records, :item => { :title => lambda { |r| r.name }, :description => lambda { |r| r.body }, :pub_date => lambda { |r| r.create_date },
|
||||
:link => lambda { |r| "/#{r.created_at.to_i}" }, :guid => lambda { |r| r.created_at.to_i } }
|
||||
|
||||
assert_select 'entry', 5 do
|
||||
assert_select 'title', :text => 'feed title (name)'
|
||||
assert_select "content[type='html']", '<p>feed description (body)</p>'
|
||||
assert_select 'published', (@records.first.created_at - 5.minutes).xmlschema
|
||||
assert_select 'updated', (@records.first.created_at - 5.minutes).xmlschema
|
||||
assert_select 'id', /:\d+$/
|
||||
assert_select 'link' do
|
||||
assert_select "[rel='alternate']"
|
||||
assert_select "[type='text/html']"
|
||||
assert_select "[href=?]", /^\/\d+$/
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
86
vendor/plugins/resource_feeder/test/rss_feed_test.rb
vendored
Normal file
86
vendor/plugins/resource_feeder/test/rss_feed_test.rb
vendored
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
require File.dirname(__FILE__) + '/test_helper'
|
||||
class RssFeedTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@records = Array.new(5).fill(Post.new)
|
||||
@records.each &:save
|
||||
end
|
||||
|
||||
def test_default_rss_feed
|
||||
rss_feed_for @records
|
||||
|
||||
assert_select 'rss[version="2.0"]' do
|
||||
assert_select 'channel' do
|
||||
assert_select '>title', 'Posts'
|
||||
assert_select '>link', 'http://example.com/posts'
|
||||
assert_select 'language', 'en-us'
|
||||
assert_select 'ttl', '40'
|
||||
end
|
||||
assert_select 'item', 5 do
|
||||
assert_select 'title', :text => 'feed title (title)'
|
||||
assert_select 'description', '<p>feed description (description)</p>'
|
||||
%w(guid link).each do |node|
|
||||
assert_select node, 'http://example.com/posts/1'
|
||||
end
|
||||
assert_select 'pubDate', @records.first.created_at.to_s(:rfc822)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_allow_custom_feed_options
|
||||
rss_feed_for @records, :feed => { :title => 'Custom Posts', :link => '/posts', :description => 'stuff', :language => 'en-gb', :ttl => '80' }
|
||||
|
||||
assert_select 'channel>title', 'Custom Posts'
|
||||
assert_select 'channel>link', '/posts'
|
||||
assert_select 'channel>description', 'stuff'
|
||||
assert_select 'channel>language', 'en-gb'
|
||||
assert_select 'channel>ttl', '80'
|
||||
end
|
||||
|
||||
def test_should_allow_custom_item_attributes
|
||||
rss_feed_for @records, :item => { :title => :name, :description => :body, :pub_date => :create_date, :link => :id }
|
||||
|
||||
assert_select 'item', 5 do
|
||||
assert_select 'title', :text => 'feed title (name)'
|
||||
assert_select 'description', '<p>feed description (body)</p>'
|
||||
assert_select 'pubDate', (@records.first.created_at - 5.minutes).to_s(:rfc822)
|
||||
assert_select 'link', '1'
|
||||
assert_select 'guid', '1'
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_allow_custom_item_attribute_blocks
|
||||
rss_feed_for @records, :item => { :title => lambda { |r| r.name }, :description => lambda { |r| r.body }, :pub_date => lambda { |r| r.create_date },
|
||||
:link => lambda { |r| "/#{r.created_at.to_i}" }, :guid => lambda { |r| r.created_at.to_i } }
|
||||
|
||||
assert_select 'item', 5 do
|
||||
assert_select 'title', :text => 'feed title (name)'
|
||||
assert_select 'description', '<p>feed description (body)</p>'
|
||||
assert_select 'pubDate', (@records.first.created_at - 5.minutes).to_s(:rfc822)
|
||||
end
|
||||
end
|
||||
|
||||
# note that assert_select isnt easily able to get elements that have xml namespaces (as it thinks they are
|
||||
# invalid html psuedo children), so we do some manual testing with the response body
|
||||
def test_should_allow_content_encoded_for_items
|
||||
rss_feed_for @records, :item => { :content_encoded => :full_html_body }
|
||||
|
||||
html_content = "<strong>Here is some <i>full</i> content, with out any excerpts</strong>"
|
||||
assert_equal 5, @response.body.scan("<![CDATA[#{html_content}]]>").size
|
||||
assert_select 'item', 5 do
|
||||
assert_select 'description + *', "<![CDATA[#{html_content}" # assert_select seems to strip the ending cdata tag
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_have_content_encoded_namespace_if_used
|
||||
rss_feed_for @records, :item => { :content_encoded => :full_html_body }
|
||||
assert_equal %[<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">\n],
|
||||
@response.body.grep(/<rss version="2\.0.*"/).first
|
||||
end
|
||||
|
||||
def test_should_have_normal_rss_root_without_content_encoded
|
||||
rss_feed_for @records
|
||||
assert_equal %[<rss version="2.0">\n],
|
||||
@response.body.grep(/<rss version="2\.0.*"/).first
|
||||
end
|
||||
|
||||
end
|
||||
64
vendor/plugins/resource_feeder/test/test_helper.rb
vendored
Normal file
64
vendor/plugins/resource_feeder/test/test_helper.rb
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
RAILS_ENV = 'test'
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
|
||||
require 'action_controller/test_process'
|
||||
require 'breakpoint'
|
||||
require 'ostruct'
|
||||
|
||||
class Post
|
||||
attr_reader :id, :created_at
|
||||
def save; @id = 1; @created_at = Time.now.utc end
|
||||
def new_record?; @id.nil? end
|
||||
|
||||
[:title, :name].each do |attr_name|
|
||||
define_method attr_name do
|
||||
"feed title (#{attr_name})"
|
||||
end
|
||||
end
|
||||
|
||||
[:description, :body].each do |attr_name|
|
||||
define_method attr_name do
|
||||
"<p>feed description (#{attr_name})</p>"
|
||||
end
|
||||
end
|
||||
|
||||
def full_html_body
|
||||
"<strong>Here is some <i>full</i> content, with out any excerpts</strong>"
|
||||
end
|
||||
|
||||
def create_date
|
||||
@created_at - 5.minutes
|
||||
end
|
||||
end
|
||||
|
||||
class Test::Unit::TestCase
|
||||
include ResourceFeeder::Rss, ResourceFeeder::Atom
|
||||
|
||||
def render_feed(xml)
|
||||
@response = OpenStruct.new
|
||||
@response.headers = {'Content-Type' => 'text/xml'}
|
||||
@response.body = xml
|
||||
end
|
||||
|
||||
def rss_feed_for_with_ostruct(resources, options = {})
|
||||
render_feed rss_feed_for_without_ostruct(resources, options)
|
||||
end
|
||||
|
||||
def atom_feed_for_with_ostruct(resources, options = {})
|
||||
render_feed atom_feed_for_without_ostruct(resources, options)
|
||||
end
|
||||
|
||||
alias_method_chain :rss_feed_for, :ostruct
|
||||
alias_method_chain :atom_feed_for, :ostruct
|
||||
|
||||
def html_document
|
||||
@html_document ||= HTML::Document.new(@response.body, false, true)
|
||||
end
|
||||
|
||||
def posts_url
|
||||
"http://example.com/posts"
|
||||
end
|
||||
|
||||
def post_url(post)
|
||||
"http://example.com/posts/#{post.id}"
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue