bcms_sitemap 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,6 +1,6 @@
1
1
  **WARNING: This module has not yet been tested in a live production environment**
2
2
 
3
- **NOTE: Gem has not been built yet.**
3
+ Available as a gem at [Gemcutter.org](http://gemcutter.org)
4
4
 
5
5
  # BCMS\_sitemap BrowserCMS sitemap submission module
6
6
 
@@ -4,7 +4,14 @@ module SitemapsHelper
4
4
  end
5
5
 
6
6
  def xml_url(object)
7
- "http://#{SITE_DOMAIN}#{object.path}"
7
+ if object.respond_to? :path
8
+ "http://#{SITE_DOMAIN}#{object.path}"
9
+ elsif object.respond_to? :route_params
10
+ object_name = ActionController::RecordIdentifier::singular_class_name(object)
11
+ self.send("#{object_name}_url", object.route_params)
12
+ else
13
+ polymorphic_url(object)
14
+ end
8
15
  end
9
16
 
10
17
  def xml_article_url(object)
@@ -1,6 +1,6 @@
1
1
  xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
2
2
  xml.urlset :xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9" do
3
- @articles.each do |object|
3
+ @news_articles.each do |object|
4
4
  xml.url do
5
5
  xml.loc news_article_url(object.route_params)
6
6
  xml.lastmod xml_lastmod(object)
@@ -34,7 +34,7 @@ def page(path, priority = 0.9, frequency = :daily, archived = false)
34
34
  <?xml version="1.0" encoding="UTF-8"?>
35
35
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
36
36
  <url>
37
- <loc>http://localhost:3000#{path}</loc>
37
+ <loc>http://test.host#{path}</loc>
38
38
  <lastmod>2010-02-05T10:54:49Z</lastmod>
39
39
  <changefreq>#{frequency}</changefreq>
40
40
  <priority>#{priority}</priority>
@@ -115,23 +115,39 @@ TEXT
115
115
  setup do
116
116
  @article = create_news_article(:name => 'This is the name of the article', :release_date => @time.to_date)
117
117
  end
118
- should_eventually 'publish articles' do
118
+ should 'publish articles' do
119
119
  @expected = <<-TEXT
120
- <?xml version="1.0" encoding="UTF-8"?>
121
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
122
- <url>
123
- <loc>http://localhost:3000/news/articles/2010/02/10/this-is-the-name-of-the-article</loc>
124
- <lastmod>2010-02-05T10:54:49Z</lastmod>
125
- <changefreq>weekly</changefreq>
126
- <priority>0.7</priority>
127
- </url>
128
- </urlset>
120
+ <?xml version="1.0" encoding="UTF-8"?>
121
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
122
+ <url>
123
+ <loc>http://test.host/news/articles/2010/02/04/this-is-the-name-of-the-article</loc>
124
+ <lastmod>2010-02-05T10:54:49Z</lastmod>
125
+ <changefreq>weekly</changefreq>
126
+ <priority>0.7</priority>
127
+ </url>
128
+ </urlset>
129
129
  TEXT
130
- get :news_articles, :format => 'xml'
130
+ get :model, :model => 'news_articles', :format => :xml
131
131
  assert_response :success
132
132
  assert_dom_equal @expected, @response.body
133
133
  end
134
134
  should_eventually 'give archived articles lower priority' do
135
+ @article.update_attribute(:archived, true)
136
+ @expected = <<-TEXT
137
+ <?xml version="1.0" encoding="UTF-8"?>
138
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
139
+ <url>
140
+ <loc>http://test.host/news/articles/2010/02/04/this-is-the-name-of-the-article</loc>
141
+ <lastmod>2010-02-05T10:54:49Z</lastmod>
142
+ <changefreq>never</changefreq>
143
+ <priority>0.4</priority>
144
+ </url>
145
+ </urlset>
146
+ TEXT
147
+ get :model, :model => 'news_articles', :format => :xml
148
+ assert_response :success
149
+ assert_dom_equal @expected, @response.body
150
+
135
151
  end
136
152
  end
137
153
 
@@ -33,7 +33,7 @@ class Cms::SitemapSubmitterTest < ActiveSupport::TestCase
33
33
  assert_equal 404, resp
34
34
  end
35
35
  should 'generate correct parameters' do
36
- assert_equal "http%3A%2F%2Flocalhost%3A3000%2Fsitemaps.xml", @submitter.parameters
36
+ assert_equal "http%3A%2F%2Ftest.host%2Fsitemaps.xml", @submitter.parameters
37
37
  end
38
38
  end
39
39
 
data/test/test_factory.rb CHANGED
@@ -26,4 +26,7 @@ module TestFactory
26
26
  def create_news_article(options = {})
27
27
  _create NewsArticle.create({:name => 'Nyhet', :body => 'i dag', :published => true, :release_date => Date.today}.merge(options))
28
28
  end
29
+ def new_news_article(options = {})
30
+ NewsArticle.new({:name => 'Nyhet', :body => 'i dag', :published => true, :release_date => Date.today}.merge(options))
31
+ end
29
32
  end
@@ -1,4 +1,22 @@
1
1
  require 'test_helper'
2
+ require 'test_factory'
2
3
 
3
4
  class SitemapsHelperTest < ActionView::TestCase
5
+ fixtures :page_routes
6
+
7
+ context 'xml_url' do
8
+ setup do
9
+ page_routes(:new_article).reload_routes
10
+ @news = create_news_article :name => 'good-news', :created_at => Date.parse('2010-03-03')
11
+ flunk "Expected news article not to respond to path" if @news.respond_to?(:path)
12
+ @page = create_page :path => '/home'
13
+ flunk "Expected page to respond to path" unless @page.respond_to?(:path)
14
+ end
15
+ should 'handle objects which has path' do
16
+ assert_equal "http://test.host/home", xml_url(@page)
17
+ end
18
+ should 'handle objects which does not have path' do
19
+ assert_equal "http://test.host/news/articles/2010/03/02/good-news", xml_url(@news)
20
+ end
21
+ end
4
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcms_sitemap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Knut Stenmark
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-17 00:00:00 +01:00
12
+ date: 2010-03-03 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency