Permalink
Browse files

Fix issue 5 that was causing only one set of sitemap files to be gene…

…rated if

the same model was added more than once with different options
  • Loading branch information...
1 parent e87fe72 commit ff71904c599c8cb05173abc0b25abf91a7a1f5d1 @alexrabarts committed Jan 25, 2011
Showing with 19 additions and 0 deletions.
  1. +9 −0 lib/big_sitemap.rb
  2. +10 −0 test/big_sitemap_test.rb
View
@@ -56,15 +56,24 @@ def initialize(options={})
Dir.mkdir(@file_path) unless File.exists? @file_path
@sources = []
+ @models = []
@sitemap_files = []
end
def add(model, options={})
+ @models << model
+
+ filename_suffix = @models.count(model) - 1
+
options[:path] ||= table_name(model)
options[:filename] ||= file_name(model)
options[:primary_column] ||= 'id' if model.new.respond_to?('id')
options[:partial_update] = @options[:partial_update] && options[:partial_update] != false
+
+ options[:filename] << "_#{filename_suffix}" unless filename_suffix == 0
+
@sources << [model, options.dup]
+
self
end
View
@@ -42,6 +42,16 @@ def teardown
assert !File.exists?(third_sitemaps_model_file), "#{third_sitemaps_model_file} does not exist"
end
+ should 'generate two sitemap model files for the same model with different options' do
+ create_sitemap
+ add_model(:path => 'foo')
+ add_model(:path => 'bar')
+ @sitemap.generate
+
+ assert File.exists?(first_sitemaps_model_file), "#{first_sitemaps_model_file} exists"
+ assert File.exists?(second_sitemaps_model_file), "#{second_sitemaps_model_file} exists"
+ end
+
context 'Sitemap index file' do
should 'contain one sitemapindex element' do
generate_sitemap_files

0 comments on commit ff71904

Please sign in to comment.