diff --git a/lib/dynamic_sitemaps/generator.rb b/lib/dynamic_sitemaps/generator.rb index 84c48c0..9f3e110 100644 --- a/lib/dynamic_sitemaps/generator.rb +++ b/lib/dynamic_sitemaps/generator.rb @@ -61,7 +61,7 @@ def sitemap(*args, &block) def sitemap_for(collection, options = {}, &block) raise ArgumentError, "The collection given to `sitemap_for` must respond to #find_each. This is for performance. Use `Model.scoped` to get an ActiveRecord relation that responds to #find_each." unless collection.respond_to?(:find_each) - name = options.delete(:name) || collection.model_name.to_s.underscore.pluralize.to_sym + name = options.delete(:name) || collection.model_name.demodulize.to_s.underscore.pluralize.to_sym options[:collection] = collection sitemap(name, options, &block) @@ -122,4 +122,4 @@ def folder(*args) end end end -end \ No newline at end of file +end diff --git a/test/dummy/app/models/blog.rb b/test/dummy/app/models/blog.rb new file mode 100644 index 0000000..411613a --- /dev/null +++ b/test/dummy/app/models/blog.rb @@ -0,0 +1,5 @@ +module Blog + def self.table_name_prefix + 'blog_' + end +end diff --git a/test/dummy/app/models/blog/post.rb b/test/dummy/app/models/blog/post.rb new file mode 100644 index 0000000..6627df3 --- /dev/null +++ b/test/dummy/app/models/blog/post.rb @@ -0,0 +1,7 @@ +class Blog::Post < ActiveRecord::Base + attr_accessible :title + + def to_param + title || id.to_s + end +end diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index 71bdf54..b8be074 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -4,4 +4,6 @@ resources :products do resources :comments end + + resources :blog_posts end \ No newline at end of file diff --git a/test/dummy/db/migrate/20140420132943_create_blog_posts.rb b/test/dummy/db/migrate/20140420132943_create_blog_posts.rb new file mode 100644 index 0000000..d851d67 --- /dev/null +++ b/test/dummy/db/migrate/20140420132943_create_blog_posts.rb @@ -0,0 +1,9 @@ +class CreateBlogPosts < ActiveRecord::Migration + def change + create_table :blog_posts do |t| + t.string :title + + t.timestamps + end + end +end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index e18ffc1..fc5edd5 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -11,7 +11,13 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130211190343) do +ActiveRecord::Schema.define(:version => 20140420132943) do + + create_table "blog_posts", :force => true do |t| + t.string "title" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end create_table "products", :force => true do |t| t.boolean "featured", :default => false diff --git a/test/dummy/test/fixtures/blog/posts.yml b/test/dummy/test/fixtures/blog/posts.yml new file mode 100644 index 0000000..1f0362f --- /dev/null +++ b/test/dummy/test/fixtures/blog/posts.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + title: MyString + +two: + title: MyString diff --git a/test/dummy/test/unit/blog/post_test.rb b/test/dummy/test/unit/blog/post_test.rb new file mode 100644 index 0000000..8b10124 --- /dev/null +++ b/test/dummy/test/unit/blog/post_test.rb @@ -0,0 +1,7 @@ +# require 'test_helper' + +# class Blog::PostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +# end diff --git a/test/generator_test.rb b/test/generator_test.rb index 6e3bc38..eefd815 100644 --- a/test/generator_test.rb +++ b/test/generator_test.rb @@ -456,6 +456,37 @@ class GeneratorTest < ActiveSupport::TestCase end end + test "basic sitemap with model in namespace" do + 2.times { Blog::Post.create } + + DynamicSitemaps.generate_sitemap do + host "www.mytest.com" + + sitemap :site do + url root_url + end + + sitemap_for Blog::Post.scoped do |product| + url product + url product_comments_url(product) + end + + end + + doc = open_sitemap + assert_equal "http://www.mytest.com/sitemaps/site.xml", doc.xpath("sitemapindex/sitemap/loc").first.text + + doc = open_sitemap(Rails.root.join("public", "sitemaps", "posts.xml")) + urls = doc.xpath("urlset/url") + assert_equal 4, urls.count + + + urls[0].tap do |url| + assert_equal "http://www.mytest.com/blog_posts/1", url.xpath("loc").text + end + + end + private # Opens a sitemap file using Nokogiri::XML and removes namespaces by default.