Skip to content

Commit

Permalink
urls should be unique
Browse files Browse the repository at this point in the history
  • Loading branch information
lis2 committed Jun 6, 2012
1 parent f0aaa97 commit 3ebc5b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/big_sitemap.rb
Expand Up @@ -178,6 +178,7 @@ def add_urls
return self if Array(@paths).empty?

with_sitemap do |builder|
@paths.uniq!
@paths.each do |path, options|
url = URI.join(@options[:base_url], path)
builder.add_url! url, options
Expand Down
26 changes: 17 additions & 9 deletions test/big_sitemap_test.rb
Expand Up @@ -75,15 +75,15 @@ def teardown

should 'contain two loc elements' do
generate_sitemap(:max_per_sitemap => 2) do
4.times { add '/' }
4.times { |i| add "/#{i}" }
end

assert_equal 2, num_elements(sitemaps_index_file, 'loc')
end

should 'contain two lastmod elements' do
generate_sitemap(:max_per_sitemap => 2) do
4.times { add '/' }
4.times { |i| add "/#{i}" }
end

assert_equal 2, num_elements(sitemaps_index_file, 'lastmod')
Expand All @@ -103,31 +103,31 @@ def teardown

should 'contain several loc elements' do
generate_sitemap do
3.times { add '/' }
3.times { |i| add "/#{i}" }
end

assert_equal 3, num_elements(first_sitemap_file, 'loc')
end

should 'contain several lastmod elements' do
generate_sitemap do
3.times { add '/', :last_modified => Time.now }
3.times { |i| add "/#{i}", :last_modified => Time.now }
end

assert_equal 3, num_elements(first_sitemap_file, 'lastmod')
end

should 'contain several changefreq elements' do
generate_sitemap do
3.times { add '/' }
3.times { |i| add "/#{i}" }
end

assert_equal 3, num_elements(first_sitemap_file, 'changefreq')
end

should 'contain several priority elements' do
generate_sitemap do
3.times { add '/', :priority => 0.2 }
3.times { |i| add "/#{i}", :priority => 0.2 }
end

assert_equal 3, num_elements(first_sitemap_file, 'priority')
Expand All @@ -153,7 +153,7 @@ def teardown

should 'contain two loc element' do
generate_sitemap(:max_per_sitemap => 2) do
4.times { add '/' }
4.times { |i| add "/#{i}" }
end

assert_equal 2, num_elements(first_sitemap_file, 'loc')
Expand All @@ -162,7 +162,7 @@ def teardown

should 'contain two changefreq elements' do
generate_sitemap(:max_per_sitemap => 2) do
4.times { add '/' }
4.times { |i| add "/#{i}" }
end

assert_equal 2, num_elements(first_sitemap_file, 'changefreq')
Expand All @@ -171,7 +171,7 @@ def teardown

should 'contain two priority element' do
generate_sitemap(:max_per_sitemap => 2) do
4.times { add '/', :priority => 0.2 }
4.times { |i| add "/#{i}", :priority => 0.2 }
end

assert_equal 2, num_elements(first_sitemap_file, 'priority')
Expand All @@ -182,6 +182,14 @@ def teardown
generate_sitemap(:gzip => false) { add '/' }
assert File.exists?(unzipped_first_sitemap_file)
end

should 'contain unique elements' do
generate_sitemap do
2.times { add '/' }
end

assert_equal 1, num_elements(first_sitemap_file, 'url')
end
end

context 'sanatize XML chars' do
Expand Down

0 comments on commit 3ebc5b7

Please sign in to comment.