sitemap_generator 4.0.alpha → 4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,7 +26,7 @@ describe SitemapGenerator::LinkSet do
26
26
  :default_host => nil,
27
27
  :include_index => false,
28
28
  :include_root => true,
29
- :create_index => true
29
+ :create_index => :auto
30
30
  }
31
31
 
32
32
  default_options.each do |option, value|
@@ -95,15 +95,15 @@ describe SitemapGenerator::LinkSet do
95
95
  it "should change when the sitemaps_path is changed" do
96
96
  ls.default_host = 'http://one.com'
97
97
  ls.sitemaps_path = 'sitemaps/'
98
- ls.sitemap.location.url.should == 'http://one.com/sitemaps/sitemap1.xml.gz'
99
- ls.sitemap_index.location.url.should == 'http://one.com/sitemaps/sitemap_index.xml.gz'
98
+ ls.sitemap.location.url.should == 'http://one.com/sitemaps/sitemap.xml.gz'
99
+ ls.sitemap_index.location.url.should == 'http://one.com/sitemaps/sitemap.xml.gz'
100
100
  end
101
101
  end
102
102
 
103
103
  describe "sitemap_index_url" do
104
104
  it "should return the url to the index file" do
105
105
  ls.default_host = default_host
106
- ls.sitemap_index.location.url.should == "#{default_host}/sitemap_index.xml.gz"
106
+ ls.sitemap_index.location.url.should == "#{default_host}/sitemap.xml.gz"
107
107
  ls.sitemap_index_url.should == ls.sitemap_index.location.url
108
108
  end
109
109
  end
@@ -187,7 +187,7 @@ describe SitemapGenerator::LinkSet do
187
187
  end
188
188
 
189
189
  describe "when finalizing" do
190
- let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :verbose => true) }
190
+ let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :verbose => true, :create_index => true) }
191
191
 
192
192
  it "should output summary lines" do
193
193
  ls.sitemap.expects(:summary)
@@ -230,7 +230,7 @@ describe SitemapGenerator::LinkSet do
230
230
  it "should not modify the index" do
231
231
  @ls.filename = :newname
232
232
  @ls.sitemap.location.filename.should =~ /newname/
233
- @ls.sitemap_index.location.filename =~ /sitemap_index/
233
+ @ls.sitemap_index.location.filename =~ /sitemap/
234
234
  end
235
235
 
236
236
  it "should not modify the index" do
@@ -520,7 +520,7 @@ describe SitemapGenerator::LinkSet do
520
520
  ls.sitemaps_namer.should == namer
521
521
  ls.sitemap.location.namer.should == namer
522
522
  ls.sitemap.location.filename.should =~ /sitemap1_1/
523
- ls.sitemap_index.location.filename.should =~ /sitemap1_index/
523
+ ls.sitemap_index.location.filename.should =~ /^sitemap1/
524
524
  end
525
525
 
526
526
  it "should support both sitemaps_namer and filename options no matter the order" do
@@ -530,7 +530,7 @@ describe SitemapGenerator::LinkSet do
530
530
  options[:filename] = "sitemap1"
531
531
  ls.create(options)
532
532
  ls.sitemap.location.filename.should =~ /sitemap1_1/
533
- ls.sitemap_index.location.filename.should =~ /sitemap1_index/
533
+ ls.sitemap_index.location.filename.should =~ /^sitemap1/
534
534
  end
535
535
 
536
536
  it "should not modify the options hash" do
@@ -547,7 +547,7 @@ describe SitemapGenerator::LinkSet do
547
547
 
548
548
  describe "reset!" do
549
549
  it "should reset the sitemap namer" do
550
- SitemapGenerator::Sitemap.sitemaps_namer.expects(:reset)
550
+ SitemapGenerator::Sitemap.namer.expects(:reset)
551
551
  SitemapGenerator::Sitemap.create(:default_host => 'http://cnn.com')
552
552
  end
553
553
 
@@ -556,6 +556,13 @@ describe SitemapGenerator::LinkSet do
556
556
  SitemapGenerator::Sitemap.create(:default_host => 'http://cnn.com')
557
557
  SitemapGenerator::Sitemap.instance_variable_set(:@added_default_links, false)
558
558
  end
559
+
560
+ it "should reset the deprecated sitemaps_namer, if set" do
561
+ ls.sitemaps_namer = stub(:reset => nil)
562
+ ls.sitemaps_namer.expects(:reset)
563
+ ls.send(:reset!)
564
+ end
565
+
559
566
  end
560
567
 
561
568
  describe "include_root?" do
@@ -720,6 +727,9 @@ describe SitemapGenerator::LinkSet do
720
727
  end
721
728
 
722
729
  describe "create_index" do
730
+ let(:location) { SitemapGenerator::SitemapLocation.new(:namer => SitemapGenerator::SitemapNamer.new(:sitemap), :public_path => 'tmp/', :sitemaps_path => 'test/', :host => 'http://example.com/') }
731
+ let(:sitemap) { SitemapGenerator::Builder::SitemapFile.new(location) }
732
+
723
733
  describe "when false" do
724
734
  let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :create_index => false) }
725
735
 
@@ -762,19 +772,52 @@ describe SitemapGenerator::LinkSet do
762
772
  ls.send(:finalize_sitemap!)
763
773
  end
764
774
 
765
- it "should not write the index when it has only one link" do
766
- ls.sitemap_index.add '/test', :host => default_host
775
+ it "should write the index when a link is added manually" do
776
+ ls.sitemap_index.add '/test'
777
+ ls.sitemap_index.empty?.should be_false
778
+ ls.send(:finalize_sitemap_index!)
779
+ ls.sitemap_index.written?.should be_true
780
+ end
781
+
782
+ it "should not write the index when only one sitemap is added (considered internal usage)" do
783
+ ls.sitemap_index.add sitemap
767
784
  ls.sitemap_index.empty?.should be_false
768
785
  ls.send(:finalize_sitemap_index!)
769
786
  ls.sitemap_index.written?.should be_false
770
787
  end
771
788
 
789
+ it "should write the index when more than one sitemap is added (considered internal usage)" do
790
+ ls.sitemap_index.add sitemap
791
+ ls.sitemap_index.add sitemap.new
792
+ ls.send(:finalize_sitemap_index!)
793
+ ls.sitemap_index.written?.should be_true
794
+ end
795
+
772
796
  it "should write the index when it has more than one link" do
773
- ls.sitemap_index.add '/test1', :host => default_host
774
- ls.sitemap_index.add '/test2', :host => default_host
797
+ ls.sitemap_index.add '/test1'
798
+ ls.sitemap_index.add '/test2'
775
799
  ls.send(:finalize_sitemap_index!)
776
800
  ls.sitemap_index.written?.should be_true
777
801
  end
778
802
  end
779
803
  end
804
+
805
+ describe "when sitemap empty" do
806
+ before :each do
807
+ ls.include_root = false
808
+ end
809
+
810
+ it "should not be written" do
811
+ ls.sitemap.empty?.should be_true
812
+ ls.expects(:add_to_index).never
813
+ ls.send(:finalize_sitemap!)
814
+ end
815
+
816
+ it "should be written" do
817
+ ls.sitemap.add '/test'
818
+ ls.sitemap.empty?.should be_false
819
+ ls.expects(:add_to_index).with(ls.sitemap)
820
+ ls.send(:finalize_sitemap!)
821
+ end
822
+ end
780
823
  end
@@ -40,42 +40,77 @@ describe "SitemapGenerator" do
40
40
  end
41
41
  end
42
42
 
43
- [:deprecated, :create].each do |extension|
44
- describe "generate sitemap" do
45
- before :all do
46
- SitemapGenerator::Sitemap.reset!
47
- clean_sitemap_files_from_rails_app
48
- copy_sitemap_file_to_rails_app(extension)
49
- with_max_links(10) { execute_sitemap_config }
50
- end
43
+ describe "generate sitemap with deprecated config" do
44
+ before :all do
45
+ SitemapGenerator::Sitemap.reset!
46
+ clean_sitemap_files_from_rails_app
47
+ copy_sitemap_file_to_rails_app(:deprecated)
48
+ with_max_links(10) { execute_sitemap_config }
49
+ end
51
50
 
52
- it "should create sitemaps" do
53
- file_should_exist(rails_path('public/sitemap_index.xml.gz'))
54
- file_should_exist(rails_path('public/sitemap1.xml.gz'))
55
- file_should_exist(rails_path('public/sitemap2.xml.gz'))
56
- file_should_not_exist(rails_path('public/sitemap3.xml.gz'))
57
- end
51
+ it "should create sitemaps" do
52
+ file_should_exist(rails_path('public/sitemap_index.xml.gz'))
53
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
54
+ file_should_exist(rails_path('public/sitemap2.xml.gz'))
55
+ file_should_not_exist(rails_path('public/sitemap3.xml.gz'))
56
+ end
58
57
 
59
- it "should have 13 links" do
60
- SitemapGenerator::Sitemap.link_count.should == 13
61
- end
58
+ it "should have 13 links" do
59
+ SitemapGenerator::Sitemap.link_count.should == 13
60
+ end
62
61
 
63
- it "index XML should validate" do
64
- gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap_index.xml.gz'), 'siteindex'
65
- end
62
+ it "index XML should validate" do
63
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap_index.xml.gz'), 'siteindex'
64
+ end
66
65
 
67
- it "sitemap XML should validate" do
68
- gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap1.xml.gz'), 'sitemap'
69
- gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap2.xml.gz'), 'sitemap'
70
- end
66
+ it "sitemap XML should validate" do
67
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap1.xml.gz'), 'sitemap'
68
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap2.xml.gz'), 'sitemap'
69
+ end
71
70
 
72
- it "index XML should not have excess whitespace" do
73
- gzipped_xml_file_should_have_minimal_whitespace rails_path('public/sitemap_index.xml.gz')
74
- end
71
+ it "index XML should not have excess whitespace" do
72
+ gzipped_xml_file_should_have_minimal_whitespace rails_path('public/sitemap_index.xml.gz')
73
+ end
75
74
 
76
- it "sitemap XML should not have excess whitespace" do
77
- gzipped_xml_file_should_have_minimal_whitespace rails_path('public/sitemap1.xml.gz')
78
- end
75
+ it "sitemap XML should not have excess whitespace" do
76
+ gzipped_xml_file_should_have_minimal_whitespace rails_path('public/sitemap1.xml.gz')
77
+ end
78
+ end
79
+
80
+ describe "generate sitemap with normal config" do
81
+ before :all do
82
+ SitemapGenerator::Sitemap.reset!
83
+ clean_sitemap_files_from_rails_app
84
+ copy_sitemap_file_to_rails_app(:create)
85
+ with_max_links(10) { execute_sitemap_config }
86
+ end
87
+
88
+ it "should create sitemaps" do
89
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
90
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
91
+ file_should_exist(rails_path('public/sitemap2.xml.gz'))
92
+ file_should_not_exist(rails_path('public/sitemap3.xml.gz'))
93
+ end
94
+
95
+ it "should have 13 links" do
96
+ SitemapGenerator::Sitemap.link_count.should == 13
97
+ end
98
+
99
+ it "index XML should validate" do
100
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
101
+ end
102
+
103
+ it "sitemap XML should validate" do
104
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap1.xml.gz'), 'sitemap'
105
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap2.xml.gz'), 'sitemap'
106
+ end
107
+
108
+ it "index XML should not have excess whitespace" do
109
+ gzipped_xml_file_should_have_minimal_whitespace rails_path('public/sitemap.xml.gz')
110
+ end
111
+
112
+ it "sitemap XML should not have excess whitespace" do
113
+ gzipped_xml_file_should_have_minimal_whitespace rails_path('public/sitemap1.xml.gz')
79
114
  end
80
115
  end
81
116
 
@@ -86,34 +121,35 @@ describe "SitemapGenerator" do
86
121
  copy_sitemap_file_to_rails_app(:groups)
87
122
  with_max_links(2) { execute_sitemap_config }
88
123
  @expected = %w[
89
- public/en/xxx1.xml.gz
124
+ public/en/xxx.xml.gz
90
125
  public/fr/abc3.xml.gz
91
126
  public/fr/abc4.xml.gz
92
- public/fr/new_sitemaps_index.xml.gz
127
+ public/fr/def.xml.gz
128
+ public/fr/new_sitemaps.xml.gz
93
129
  public/fr/new_sitemaps1.xml.gz
94
130
  public/fr/new_sitemaps2.xml.gz
95
131
  public/fr/new_sitemaps3.xml.gz
96
132
  public/fr/new_sitemaps4.xml.gz]
97
- @sitemaps = (@expected - %w[public/fr/new_sitemaps_index.xml.gz])
133
+ @sitemaps = (@expected - %w[public/fr/new_sitemaps.xml.gz])
98
134
  end
99
135
 
100
136
  it "should create sitemaps" do
101
137
  @expected.each { |file| file_should_exist(rails_path(file)) }
102
138
  file_should_not_exist(rails_path('public/fr/new_sitemaps5.xml.gz'))
103
- file_should_not_exist(rails_path('public/en/xxx2.xml.gz'))
139
+ file_should_not_exist(rails_path('public/en/xxx1.xml.gz'))
104
140
  file_should_not_exist(rails_path('public/fr/abc5.xml.gz'))
105
141
  end
106
142
 
107
- it "should have 13 links" do
108
- SitemapGenerator::Sitemap.link_count.should == 13
143
+ it "should have 16 links" do
144
+ SitemapGenerator::Sitemap.link_count.should == 16
109
145
  end
110
146
 
111
147
  it "index XML should validate" do
112
- gzipped_xml_file_should_validate_against_schema rails_path('public/fr/new_sitemaps_index.xml.gz'), 'siteindex'
148
+ gzipped_xml_file_should_validate_against_schema rails_path('public/fr/new_sitemaps.xml.gz'), 'siteindex'
113
149
  end
114
150
 
115
151
  it "index XML should not have excess whitespace" do
116
- gzipped_xml_file_should_have_minimal_whitespace rails_path('public/fr/new_sitemaps_index.xml.gz')
152
+ gzipped_xml_file_should_have_minimal_whitespace rails_path('public/fr/new_sitemaps.xml.gz')
117
153
  end
118
154
 
119
155
  it "sitemaps XML should validate" do
@@ -125,12 +161,119 @@ describe "SitemapGenerator" do
125
161
  end
126
162
  end
127
163
 
164
+ describe "should handle links added manually" do
165
+ before :each do
166
+ clean_sitemap_files_from_rails_app
167
+ ::SitemapGenerator::Sitemap.reset!
168
+ ::SitemapGenerator::Sitemap.default_host = "http://www.example.com"
169
+ ::SitemapGenerator::Sitemap.namer = ::SitemapGenerator::SimpleNamer.new(:sitemap, :start => 4)
170
+ ::SitemapGenerator::Sitemap.create do
171
+ 3.times do |i|
172
+ add_to_index "sitemap#{i}.xml.gz"
173
+ end
174
+ add '/home'
175
+ end
176
+ end
177
+
178
+ it "should create the index and start the sitemap numbering from 4" do
179
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
180
+ file_should_exist(rails_path('public/sitemap4.xml.gz'))
181
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
182
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap4.xml.gz'), 'sitemap'
183
+ end
184
+ end
185
+
186
+ describe "should handle links added manually" do
187
+ before :each do
188
+ clean_sitemap_files_from_rails_app
189
+ ::SitemapGenerator::Sitemap.reset!
190
+ ::SitemapGenerator::Sitemap.default_host = "http://www.example.com"
191
+ ::SitemapGenerator::Sitemap.include_root = false
192
+ end
193
+
194
+ it "should create the index" do
195
+ with_max_links(1) {
196
+ ::SitemapGenerator::Sitemap.create do
197
+ add_to_index "customsitemap.xml.gz"
198
+ add '/one'
199
+ add '/two'
200
+ end
201
+ }
202
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
203
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
204
+ file_should_exist(rails_path('public/sitemap2.xml.gz'))
205
+ file_should_not_exist(rails_path('public/sitemap3.xml.gz'))
206
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
207
+ end
208
+
209
+ it "should create the index" do
210
+ with_max_links(1) {
211
+ ::SitemapGenerator::Sitemap.create do
212
+ add '/one'
213
+ add_to_index "customsitemap.xml.gz"
214
+ add '/two'
215
+ end
216
+ }
217
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
218
+ file_should_exist(rails_path('public/sitemap1.xml.gz'))
219
+ file_should_exist(rails_path('public/sitemap2.xml.gz'))
220
+ file_should_not_exist(rails_path('public/sitemap3.xml.gz'))
221
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
222
+ end
223
+
224
+ it "should create an index when only manually added links" do
225
+ with_max_links(1) {
226
+ ::SitemapGenerator::Sitemap.create(:create_index => :auto) do
227
+ add_to_index "customsitemap1.xml.gz"
228
+ end
229
+ }
230
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
231
+ file_should_not_exist(rails_path('public/sitemap1.xml.gz'))
232
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
233
+ end
234
+
235
+ it "should create an index when only manually added links" do
236
+ with_max_links(1) {
237
+ ::SitemapGenerator::Sitemap.create(:create_index => :auto) do
238
+ add_to_index "customsitemap1.xml.gz"
239
+ add_to_index "customsitemap2.xml.gz"
240
+ add_to_index "customsitemap3.xml.gz"
241
+ end
242
+ }
243
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
244
+ file_should_not_exist(rails_path('public/sitemap1.xml.gz'))
245
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
246
+ end
247
+
248
+ it "should not create an index" do
249
+ # Create index is explicity turned off and no links added to sitemap,
250
+ # respect the setting and don't create the index. There is no sitemap file either.
251
+ ::SitemapGenerator::Sitemap.create(:create_index => false) do
252
+ add_to_index "customsitemap1.xml.gz"
253
+ add_to_index "customsitemap2.xml.gz"
254
+ add_to_index "customsitemap3.xml.gz"
255
+ end
256
+ file_should_not_exist(rails_path('public/sitemap.xml.gz'))
257
+ file_should_not_exist(rails_path('public/sitemap1.xml.gz'))
258
+ end
259
+
260
+ it "should not create an index" do
261
+ ::SitemapGenerator::Sitemap.create(:create_index => false) do
262
+ add '/one'
263
+ end
264
+ file_should_exist(rails_path('public/sitemap.xml.gz')) # the sitemap, not an index
265
+ file_should_not_exist(rails_path('public/sitemap1.xml.gz'))
266
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'sitemap'
267
+ end
268
+ end
269
+
128
270
  describe "sitemap path" do
129
271
  before :each do
130
272
  clean_sitemap_files_from_rails_app
131
273
  ::SitemapGenerator::Sitemap.reset!
132
274
  ::SitemapGenerator::Sitemap.default_host = 'http://test.local'
133
275
  ::SitemapGenerator::Sitemap.filename = 'sitemap'
276
+ ::SitemapGenerator::Sitemap.create_index = true
134
277
  end
135
278
 
136
279
  it "should allow changing of the filename" do
@@ -138,7 +281,7 @@ describe "SitemapGenerator" do
138
281
  add '/goerss', :geo => { :format => 'georss' }
139
282
  add '/kml', :geo => { :format => 'kml' }
140
283
  end
141
- file_should_exist(rails_path('public/geo_sitemap_index.xml.gz'))
284
+ file_should_exist(rails_path('public/geo_sitemap.xml.gz'))
142
285
  file_should_exist(rails_path('public/geo_sitemap1.xml.gz'))
143
286
  end
144
287
 
@@ -152,7 +295,7 @@ describe "SitemapGenerator" do
152
295
  add '/another'
153
296
  end
154
297
 
155
- file_should_exist(rails_path('public/sitemaps/sitemap_index.xml.gz'))
298
+ file_should_exist(rails_path('public/sitemaps/sitemap.xml.gz'))
156
299
  file_should_exist(rails_path('public/sitemaps/sitemap1.xml.gz'))
157
300
  end
158
301
 
@@ -167,7 +310,7 @@ describe "SitemapGenerator" do
167
310
  add '/yet-another'
168
311
  end
169
312
 
170
- file_should_exist(rails_path('public/sitemaps/deep/directory/sitemap_index.xml.gz'))
313
+ file_should_exist(rails_path('public/sitemaps/deep/directory/sitemap.xml.gz'))
171
314
  file_should_exist(rails_path('public/sitemaps/deep/directory/sitemap1.xml.gz'))
172
315
  end
173
316
  end
@@ -203,7 +346,6 @@ describe "SitemapGenerator" do
203
346
  end
204
347
 
205
348
  describe "create_index" do
206
-
207
349
  before :each do
208
350
  clean_sitemap_files_from_rails_app
209
351
  end
@@ -211,87 +353,92 @@ describe "SitemapGenerator" do
211
353
  describe "when true" do
212
354
  let(:ls) { SitemapGenerator::LinkSet.new(:include_root => false, :default_host => 'http://example.com', :create_index => true) }
213
355
 
214
- it "should always create index" do
215
- ls.create { }
216
- file_should_exist(rails_path('public/sitemap_index.xml.gz'))
217
- file_should_exist(rails_path('public/sitemap1.xml.gz'))
218
- file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
219
- end
220
-
221
356
  it "should always create index" do
222
357
  with_max_links(1) do
223
358
  ls.create { add('/one') }
224
359
  end
225
- file_should_exist(rails_path('public/sitemap_index.xml.gz'))
360
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
226
361
  file_should_exist(rails_path('public/sitemap1.xml.gz'))
227
362
  file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
363
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
364
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap1.xml.gz'), 'sitemap'
228
365
  end
229
366
 
230
367
  it "should always create index" do
231
368
  with_max_links(1) do
232
369
  ls.create { add('/one'); add('/two') }
233
370
  end
234
- file_should_exist(rails_path('public/sitemap_index.xml.gz'))
371
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
235
372
  file_should_exist(rails_path('public/sitemap1.xml.gz'))
236
373
  file_should_exist(rails_path('public/sitemap2.xml.gz'))
374
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
375
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap1.xml.gz'), 'sitemap'
376
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap2.xml.gz'), 'sitemap'
237
377
  end
238
378
  end
239
379
 
240
380
  describe "when false" do
241
381
  let(:ls) { SitemapGenerator::LinkSet.new(:include_root => false, :default_host => 'http://example.com', :create_index => false) }
242
382
 
243
- it "should never create index" do
244
- ls.create { }
245
- file_should_not_exist(rails_path('public/sitemap_index.xml.gz'))
246
- file_should_exist(rails_path('public/sitemap1.xml.gz'))
247
- file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
248
- end
249
-
250
383
  it "should never create index" do
251
384
  with_max_links(1) do
252
385
  ls.create { add('/one') }
253
386
  end
254
- file_should_not_exist(rails_path('public/sitemap_index.xml.gz'))
255
- file_should_exist(rails_path('public/sitemap1.xml.gz'))
256
- file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
387
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
388
+ file_should_not_exist(rails_path('public/sitemap1.xml.gz'))
389
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'sitemap'
257
390
  end
258
391
 
259
392
  it "should never create index" do
260
393
  with_max_links(1) do
261
394
  ls.create { add('/one'); add('/two') }
262
395
  end
263
- file_should_not_exist(rails_path('public/sitemap_index.xml.gz'))
396
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
264
397
  file_should_exist(rails_path('public/sitemap1.xml.gz'))
265
- file_should_exist(rails_path('public/sitemap2.xml.gz'))
398
+ file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
399
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'sitemap'
400
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap1.xml.gz'), 'sitemap'
266
401
  end
267
402
  end
268
403
 
269
404
  describe "when :auto" do
270
405
  let(:ls) { SitemapGenerator::LinkSet.new(:include_root => false, :default_host => 'http://example.com', :create_index => :auto) }
271
406
 
272
- it "should not create index if one sitemap file" do
273
- ls.create { }
274
- file_should_not_exist(rails_path('public/sitemap_index.xml.gz'))
275
- file_should_exist(rails_path('public/sitemap1.xml.gz'))
276
- file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
277
- end
278
-
279
- it "should not create index if one sitemap file" do
407
+ it "should not create index if only one sitemap file" do
280
408
  with_max_links(1) do
281
409
  ls.create { add('/one') }
282
410
  end
283
- file_should_not_exist(rails_path('public/sitemap_index.xml.gz'))
284
- file_should_exist(rails_path('public/sitemap1.xml.gz'))
285
- file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
411
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
412
+ file_should_not_exist(rails_path('public/sitemap1.xml.gz'))
413
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'sitemap'
286
414
  end
287
415
 
288
416
  it "should create index if more than one sitemap file" do
289
417
  with_max_links(1) do
290
418
  ls.create { add('/one'); add('/two') }
291
419
  end
292
- file_should_exist(rails_path('public/sitemap_index.xml.gz'))
420
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
293
421
  file_should_exist(rails_path('public/sitemap1.xml.gz'))
294
422
  file_should_exist(rails_path('public/sitemap2.xml.gz'))
423
+ file_should_not_exist(rails_path('public/sitemap3.xml.gz'))
424
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
425
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap1.xml.gz'), 'sitemap'
426
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap2.xml.gz'), 'sitemap'
427
+ end
428
+
429
+ it "should create index if more than one group" do
430
+ with_max_links(1) do
431
+ ls.create do
432
+ group(:filename => :group1) { add('/one') };
433
+ group(:filename => :group2) { add('/two') };
434
+ end
435
+ end
436
+ file_should_exist(rails_path('public/sitemap.xml.gz'))
437
+ file_should_exist(rails_path('public/group1.xml.gz'))
438
+ file_should_exist(rails_path('public/group2.xml.gz'))
439
+ gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
440
+ gzipped_xml_file_should_validate_against_schema rails_path('public/group1.xml.gz'), 'sitemap'
441
+ gzipped_xml_file_should_validate_against_schema rails_path('public/group2.xml.gz'), 'sitemap'
295
442
  end
296
443
  end
297
444
  end