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,24 @@
1
+ require 'spec_helper'
2
+ require 'sitemap_generator/interpreter'
3
+
4
+ describe SitemapGenerator::Interpreter do
5
+ # The interpreter doesn't have the URL helpers included for some reason, so it
6
+ # fails when adding links. That messes up later specs unless we reset the sitemap object.
7
+ after :all do
8
+ SitemapGenerator::Sitemap.reset!
9
+ end
10
+
11
+ it "should find the config file if Rails.root doesn't end in a slash" do
12
+ SitemapGenerator::Utilities.with_warnings(nil) do
13
+ Rails = stub(:root => SitemapGenerator.app.root.to_s.sub(/\/$/, ''))
14
+ end
15
+ # Rails.expects(:root).returns(rails_root).at_least_once
16
+ lambda { SitemapGenerator::Interpreter.run }.should_not raise_exception(Errno::ENOENT)
17
+ end
18
+
19
+ it "should set the verbose option" do
20
+ SitemapGenerator::Interpreter.any_instance.expects(:instance_eval)
21
+ interpreter = SitemapGenerator::Interpreter.run(:verbose => true)
22
+ interpreter.instance_variable_get(:@linkset).verbose.should be_true
23
+ end
24
+ end
@@ -0,0 +1,606 @@
1
+ require 'spec_helper'
2
+
3
+ describe SitemapGenerator::LinkSet do
4
+ before :each do
5
+ @default_host = 'http://example.com'
6
+ @ls = SitemapGenerator::LinkSet.new
7
+ end
8
+
9
+ describe "initializer options" do
10
+ options = [:public_path, :sitemaps_path, :default_host, :filename, :search_engines]
11
+ values = [File.expand_path(SitemapGenerator.app.root + 'tmp/'), 'mobile/', 'http://myhost.com', :xxx, { :abc => '123' }]
12
+
13
+ options.zip(values).each do |option, value|
14
+ it "should set #{option} to #{value}" do
15
+ @ls = SitemapGenerator::LinkSet.new(option => value)
16
+ @ls.send(option).should == value
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "default options" do
22
+ default_options = {
23
+ :filename => :sitemap,
24
+ :sitemaps_path => nil,
25
+ :public_path => SitemapGenerator.app.root + 'public/',
26
+ :default_host => nil,
27
+ :include_index => true,
28
+ :include_root => true
29
+ }
30
+
31
+ default_options.each do |option, value|
32
+ it "#{option} should default to #{value}" do
33
+ @ls.send(option).should == value
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "include_root include_index option" do
39
+ it "should not include the root url" do
40
+ @ls = SitemapGenerator::LinkSet.new(:default_host => @default_host, :include_root => false)
41
+ @ls.include_root.should be_false
42
+ @ls.include_index.should be_true
43
+ @ls.add_links { |sitemap| }
44
+ @ls.sitemap.link_count.should == 1
45
+ end
46
+
47
+ it "should not include the sitemap index url" do
48
+ @ls = SitemapGenerator::LinkSet.new(:default_host => @default_host, :include_index => false)
49
+ @ls.include_root.should be_true
50
+ @ls.include_index.should be_false
51
+ @ls.add_links { |sitemap| }
52
+ @ls.sitemap.link_count.should == 1
53
+ end
54
+
55
+ it "should not include the root url or the sitemap index url" do
56
+ @ls = SitemapGenerator::LinkSet.new(:default_host => @default_host, :include_root => false, :include_index => false)
57
+ @ls.include_root.should be_false
58
+ @ls.include_index.should be_false
59
+ @ls.add_links { |sitemap| }
60
+ @ls.sitemap.link_count.should == 0
61
+ end
62
+ end
63
+
64
+ describe "sitemaps public_path" do
65
+ it "should default to public/" do
66
+ @ls.public_path.should == SitemapGenerator.app.root + 'public/'
67
+ @ls.sitemap.location.public_path.should == @ls.public_path
68
+ @ls.sitemap_index.location.public_path.should == @ls.public_path
69
+ end
70
+
71
+ it "should change when the public_path is changed" do
72
+ @ls.public_path = 'tmp'
73
+ @ls.sitemap.location.public_path.should == @ls.public_path
74
+ @ls.sitemap_index.location.public_path.should == @ls.public_path
75
+ end
76
+ end
77
+
78
+ describe "sitemaps url" do
79
+ it "should change when the default_host is changed" do
80
+ @ls.default_host = 'http://one.com'
81
+ @ls.default_host.should == 'http://one.com'
82
+ @ls.default_host.should == @ls.sitemap.location.host
83
+ @ls.default_host.should == @ls.sitemap_index.location.host
84
+ end
85
+
86
+ it "should change when the sitemaps_path is changed" do
87
+ @ls.default_host = 'http://one.com'
88
+ @ls.sitemaps_path = 'sitemaps/'
89
+ @ls.sitemap.location.url.should == 'http://one.com/sitemaps/sitemap1.xml.gz'
90
+ @ls.sitemap_index.location.url.should == 'http://one.com/sitemaps/sitemap_index.xml.gz'
91
+ end
92
+ end
93
+
94
+ describe "sitemap_index_url" do
95
+ it "should return the url to the index file" do
96
+ @ls.default_host = @default_host
97
+ @ls.sitemap_index.location.url.should == "#{@default_host}/sitemap_index.xml.gz"
98
+ @ls.sitemap_index_url.should == @ls.sitemap_index.location.url
99
+ end
100
+ end
101
+
102
+ describe "search_engines" do
103
+ it "should have search engines by default" do
104
+ @ls.search_engines.should be_a(Hash)
105
+ @ls.search_engines.size.should == 4
106
+ end
107
+
108
+ it "should support being modified" do
109
+ @ls.search_engines[:newengine] = 'abc'
110
+ @ls.search_engines.size.should == 5
111
+ end
112
+
113
+ it "should support being set to nil" do
114
+ ls = SitemapGenerator::LinkSet.new(:default_host => 'http://one.com', :search_engines => nil)
115
+ ls.search_engines.should be_a(Hash)
116
+ ls.search_engines.should be_empty
117
+ ls.search_engines = nil
118
+ ls.search_engines.should be_a(Hash)
119
+ ls.search_engines.should be_empty
120
+ end
121
+ end
122
+
123
+ describe "ping search engines" do
124
+ before do
125
+ @ls = SitemapGenerator::LinkSet.new :default_host => 'http://one.com'
126
+ end
127
+
128
+ it "should not fail" do
129
+ @ls.expects(:open).at_least_once
130
+ lambda { @ls.ping_search_engines }.should_not raise_error
131
+ end
132
+
133
+ it "should raise if no host is set" do
134
+ lambda { SitemapGenerator::LinkSet.new.ping_search_engines }.should raise_error(SitemapGenerator::SitemapError, 'No value set for host')
135
+ end
136
+
137
+ it "should use the sitemap index url provided" do
138
+ index_url = 'http://example.com/index.xml'
139
+ ls = SitemapGenerator::LinkSet.new(:search_engines => { :google => 'http://google.com/?url=%s' })
140
+ ls.expects(:open).with("http://google.com/?url=#{CGI.escape(index_url)}")
141
+ ls.ping_search_engines(index_url)
142
+ end
143
+
144
+ it "should use the sitemap index url from the link set" do
145
+ ls = SitemapGenerator::LinkSet.new(
146
+ :default_host => 'http://one.com',
147
+ :search_engines => { :google => 'http://google.com/?url=%s' })
148
+ index_url = ls.sitemap_index_url
149
+ ls.expects(:open).with("http://google.com/?url=#{CGI.escape(index_url)}")
150
+ ls.ping_search_engines(index_url)
151
+ end
152
+
153
+ it "should include the given search engines" do
154
+ @ls.search_engines = nil
155
+ @ls.expects(:open).with(regexp_matches(/^http:\/\/newnegine\.com\?/))
156
+ @ls.ping_search_engines(:newengine => 'http://newnegine.com?%s')
157
+
158
+ @ls.expects(:open).with(regexp_matches(/^http:\/\/newnegine\.com\?/)).twice
159
+ @ls.ping_search_engines(:newengine => 'http://newnegine.com?%s', :anotherengine => 'http://newnegine.com?%s')
160
+ end
161
+ end
162
+
163
+ describe "verbose" do
164
+ before do
165
+ @ls = SitemapGenerator::LinkSet.new(:default_host => 'http://one.com')
166
+ end
167
+
168
+ it "should be set as an initialize option" do
169
+ SitemapGenerator::LinkSet.new(:default_host => 'http://one.com', :verbose => false).verbose.should be_false
170
+ SitemapGenerator::LinkSet.new(:default_host => 'http://one.com', :verbose => true).verbose.should be_true
171
+ end
172
+
173
+ it "should be set as an accessor" do
174
+ @ls.verbose = true
175
+ @ls.verbose.should be_true
176
+ @ls.verbose = false
177
+ @ls.verbose.should be_false
178
+ end
179
+
180
+ it "should use SitemapGenerator.verbose as a default" do
181
+ SitemapGenerator.expects(:verbose).returns(true).at_least_once
182
+ SitemapGenerator::LinkSet.new.verbose.should be_true
183
+ SitemapGenerator.expects(:verbose).returns(false).at_least_once
184
+ SitemapGenerator::LinkSet.new.verbose.should be_false
185
+ end
186
+ end
187
+
188
+ describe "when finalizing" do
189
+ before do
190
+ @ls = SitemapGenerator::LinkSet.new(:default_host => 'http://one.com', :verbose => true)
191
+ end
192
+
193
+ it "should output summary lines" do
194
+ @ls.sitemap.expects(:finalize!)
195
+ @ls.sitemap.expects(:summary)
196
+ @ls.sitemap_index.expects(:finalize!)
197
+ @ls.sitemap_index.expects(:summary)
198
+ @ls.finalize!
199
+ end
200
+ end
201
+
202
+ describe "sitemaps host" do
203
+ before do
204
+ @new_host = 'http://wowza.com'
205
+ @ls = SitemapGenerator::LinkSet.new(:default_host => @default_host)
206
+ end
207
+
208
+ it "should have a host" do
209
+ @ls.default_host = @default_host
210
+ @ls.default_host.should == @default_host
211
+ end
212
+
213
+ it "should default to default host" do
214
+ @ls.sitemaps_host.should == @ls.default_host
215
+ end
216
+
217
+ it "should update the host in the sitemaps when changed" do
218
+ @ls.sitemaps_host = @new_host
219
+ @ls.sitemaps_host.should == @new_host
220
+ @ls.sitemap.location.host.should == @ls.sitemaps_host
221
+ @ls.sitemap_index.location.host.should == @ls.sitemaps_host
222
+ end
223
+
224
+ it "should not change the default host for links" do
225
+ @ls.sitemaps_host = @new_host
226
+ @ls.default_host.should == @default_host
227
+ end
228
+ end
229
+
230
+ describe "with a sitemap index specified" do
231
+ before :each do
232
+ @index = SitemapGenerator::Builder::SitemapIndexFile.new(:host => @default_host)
233
+ @ls = SitemapGenerator::LinkSet.new(:sitemap_index => @index, :sitemaps_host => 'http://newhost.com')
234
+ end
235
+
236
+ it "should not modify the index" do
237
+ @ls.filename = :newname
238
+ @ls.sitemap.location.filename.should =~ /newname/
239
+ @ls.sitemap_index.location.filename =~ /sitemap_index/
240
+ end
241
+
242
+ it "should not modify the index" do
243
+ @ls.sitemaps_host = 'http://newhost.com'
244
+ @ls.sitemap.location.host.should == 'http://newhost.com'
245
+ @ls.sitemap_index.location.host.should == @default_host
246
+ end
247
+
248
+ it "should not finalize the index" do
249
+ @ls.send(:finalize_sitemap_index!)
250
+ @ls.sitemap_index.finalized?.should be_false
251
+ end
252
+ end
253
+
254
+ describe "new group" do
255
+ before :each do
256
+ @ls = SitemapGenerator::LinkSet.new(:default_host => @default_host)
257
+ end
258
+
259
+ describe "general behaviour" do
260
+ it "should return a LinkSet" do
261
+ @ls.group.should be_a(SitemapGenerator::LinkSet)
262
+ end
263
+
264
+ it "should inherit the index" do
265
+ @ls.group.sitemap_index.should == @ls.sitemap_index
266
+ end
267
+
268
+ it "should protect the sitemap_index" do
269
+ @ls.group.instance_variable_get(:@protect_index).should be_true
270
+ end
271
+
272
+ it "should not allow chaning the public_path" do
273
+ @ls.group(:public_path => 'new/path/').public_path.to_s.should == @ls.public_path.to_s
274
+ end
275
+ end
276
+
277
+ describe "include_index" do
278
+ it "should set the value" do
279
+ @ls.group(:include_index => !@ls.include_index).include_index.should_not == @ls.include_index
280
+ end
281
+
282
+ it "should default to false" do
283
+ @ls.group.include_index.should be_false
284
+ end
285
+ end
286
+
287
+ describe "include_root" do
288
+ it "should set the value" do
289
+ @ls.group(:include_root => !@ls.include_root).include_root.should_not == @ls.include_root
290
+ end
291
+
292
+ it "should default to false" do
293
+ @ls.group.include_root.should be_false
294
+ end
295
+ end
296
+
297
+ describe "filename" do
298
+ it "should inherit the value" do
299
+ @ls.group.filename.should == :sitemap
300
+ end
301
+
302
+ it "should set the value" do
303
+ group = @ls.group(:filename => :xxx)
304
+ group.filename.should == :xxx
305
+ group.sitemap.location.filename.should =~ /xxx/
306
+ end
307
+ end
308
+
309
+ describe "verbose" do
310
+ it "should inherit the value" do
311
+ @ls.group.verbose.should == @ls.verbose
312
+ end
313
+
314
+ it "should set the value" do
315
+ @ls.group(:verbose => !@ls.verbose).verbose.should_not == @ls.verbose
316
+ end
317
+ end
318
+
319
+ describe "sitemaps_path" do
320
+ it "should inherit the sitemaps_path" do
321
+ group = @ls.group
322
+ group.sitemaps_path.should == @ls.sitemaps_path
323
+ group.sitemap.location.sitemaps_path.should == @ls.sitemap.location.sitemaps_path
324
+ end
325
+
326
+ it "should set the sitemaps_path" do
327
+ path = 'new/path'
328
+ group = @ls.group(:sitemaps_path => path)
329
+ group.sitemaps_path.should == path
330
+ group.sitemap.location.sitemaps_path.to_s.should == path
331
+ end
332
+ end
333
+
334
+ describe "default_host" do
335
+ it "should inherit the default_host" do
336
+ @ls.group.default_host.should == @default_host
337
+ end
338
+
339
+ it "should set the default_host" do
340
+ host = 'http://defaulthost.com'
341
+ group = @ls.group(:default_host => host)
342
+ group.default_host.should == host
343
+ group.sitemap.location.host.should == host
344
+ end
345
+ end
346
+
347
+ describe "sitemaps_host" do
348
+ it "should set the sitemaps host" do
349
+ @host = 'http://sitemaphost.com'
350
+ @group = @ls.group(:sitemaps_host => @host)
351
+ @group.sitemaps_host.should == @host
352
+ @group.sitemap.location.host.should == @host
353
+ end
354
+
355
+ it "should finalize the sitemap if it is the only option" do
356
+ @ls.expects(:finalize_sitemap!)
357
+ @ls.group(:sitemaps_host => 'http://test.com') {}
358
+ end
359
+
360
+ it "should use the same sitemaps_namer" do
361
+ @group = @ls.group(:sitemaps_host => 'http://test.com') {}
362
+ @group.sitemap.location.namer.should == @ls.sitemap.location.namer
363
+ end
364
+ end
365
+
366
+ describe "sitemaps_namer" do
367
+ it "should inherit the value" do
368
+ @ls.group.sitemaps_namer.should == @ls.sitemaps_namer
369
+ @ls.group.sitemap.location.namer.should == @ls.sitemaps_namer
370
+ end
371
+
372
+ it "should set the value" do
373
+ namer = SitemapGenerator::SitemapNamer.new(:xxx)
374
+ group = @ls.group(:sitemaps_namer => namer)
375
+ group.sitemaps_namer.should == namer
376
+ group.sitemap.location.namer.should == namer
377
+ group.sitemap.location.filename.should =~ /xxx/
378
+ end
379
+ end
380
+
381
+ describe "should share the current sitemap" do
382
+ it "if only default_host is passed" do
383
+ group = @ls.group(:default_host => 'http://newhost.com')
384
+ group.sitemap.should == @ls.sitemap
385
+ group.sitemap.location.host.should == 'http://newhost.com'
386
+ end
387
+ end
388
+
389
+ describe "should not share the current sitemap" do
390
+ {
391
+ :filename => :xxx,
392
+ :sitemaps_path => 'en/',
393
+ :filename => :example,
394
+ :sitemaps_namer => SitemapGenerator::SitemapNamer.new(:sitemap)
395
+ }.each do |key, value|
396
+ it "if #{key} is present" do
397
+ @ls.group(key => value).sitemap.should_not == @ls.sitemap
398
+ end
399
+ end
400
+ end
401
+
402
+ describe "finalizing" do
403
+ it "should finalize the sitemaps if a block is passed" do
404
+ @group = @ls.group
405
+ @group.sitemap.finalized?.should be_false
406
+ end
407
+
408
+ it "should only finalize the sitemaps if a block is passed" do
409
+ @group = @ls.group
410
+ @group.sitemap.finalized?.should be_false
411
+ end
412
+
413
+ it "should not finalize the sitemap if a group is created" do
414
+ @ls.create { group {} }
415
+ @ls.sitemap.empty?.should be_true
416
+ @ls.sitemap.finalized?.should be_false
417
+ end
418
+
419
+ {:sitemaps_path => 'en/',
420
+ :filename => :example,
421
+ :sitemaps_namer => SitemapGenerator::SitemapNamer.new(:sitemap)}.each do |k, v|
422
+
423
+ it "should not finalize the sitemap if #{k} is present" do
424
+ @ls.expects(:finalize_sitemap!).never
425
+ @ls.group(k => v) { }
426
+ end
427
+ end
428
+ end
429
+ end
430
+
431
+ describe "after create" do
432
+ before :each do
433
+ @ls = SitemapGenerator::LinkSet.new :default_host => @default_host
434
+ end
435
+
436
+ it "should finalize the sitemap index" do
437
+ @ls.create {}
438
+ @ls.sitemap_index.finalized?.should be_true
439
+ end
440
+
441
+ it "should finalize the sitemap" do
442
+ @ls.create {}
443
+ @ls.sitemap.finalized?.should be_true
444
+ end
445
+
446
+ it "should not finalize the sitemap if a group was created" do
447
+ @ls.instance_variable_set(:@created_group, true)
448
+ @ls.send(:finalize_sitemap!)
449
+ @ls.sitemap.finalized?.should be_false
450
+ end
451
+ end
452
+
453
+ describe "options to create" do
454
+ before :each do
455
+ @ls = SitemapGenerator::LinkSet.new(:default_host => @default_host)
456
+ @ls.expects(:finalize!)
457
+ end
458
+
459
+ it "should set include_index" do
460
+ original = @ls.include_index
461
+ @ls.create(:include_index => !original).include_index.should_not == original
462
+ end
463
+
464
+ it "should set include_root" do
465
+ original = @ls.include_root
466
+ @ls.create(:include_root => !original).include_root.should_not == original
467
+ end
468
+
469
+ it "should set the filename" do
470
+ ls = @ls.create(:filename => :xxx)
471
+ ls.filename.should == :xxx
472
+ ls.sitemap.location.filename.should =~ /xxx/
473
+ end
474
+
475
+ it "should set verbose" do
476
+ original = @ls.verbose
477
+ @ls.create(:verbose => !original).verbose.should_not == original
478
+ end
479
+
480
+ it "should set the sitemaps_path" do
481
+ path = 'new/path'
482
+ ls = @ls.create(:sitemaps_path => path)
483
+ ls.sitemaps_path.should == path
484
+ ls.sitemap.location.sitemaps_path.to_s.should == path
485
+ end
486
+
487
+ it "should set the default_host" do
488
+ host = 'http://defaulthost.com'
489
+ ls = @ls.create(:default_host => host)
490
+ ls.default_host.should == host
491
+ ls.sitemap.location.host.should == host
492
+ end
493
+
494
+ it "should set the sitemaps host" do
495
+ @host = 'http://sitemaphost.com'
496
+ ls = @ls.create(:sitemaps_host => @host)
497
+ ls.sitemaps_host.should == @host
498
+ ls.sitemap.location.host.should == @host
499
+ end
500
+
501
+ it "should set the sitemaps_namer" do
502
+ namer = SitemapGenerator::SitemapNamer.new(:xxx)
503
+ ls = @ls.create(:sitemaps_namer => namer)
504
+ ls.sitemaps_namer.should == namer
505
+ ls.sitemap.location.namer.should == namer
506
+ ls.sitemap.location.filename.should =~ /xxx/
507
+ end
508
+
509
+ it "should support both sitemaps_namer and filename options" do
510
+ namer = SitemapGenerator::SitemapNamer.new("sitemap1_")
511
+ ls = @ls.create(:sitemaps_namer => namer, :filename => "sitemap1")
512
+ ls.sitemaps_namer.should == namer
513
+ ls.sitemap.location.namer.should == namer
514
+ ls.sitemap.location.filename.should =~ /sitemap1_1/
515
+ ls.sitemap_index.location.filename.should =~ /sitemap1_index/
516
+ end
517
+
518
+ it "should support both sitemaps_namer and filename options no matter the order" do
519
+ namer = SitemapGenerator::SitemapNamer.new("sitemap1_")
520
+ options = {} #ActiveSupport::OrderedHash.new
521
+ options[:sitemaps_namer] = namer
522
+ options[:filename] = "sitemap1"
523
+ ls = @ls.create(options)
524
+ ls.sitemap.location.filename.should =~ /sitemap1_1/
525
+ ls.sitemap_index.location.filename.should =~ /sitemap1_index/
526
+ end
527
+ end
528
+
529
+ describe "reset!" do
530
+ it "should reset the sitemap namer" do
531
+ SitemapGenerator::Sitemap.sitemaps_namer.expects(:reset)
532
+ SitemapGenerator::Sitemap.create(:default_host => 'http://cnn.com')
533
+ end
534
+
535
+ it "should reset the default link variable" do
536
+ SitemapGenerator::Sitemap.instance_variable_set(:@added_default_links, true)
537
+ SitemapGenerator::Sitemap.create(:default_host => 'http://cnn.com')
538
+ SitemapGenerator::Sitemap.instance_variable_set(:@added_default_links, false)
539
+ end
540
+ end
541
+
542
+ describe "include_root?" do
543
+ it "should return false" do
544
+ @ls.include_root = false
545
+ @ls.include_root.should be_false
546
+ end
547
+
548
+ it "should return true" do
549
+ @ls.include_root = true
550
+ @ls.include_root.should be_true
551
+ end
552
+ end
553
+
554
+ describe "include_index?" do
555
+ let(:sitemaps_host) { 'http://amazon.com' }
556
+
557
+ before :each do
558
+ @ls.default_host = @default_host
559
+ end
560
+
561
+ it "should be true if no sitemaps_host set, or it is the same" do
562
+ @ls.include_index = true
563
+ @ls.sitemaps_host = @default_host
564
+ @ls.include_index?.should be_true
565
+
566
+ @ls.sitemaps_host = nil
567
+ @ls.include_index?.should be_true
568
+ end
569
+
570
+ it "should be false if include_index is false or sitemaps_host differs" do
571
+ @ls.include_index = false
572
+ @ls.sitemaps_host = @default_host
573
+ @ls.include_index?.should be_false
574
+
575
+ @ls.include_index = true
576
+ @ls.sitemaps_host = sitemaps_host
577
+ @ls.include_index?.should be_false
578
+ end
579
+
580
+ it "should return false" do
581
+ ls = SitemapGenerator::LinkSet.new(:default_host => @default_host, :sitemaps_host => sitemaps_host)
582
+ ls.include_index?.should be_false
583
+ end
584
+
585
+ it "should return true" do
586
+ ls = SitemapGenerator::LinkSet.new(:default_host => @default_host, :sitemaps_host => @default_host)
587
+ ls.include_index?.should be_true
588
+ end
589
+ end
590
+
591
+ describe "output" do
592
+ let(:ls) { SitemapGenerator::LinkSet.new }
593
+
594
+ it "should not output" do
595
+ ls.verbose = false
596
+ ls.expects(:puts).never
597
+ ls.send(:output, '')
598
+ end
599
+
600
+ it "should print the given string" do
601
+ ls.verbose = true
602
+ ls.expects(:puts).with('')
603
+ ls.send(:output, '')
604
+ end
605
+ end
606
+ end