sitemap_generator 2.2.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. data/Gemfile +9 -24
  2. data/Gemfile.lock +23 -58
  3. data/README.md +56 -75
  4. data/Rakefile +29 -117
  5. data/VERSION +1 -1
  6. data/lib/sitemap_generator.rb +24 -8
  7. data/lib/sitemap_generator/application.rb +31 -4
  8. data/lib/sitemap_generator/builder.rb +0 -6
  9. data/lib/sitemap_generator/builder/sitemap_file.rb +16 -6
  10. data/lib/sitemap_generator/builder/sitemap_index_file.rb +4 -3
  11. data/lib/sitemap_generator/builder/sitemap_index_url.rb +1 -1
  12. data/lib/sitemap_generator/builder/sitemap_url.rb +6 -8
  13. data/lib/sitemap_generator/core_ext.rb +3 -0
  14. data/lib/sitemap_generator/core_ext/big_decimal.rb +45 -0
  15. data/lib/sitemap_generator/core_ext/numeric.rb +48 -0
  16. data/lib/sitemap_generator/helpers/number_helper.rb +237 -0
  17. data/lib/sitemap_generator/interpreter.rb +1 -1
  18. data/lib/sitemap_generator/link_set.rb +39 -18
  19. data/lib/sitemap_generator/railtie.rb +2 -2
  20. data/lib/sitemap_generator/sitemap_namer.rb +1 -1
  21. data/lib/sitemap_generator/tasks.rb +53 -1
  22. data/lib/sitemap_generator/utilities.rb +107 -1
  23. data/lib/tasks/sitemap_generator_tasks.rake +1 -0
  24. data/spec/blueprint.rb +15 -0
  25. data/spec/files/sitemap.create.rb +12 -0
  26. data/spec/files/sitemap.deprecated.rb +13 -0
  27. data/spec/files/sitemap.groups.rb +37 -0
  28. data/spec/sitemap_generator/application_spec.rb +69 -0
  29. data/spec/sitemap_generator/builder/sitemap_file_spec.rb +77 -0
  30. data/spec/sitemap_generator/builder/sitemap_index_file_spec.rb +38 -0
  31. data/spec/sitemap_generator/builder/sitemap_index_url_spec.rb +16 -0
  32. data/spec/sitemap_generator/builder/sitemap_url_spec.rb +152 -0
  33. data/spec/sitemap_generator/core_ext/bigdecimal_spec.rb +20 -0
  34. data/spec/sitemap_generator/core_ext/numeric_spec.rb +43 -0
  35. data/spec/sitemap_generator/geo_sitemap_spec.rb +30 -0
  36. data/spec/sitemap_generator/helpers/number_helper_spec.rb +191 -0
  37. data/spec/sitemap_generator/interpreter_spec.rb +24 -0
  38. data/spec/sitemap_generator/link_set_spec.rb +606 -0
  39. data/spec/sitemap_generator/news_sitemap_spec.rb +42 -0
  40. data/spec/sitemap_generator/sitemap_generator_spec.rb +232 -0
  41. data/spec/sitemap_generator/sitemap_groups_spec.rb +133 -0
  42. data/spec/sitemap_generator/sitemap_location_spec.rb +124 -0
  43. data/spec/sitemap_generator/sitemap_namer_spec.rb +61 -0
  44. data/spec/sitemap_generator/templates_spec.rb +24 -0
  45. data/spec/sitemap_generator/utilities/existence_spec.rb +26 -0
  46. data/spec/sitemap_generator/utilities/hash_spec.rb +57 -0
  47. data/spec/sitemap_generator/utilities/rounding_spec.rb +31 -0
  48. data/spec/sitemap_generator/utilities_spec.rb +50 -0
  49. data/spec/sitemap_generator/video_sitemap_spec.rb +103 -0
  50. data/spec/spec_helper.rb +20 -0
  51. data/spec/support/file_macros.rb +39 -0
  52. data/spec/support/schemas/siteindex.xsd +73 -0
  53. data/spec/support/schemas/sitemap-geo.xsd +41 -0
  54. data/spec/support/schemas/sitemap-news.xsd +159 -0
  55. data/spec/support/schemas/sitemap-video.xsd +409 -0
  56. data/spec/support/schemas/sitemap.xsd +115 -0
  57. data/spec/support/xml_macros.rb +55 -0
  58. metadata +141 -122
  59. data/tasks/sitemap_generator_tasks.rake +0 -43
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe "SitemapGenerator" do
4
+
5
+ it "should add the news sitemap element" do
6
+ loc = 'http://www.example.com/my_article.html'
7
+
8
+ news_xml_fragment = SitemapGenerator::Builder::SitemapUrl.new('my_article.html', {
9
+ :host => 'http://www.example.com',
10
+
11
+ :news => {
12
+ :publication_name => "Example",
13
+ :publication_language => "en",
14
+ :title => "My Article",
15
+ :keywords => "my article, articles about myself",
16
+ :stock_tickers => "SAO:PETR3",
17
+ :publication_date => "2011-08-22",
18
+ :access => "Subscription",
19
+ :genres => "PressRelease"
20
+ }
21
+ }).to_xml
22
+
23
+ doc = Nokogiri::XML.parse("<root xmlns:news='http://www.google.com/schemas/sitemap-news/0.9'>#{news_xml_fragment}</root>")
24
+
25
+ url = doc.at_xpath("//url")
26
+ loc = url.at_xpath("loc")
27
+ loc.text.should == 'http://www.example.com/my_article.html'
28
+
29
+ news = doc.at_xpath("//news:news")
30
+
31
+ news.at_xpath('//news:title').text.should == "My Article"
32
+ news.at_xpath("//news:keywords").text.should == "my article, articles about myself"
33
+ news.at_xpath("//news:stock_tickers").text.should == "SAO:PETR3"
34
+ news.at_xpath("//news:publication_date").text.should == "2011-08-22"
35
+ news.at_xpath("//news:access").text.should == "Subscription"
36
+ news.at_xpath("//news:genres").text.should == "PressRelease"
37
+ news.at_xpath("//news:name").text.should == "Example"
38
+ news.at_xpath("//news:language").text.should == "en"
39
+
40
+ xml_fragment_should_validate_against_schema(news, 'http://www.google.com/schemas/sitemap-news/0.9', 'sitemap-news')
41
+ end
42
+ end
@@ -0,0 +1,232 @@
1
+ require 'spec_helper'
2
+
3
+ class Holder
4
+ class << self
5
+ attr_accessor :executed
6
+ end
7
+ end
8
+
9
+ def with_max_links(num)
10
+ original = SitemapGenerator::MAX_SITEMAP_LINKS
11
+ SitemapGenerator.const_set(:MAX_SITEMAP_LINKS, num)
12
+ yield
13
+ SitemapGenerator.const_set(:MAX_SITEMAP_LINKS, original)
14
+ end
15
+
16
+ describe "SitemapGenerator" do
17
+
18
+ describe "reset!" do
19
+ before :each do
20
+ SitemapGenerator::Sitemap.default_host # Force initialization of the LinkSet
21
+ end
22
+
23
+ it "should set a new LinkSet instance" do
24
+ first = SitemapGenerator::Sitemap.instance_variable_get(:@link_set)
25
+ first.should be_a(SitemapGenerator::LinkSet)
26
+ SitemapGenerator::Sitemap.reset!
27
+ second = SitemapGenerator::Sitemap.instance_variable_get(:@link_set)
28
+ second.should be_a(SitemapGenerator::LinkSet)
29
+ first.should_not be(second)
30
+ end
31
+ end
32
+
33
+ describe "root" do
34
+ it "should be set to the root of the gem" do
35
+ SitemapGenerator.root.should == File.expand_path('../../../' , __FILE__)
36
+ end
37
+ end
38
+
39
+ [:deprecated, :create].each do |extension|
40
+ describe "generate sitemap" do
41
+ before :all do
42
+ SitemapGenerator::Sitemap.reset!
43
+ clean_sitemap_files_from_rails_app
44
+ copy_sitemap_file_to_rails_app(extension)
45
+ with_max_links(10) { execute_sitemap_config }
46
+ end
47
+
48
+ it "should create sitemaps" do
49
+ file_should_exist(rails_path('public/sitemap_index.xml.gz'))
50
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
51
+ file_should_exist(rails_path('public/sitemap2.xml.gz'))
52
+ file_should_not_exist(rails_path('public/sitemap3.xml.gz'))
53
+ end
54
+
55
+ it "should have 14 links" do
56
+ SitemapGenerator::Sitemap.link_count.should == 14
57
+ end
58
+
59
+ it "index XML should validate" do
60
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap_index.xml.gz'), 'siteindex'
61
+ end
62
+
63
+ it "sitemap XML should validate" do
64
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap1.xml.gz'), 'sitemap'
65
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap2.xml.gz'), 'sitemap'
66
+ end
67
+
68
+ it "index XML should not have excess whitespace" do
69
+ gzipped_xml_file_should_have_minimal_whitespace rails_path('public/sitemap_index.xml.gz')
70
+ end
71
+
72
+ it "sitemap XML should not have excess whitespace" do
73
+ gzipped_xml_file_should_have_minimal_whitespace rails_path('public/sitemap1.xml.gz')
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "sitemap with groups" do
79
+ before :all do
80
+ SitemapGenerator::Sitemap.reset!
81
+ clean_sitemap_files_from_rails_app
82
+ copy_sitemap_file_to_rails_app(:groups)
83
+ with_max_links(2) { execute_sitemap_config }
84
+ @expected = %w[
85
+ public/en/xxx1.xml.gz
86
+ public/fr/abc3.xml.gz
87
+ public/fr/abc4.xml.gz
88
+ public/fr/new_sitemaps_index.xml.gz
89
+ public/fr/new_sitemaps1.xml.gz
90
+ public/fr/new_sitemaps2.xml.gz
91
+ public/fr/new_sitemaps3.xml.gz
92
+ public/fr/new_sitemaps4.xml.gz]
93
+ @sitemaps = (@expected - %w[public/fr/new_sitemaps_index.xml.gz])
94
+ end
95
+
96
+ it "should create sitemaps" do
97
+ @expected.each { |file| file_should_exist(rails_path(file)) }
98
+ file_should_not_exist(rails_path('public/fr/new_sitemaps5.xml.gz'))
99
+ file_should_not_exist(rails_path('public/en/xxx2.xml.gz'))
100
+ file_should_not_exist(rails_path('public/fr/abc5.xml.gz'))
101
+ end
102
+
103
+ it "should have 14 links" do
104
+ SitemapGenerator::Sitemap.link_count.should == 13
105
+ end
106
+
107
+ it "index XML should validate" do
108
+ gzipped_xml_file_should_validate_against_schema rails_path('public/fr/new_sitemaps_index.xml.gz'), 'siteindex'
109
+ end
110
+
111
+ it "index XML should not have excess whitespace" do
112
+ gzipped_xml_file_should_have_minimal_whitespace rails_path('public/fr/new_sitemaps_index.xml.gz')
113
+ end
114
+
115
+ it "sitemaps XML should validate" do
116
+ @sitemaps.each { |file| gzipped_xml_file_should_validate_against_schema(rails_path(file), 'sitemap') }
117
+ end
118
+
119
+ it "sitemap XML should not have excess whitespace" do
120
+ @sitemaps.each { |file| gzipped_xml_file_should_have_minimal_whitespace(rails_path(file)) }
121
+ end
122
+ end
123
+
124
+ describe "sitemap path" do
125
+ before :each do
126
+ clean_sitemap_files_from_rails_app
127
+ ::SitemapGenerator::Sitemap.reset!
128
+ ::SitemapGenerator::Sitemap.default_host = 'http://test.local'
129
+ ::SitemapGenerator::Sitemap.filename = 'sitemap'
130
+ end
131
+
132
+ it "should allow changing of the filename" do
133
+ ::SitemapGenerator::Sitemap.create(:filename => :geo_sitemap) do
134
+ add '/goerss', :geo => { :format => 'georss' }
135
+ add '/kml', :geo => { :format => 'kml' }
136
+ end
137
+ file_should_exist(rails_path('public/geo_sitemap_index.xml.gz'))
138
+ file_should_exist(rails_path('public/geo_sitemap1.xml.gz'))
139
+ end
140
+
141
+ it "should support setting a sitemap path" do
142
+ directory_should_not_exist(rails_path('public/sitemaps/'))
143
+
144
+ sm = ::SitemapGenerator::Sitemap
145
+ sm.sitemaps_path = 'sitemaps/'
146
+ sm.create do
147
+ add '/'
148
+ add '/another'
149
+ end
150
+
151
+ file_should_exist(rails_path('public/sitemaps/sitemap_index.xml.gz'))
152
+ file_should_exist(rails_path('public/sitemaps/sitemap1.xml.gz'))
153
+ end
154
+
155
+ it "should support setting a deeply nested sitemap path" do
156
+ directory_should_not_exist(rails_path('public/sitemaps/deep/directory'))
157
+
158
+ sm = ::SitemapGenerator::Sitemap
159
+ sm.sitemaps_path = 'sitemaps/deep/directory/'
160
+ sm.create do
161
+ add '/'
162
+ add '/another'
163
+ add '/yet-another'
164
+ end
165
+
166
+ file_should_exist(rails_path('public/sitemaps/deep/directory/sitemap_index.xml.gz'))
167
+ file_should_exist(rails_path('public/sitemaps/deep/directory/sitemap1.xml.gz'))
168
+ end
169
+ end
170
+
171
+ describe "external dependencies" do
172
+ describe "rails" do
173
+ before :each do
174
+ @rails = Rails
175
+ Object.send(:remove_const, :Rails)
176
+ end
177
+
178
+ after :each do
179
+ Object::Rails = @rails
180
+ end
181
+
182
+ it "should work outside of Rails" do
183
+ defined?(Rails).should be_nil
184
+ lambda { ::SitemapGenerator::LinkSet.new }.should_not raise_exception
185
+ end
186
+ end
187
+ end
188
+
189
+ describe "verbose" do
190
+ it "should be set via ENV['VERBOSE']" do
191
+ original = SitemapGenerator.verbose
192
+ SitemapGenerator.verbose = nil
193
+ ENV['VERBOSE'] = 'true'
194
+ SitemapGenerator.verbose.should be_true
195
+ SitemapGenerator.verbose = nil
196
+ ENV['VERBOSE'] = 'false'
197
+ SitemapGenerator.verbose.should be_false
198
+ SitemapGenerator.verbose = original
199
+ end
200
+ end
201
+
202
+ protected
203
+
204
+ #
205
+ # Helpers
206
+ #
207
+
208
+ def rails_path(file)
209
+ SitemapGenerator.app.root + file
210
+ end
211
+
212
+ def copy_sitemap_file_to_rails_app(extension)
213
+ FileUtils.cp(File.join(SitemapGenerator.root, "spec/files/sitemap.#{extension}.rb"), SitemapGenerator.app.root + 'config/sitemap.rb')
214
+ end
215
+
216
+ def delete_sitemap_file_from_rails_app
217
+ FileUtils.remove(SitemapGenerator.app.root + 'config/sitemap.rb')
218
+ rescue
219
+ nil
220
+ end
221
+
222
+ def clean_sitemap_files_from_rails_app
223
+ FileUtils.rm_rf(rails_path('public/'))
224
+ FileUtils.mkdir_p(rails_path('public/'))
225
+ end
226
+
227
+ # Better would be to just invoke the environment task and use
228
+ # the interpreter.
229
+ def execute_sitemap_config
230
+ SitemapGenerator::Interpreter.run
231
+ end
232
+ end
@@ -0,0 +1,133 @@
1
+ require "spec_helper"
2
+
3
+ def with_max_links(num)
4
+ SitemapGenerator::Utilities.with_warnings(nil) do
5
+ original = SitemapGenerator::MAX_SITEMAP_LINKS
6
+ SitemapGenerator.const_set(:MAX_SITEMAP_LINKS, num)
7
+ yield
8
+ SitemapGenerator.const_set(:MAX_SITEMAP_LINKS, original)
9
+ end
10
+ end
11
+
12
+ describe "Sitemap Groups" do
13
+ before :each do
14
+ @sm = ::SitemapGenerator::LinkSet.new(:default_host => 'http://test.com')
15
+ FileUtils.rm_rf(SitemapGenerator.app.root + 'public/')
16
+ end
17
+
18
+ it "should not finalize the default sitemap if using groups" do
19
+ @sm.create do
20
+ group(:filename => :sitemap_en) do
21
+ add '/en'
22
+ end
23
+ end
24
+
25
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap_index.xml.gz')
26
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap_en1.xml.gz')
27
+ file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
28
+ end
29
+
30
+ it "should add default links if no groups are created" do
31
+ @sm.create do
32
+ end
33
+ @sm.link_count.should == 2
34
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap_index.xml.gz')
35
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
36
+ end
37
+
38
+ it "should add links to the default sitemap" do
39
+ @sm.create do
40
+ add '/before'
41
+ group(:filename => :sitemap_en) { }
42
+ add '/after'
43
+ end
44
+ @sm.link_count.should == 4
45
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap_index.xml.gz')
46
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
47
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap_en1.xml.gz')
48
+ end
49
+
50
+ it "should rollover when sitemaps are full" do
51
+ with_max_links(1) {
52
+ @sm.include_index = false
53
+ @sm.include_root = false
54
+ @sm.create do
55
+ add '/before'
56
+ group(:filename => :sitemap_en, :sitemaps_path => 'en/') do
57
+ add '/one'
58
+ add '/two'
59
+ end
60
+ add '/after'
61
+ end
62
+ }
63
+ @sm.link_count.should == 4
64
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap_index.xml.gz')
65
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
66
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap2.xml.gz')
67
+ file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap3.xml.gz')
68
+ file_should_exist(SitemapGenerator.app.root + 'public/en/sitemap_en1.xml.gz')
69
+ file_should_exist(SitemapGenerator.app.root + 'public/en/sitemap_en2.xml.gz')
70
+ file_should_not_exist(SitemapGenerator.app.root + 'public/en/sitemap_en3.xml.gz')
71
+ end
72
+
73
+ it "should support multiple groups" do
74
+ @sm.create do
75
+ group(:filename => :sitemap_en, :sitemaps_path => 'en/') do
76
+ add '/one'
77
+ end
78
+ group(:filename => :sitemap_fr, :sitemaps_path => 'fr/') do
79
+ add '/one'
80
+ end
81
+ end
82
+ @sm.link_count.should == 2
83
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap_index.xml.gz')
84
+ file_should_exist(SitemapGenerator.app.root + 'public/en/sitemap_en1.xml.gz')
85
+ file_should_exist(SitemapGenerator.app.root + 'public/fr/sitemap_fr1.xml.gz')
86
+ end
87
+
88
+ it "the sitemap shouldn't be finalized if the groups don't conflict" do
89
+ @sm.create do
90
+ add 'one'
91
+ group(:filename => :first) { add '/two' }
92
+ add 'three'
93
+ group(:filename => :second) { add '/four' }
94
+ add 'five'
95
+ end
96
+ @sm.link_count.should == 7
97
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap_index.xml.gz')
98
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
99
+ file_should_exist(SitemapGenerator.app.root + 'public/first1.xml.gz')
100
+ file_should_exist(SitemapGenerator.app.root + 'public/second1.xml.gz')
101
+ end
102
+
103
+ it "groups should share the sitemap if the sitemap location is unchanged" do
104
+ @sm.create do
105
+ add 'one'
106
+ group(:default_host => 'http://newhost.com') { add '/two' }
107
+ add 'three'
108
+ group(:default_host => 'http://betterhost.com') { add '/four' }
109
+ add 'five'
110
+ end
111
+ @sm.link_count.should == 7
112
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap_index.xml.gz')
113
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
114
+ file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap2.xml.gz')
115
+ end
116
+
117
+ it "sitemaps should be finalized if virtual location settings are changed" do
118
+ @sm.create do
119
+ add 'one'
120
+ group(:sitemaps_path => :en) { add '/two' }
121
+ add 'three'
122
+ group(:sitemaps_host => 'http://newhost.com') { add '/four' }
123
+ add 'five'
124
+ end
125
+ @sm.link_count.should == 7
126
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap_index.xml.gz')
127
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
128
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap2.xml.gz')
129
+ file_should_exist(SitemapGenerator.app.root + 'public/sitemap3.xml.gz')
130
+ file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap4.xml.gz')
131
+ file_should_exist(SitemapGenerator.app.root + 'public/en/sitemap1.xml.gz')
132
+ end
133
+ end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe SitemapGenerator::SitemapLocation do
4
+ before :all do
5
+ @default_host = 'http://example.com'
6
+ end
7
+
8
+ it "public_path should default to the public directory in the application root" do
9
+ @l = SitemapGenerator::SitemapLocation.new
10
+ @l.public_path.should == SitemapGenerator.app.root + 'public/'
11
+ end
12
+
13
+ it "should have a default namer" do
14
+ @l = SitemapGenerator::SitemapLocation.new
15
+ @l[:namer].should_not be_nil
16
+ @l[:filename].should be_nil
17
+ @l.filename.should == 'sitemap1.xml.gz'
18
+ end
19
+
20
+ it "should require a filename" do
21
+ @l = SitemapGenerator::SitemapLocation.new
22
+ @l[:filename] = nil
23
+ lambda {
24
+ @l.filename.should be_nil
25
+ }.should raise_error
26
+ end
27
+
28
+ it "should require a namer" do
29
+ @l = SitemapGenerator::SitemapLocation.new
30
+ @l[:namer] = nil
31
+ lambda {
32
+ @l.filename.should be_nil
33
+ }.should raise_error
34
+ end
35
+
36
+ it "should require a host" do
37
+ @l = SitemapGenerator::SitemapLocation.new(:filename => nil, :namer => nil)
38
+ lambda {
39
+ @l.host.should be_nil
40
+ }.should raise_error
41
+ end
42
+
43
+ it "should accept a Namer option" do
44
+ @namer = SitemapGenerator::SitemapNamer.new(:xxx)
45
+ @l = SitemapGenerator::SitemapLocation.new(:namer => @namer)
46
+ @l.filename.should == @namer.to_s
47
+ end
48
+
49
+ it "should protect the filename from further changes in the Namer" do
50
+ @namer = SitemapGenerator::SitemapNamer.new(:xxx)
51
+ @l = SitemapGenerator::SitemapLocation.new(:namer => @namer)
52
+ @l.filename.should == @namer.to_s
53
+ @namer.next
54
+ @l.filename.should == @namer.previous.to_s
55
+ end
56
+
57
+ it "should allow changing the namer" do
58
+ @namer1 = SitemapGenerator::SitemapNamer.new(:xxx)
59
+ @l = SitemapGenerator::SitemapLocation.new(:namer => @namer1)
60
+ @l.filename.should == @namer1.to_s
61
+ @namer2 = SitemapGenerator::SitemapNamer.new(:yyy)
62
+ @l[:namer] = @namer2
63
+ @l.filename.should == @namer2.to_s
64
+ end
65
+
66
+ describe "testing options and #with" do
67
+ before :all do
68
+ @l = SitemapGenerator::SitemapLocation.new
69
+ end
70
+
71
+ # Array of tuples with instance options and expected method return values
72
+ tests = [
73
+ [{
74
+ :sitemaps_path => nil,
75
+ :public_path => '/public',
76
+ :filename => 'sitemap1.xml.gz',
77
+ :host => 'http://test.com' },
78
+ { :url => 'http://test.com/sitemap1.xml.gz',
79
+ :directory => '/public',
80
+ :path => '/public/sitemap1.xml.gz',
81
+ :path_in_public => 'sitemap1.xml.gz'
82
+ }],
83
+ [{
84
+ :sitemaps_path => 'sitemaps/en/',
85
+ :public_path => '/public/system/',
86
+ :filename => 'sitemap1.xml.gz',
87
+ :host => 'http://test.com/plus/extra/' },
88
+ { :url => 'http://test.com/plus/extra/sitemaps/en/sitemap1.xml.gz',
89
+ :directory => '/public/system/sitemaps/en',
90
+ :path => '/public/system/sitemaps/en/sitemap1.xml.gz',
91
+ :path_in_public => 'sitemaps/en/sitemap1.xml.gz'
92
+ }]
93
+ ]
94
+ tests.each do |opts, returns|
95
+ returns.each do |method, value|
96
+ it "#{method} should return #{value}" do
97
+ @l.with(opts).send(method).should == value
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ describe "when duplicated" do
104
+ it "should not inherit some objects" do
105
+ @l = SitemapGenerator::SitemapLocation.new(:filename => 'xxx', :host => @default_host, :public_path => 'public/')
106
+ @l.url.should == @default_host+'/xxx'
107
+ @l.public_path.to_s.should == 'public/'
108
+ dup = @l.dup
109
+ dup.url.should == @l.url
110
+ dup.url.should_not be(@l.url)
111
+ dup.public_path.to_s.should == @l.public_path.to_s
112
+ dup.public_path.should_not be(@l.public_path)
113
+ end
114
+ end
115
+ end
116
+
117
+ describe SitemapGenerator::SitemapIndexLocation do
118
+ it "should have a default namer" do
119
+ @l = SitemapGenerator::SitemapIndexLocation.new
120
+ @l[:namer].should_not be_nil
121
+ @l[:filename].should be_nil
122
+ @l.filename.should == 'sitemap_index.xml.gz'
123
+ end
124
+ end