sitemap_generator_ftbpro 5.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +35 -0
- data/MIT-LICENSE +20 -0
- data/README.md +1139 -0
- data/Rakefile +43 -0
- data/VERSION +1 -0
- data/lib/capistrano/sitemap_generator.rb +1 -0
- data/lib/capistrano/tasks/sitemap_generator.cap +36 -0
- data/lib/sitemap_generator/adapters/file_adapter.rb +43 -0
- data/lib/sitemap_generator/adapters/fog_adapter.rb +28 -0
- data/lib/sitemap_generator/adapters/s3_adapter.rb +41 -0
- data/lib/sitemap_generator/adapters/wave_adapter.rb +21 -0
- data/lib/sitemap_generator/adapters.rb +0 -0
- data/lib/sitemap_generator/application.rb +49 -0
- data/lib/sitemap_generator/builder/sitemap_file.rb +171 -0
- data/lib/sitemap_generator/builder/sitemap_index_file.rb +149 -0
- data/lib/sitemap_generator/builder/sitemap_index_url.rb +28 -0
- data/lib/sitemap_generator/builder/sitemap_url.rb +250 -0
- data/lib/sitemap_generator/builder.rb +8 -0
- data/lib/sitemap_generator/core_ext/big_decimal.rb +45 -0
- data/lib/sitemap_generator/core_ext/numeric.rb +48 -0
- data/lib/sitemap_generator/core_ext.rb +3 -0
- data/lib/sitemap_generator/helpers/number_helper.rb +237 -0
- data/lib/sitemap_generator/interpreter.rb +80 -0
- data/lib/sitemap_generator/link_set.rb +665 -0
- data/lib/sitemap_generator/railtie.rb +7 -0
- data/lib/sitemap_generator/sitemap_location.rb +192 -0
- data/lib/sitemap_generator/sitemap_namer.rb +75 -0
- data/lib/sitemap_generator/tasks.rb +53 -0
- data/lib/sitemap_generator/templates.rb +41 -0
- data/lib/sitemap_generator/utilities.rb +181 -0
- data/lib/sitemap_generator.rb +82 -0
- data/lib/tasks/sitemap_generator_tasks.rake +1 -0
- data/rails/install.rb +2 -0
- data/rails/uninstall.rb +2 -0
- data/spec/blueprint.rb +15 -0
- data/spec/files/sitemap.create.rb +12 -0
- data/spec/files/sitemap.groups.rb +49 -0
- data/spec/sitemap_generator/adapters/s3_adapter_spec.rb +23 -0
- data/spec/sitemap_generator/alternate_sitemap_spec.rb +79 -0
- data/spec/sitemap_generator/application_spec.rb +69 -0
- data/spec/sitemap_generator/builder/sitemap_file_spec.rb +110 -0
- data/spec/sitemap_generator/builder/sitemap_index_file_spec.rb +124 -0
- data/spec/sitemap_generator/builder/sitemap_index_url_spec.rb +28 -0
- data/spec/sitemap_generator/builder/sitemap_url_spec.rb +186 -0
- data/spec/sitemap_generator/core_ext/bigdecimal_spec.rb +20 -0
- data/spec/sitemap_generator/core_ext/numeric_spec.rb +43 -0
- data/spec/sitemap_generator/file_adaptor_spec.rb +20 -0
- data/spec/sitemap_generator/geo_sitemap_spec.rb +30 -0
- data/spec/sitemap_generator/helpers/number_helper_spec.rb +196 -0
- data/spec/sitemap_generator/interpreter_spec.rb +90 -0
- data/spec/sitemap_generator/link_set_spec.rb +864 -0
- data/spec/sitemap_generator/mobile_sitemap_spec.rb +27 -0
- data/spec/sitemap_generator/news_sitemap_spec.rb +42 -0
- data/spec/sitemap_generator/pagemap_sitemap_spec.rb +57 -0
- data/spec/sitemap_generator/sitemap_generator_spec.rb +582 -0
- data/spec/sitemap_generator/sitemap_groups_spec.rb +144 -0
- data/spec/sitemap_generator/sitemap_location_spec.rb +210 -0
- data/spec/sitemap_generator/sitemap_namer_spec.rb +96 -0
- data/spec/sitemap_generator/templates_spec.rb +24 -0
- data/spec/sitemap_generator/utilities/existence_spec.rb +26 -0
- data/spec/sitemap_generator/utilities/hash_spec.rb +57 -0
- data/spec/sitemap_generator/utilities/rounding_spec.rb +31 -0
- data/spec/sitemap_generator/utilities_spec.rb +101 -0
- data/spec/sitemap_generator/video_sitemap_spec.rb +117 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/file_macros.rb +39 -0
- data/spec/support/schemas/siteindex.xsd +73 -0
- data/spec/support/schemas/sitemap-geo.xsd +41 -0
- data/spec/support/schemas/sitemap-mobile.xsd +32 -0
- data/spec/support/schemas/sitemap-news.xsd +159 -0
- data/spec/support/schemas/sitemap-pagemap.xsd +97 -0
- data/spec/support/schemas/sitemap-video.xsd +643 -0
- data/spec/support/schemas/sitemap.xsd +115 -0
- data/spec/support/xml_macros.rb +67 -0
- data/templates/sitemap.rb +27 -0
- metadata +226 -0
@@ -0,0 +1,864 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SitemapGenerator::LinkSet do
|
4
|
+
let(:default_host) { 'http://example.com' }
|
5
|
+
let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host) }
|
6
|
+
|
7
|
+
describe "initializer options" do
|
8
|
+
options = [:public_path, :sitemaps_path, :default_host, :filename, :search_engines]
|
9
|
+
values = [File.expand_path(SitemapGenerator.app.root + 'tmp/'), 'mobile/', 'http://myhost.com', :xxx, { :abc => '123' }]
|
10
|
+
|
11
|
+
options.zip(values).each do |option, value|
|
12
|
+
it "should set #{option} to #{value}" do
|
13
|
+
ls = SitemapGenerator::LinkSet.new(option => value)
|
14
|
+
ls.send(option).should == value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "default options" do
|
20
|
+
let(:ls) { SitemapGenerator::LinkSet.new }
|
21
|
+
|
22
|
+
default_options = {
|
23
|
+
:filename => :sitemap,
|
24
|
+
:sitemaps_path => nil,
|
25
|
+
:public_path => SitemapGenerator.app.root + 'public/',
|
26
|
+
:default_host => nil,
|
27
|
+
:include_index => false,
|
28
|
+
:include_root => true,
|
29
|
+
:create_index => :auto
|
30
|
+
}
|
31
|
+
|
32
|
+
default_options.each do |option, value|
|
33
|
+
it "#{option} should default to #{value}" do
|
34
|
+
ls.send(option).should == value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "include_root include_index option" do
|
40
|
+
it "should include the root url and the sitemap index url" do
|
41
|
+
ls = SitemapGenerator::LinkSet.new(:default_host => default_host, :include_root => true, :include_index => true)
|
42
|
+
ls.include_root.should be_true
|
43
|
+
ls.include_index.should be_true
|
44
|
+
ls.create { |sitemap| }
|
45
|
+
ls.sitemap.link_count.should == 2
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not include the root url" do
|
49
|
+
ls = SitemapGenerator::LinkSet.new(:default_host => default_host, :include_root => false)
|
50
|
+
ls.include_root.should be_false
|
51
|
+
ls.include_index.should be_false
|
52
|
+
ls.create { |sitemap| }
|
53
|
+
ls.sitemap.link_count.should == 0
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should not include the sitemap index url" do
|
57
|
+
ls = SitemapGenerator::LinkSet.new(:default_host => default_host, :include_index => false)
|
58
|
+
ls.include_root.should be_true
|
59
|
+
ls.include_index.should be_false
|
60
|
+
ls.create { |sitemap| }
|
61
|
+
ls.sitemap.link_count.should == 1
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not include the root url or the sitemap index url" do
|
65
|
+
ls = SitemapGenerator::LinkSet.new(:default_host => default_host, :include_root => false, :include_index => false)
|
66
|
+
ls.include_root.should be_false
|
67
|
+
ls.include_index.should be_false
|
68
|
+
ls.create { |sitemap| }
|
69
|
+
ls.sitemap.link_count.should == 0
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "sitemaps public_path" do
|
74
|
+
it "should default to public/" do
|
75
|
+
path = SitemapGenerator.app.root + 'public/'
|
76
|
+
ls.public_path.should == path
|
77
|
+
ls.sitemap.location.public_path.should == path
|
78
|
+
ls.sitemap_index.location.public_path.should == path
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should change when the public_path is changed" do
|
82
|
+
path = SitemapGenerator.app.root + 'tmp/'
|
83
|
+
ls.public_path = 'tmp/'
|
84
|
+
ls.public_path.should == path
|
85
|
+
ls.sitemap.location.public_path.should == path
|
86
|
+
ls.sitemap_index.location.public_path.should == path
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should append a slash to the path" do
|
90
|
+
path = SitemapGenerator.app.root + 'tmp/'
|
91
|
+
ls.public_path = 'tmp'
|
92
|
+
ls.public_path.should == path
|
93
|
+
ls.sitemap.location.public_path.should == path
|
94
|
+
ls.sitemap_index.location.public_path.should == path
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "sitemaps url" do
|
99
|
+
it "should change when the default_host is changed" do
|
100
|
+
ls.default_host = 'http://one.com'
|
101
|
+
ls.default_host.should == 'http://one.com'
|
102
|
+
ls.default_host.should == ls.sitemap.location.host
|
103
|
+
ls.default_host.should == ls.sitemap_index.location.host
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should change when the sitemaps_path is changed" do
|
107
|
+
ls.default_host = 'http://one.com'
|
108
|
+
ls.sitemaps_path = 'sitemaps/'
|
109
|
+
ls.sitemap.location.url.should == 'http://one.com/sitemaps/sitemap.xml.gz'
|
110
|
+
ls.sitemap_index.location.url.should == 'http://one.com/sitemaps/sitemap.xml.gz'
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should append a slash to the path" do
|
114
|
+
ls.default_host = 'http://one.com'
|
115
|
+
ls.sitemaps_path = 'sitemaps'
|
116
|
+
ls.sitemap.location.url.should == 'http://one.com/sitemaps/sitemap.xml.gz'
|
117
|
+
ls.sitemap_index.location.url.should == 'http://one.com/sitemaps/sitemap.xml.gz'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "sitemap_index_url" do
|
122
|
+
it "should return the url to the index file" do
|
123
|
+
ls.default_host = default_host
|
124
|
+
ls.sitemap_index.location.url.should == "#{default_host}/sitemap.xml.gz"
|
125
|
+
ls.sitemap_index_url.should == ls.sitemap_index.location.url
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "search_engines" do
|
130
|
+
it "should have search engines by default" do
|
131
|
+
ls.search_engines.should be_a(Hash)
|
132
|
+
ls.search_engines.size.should == 2
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should support being modified" do
|
136
|
+
ls.search_engines[:newengine] = 'abc'
|
137
|
+
ls.search_engines.size.should == 3
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should support being set to nil" do
|
141
|
+
ls = SitemapGenerator::LinkSet.new(:default_host => 'http://one.com', :search_engines => nil)
|
142
|
+
ls.search_engines.should be_a(Hash)
|
143
|
+
ls.search_engines.should be_empty
|
144
|
+
ls.search_engines = nil
|
145
|
+
ls.search_engines.should be_a(Hash)
|
146
|
+
ls.search_engines.should be_empty
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "ping search engines" do
|
151
|
+
it "should not fail" do
|
152
|
+
ls.expects(:open).at_least_once
|
153
|
+
lambda { ls.ping_search_engines }.should_not raise_error
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should raise if no host is set" do
|
157
|
+
lambda { SitemapGenerator::LinkSet.new.ping_search_engines }.should raise_error(SitemapGenerator::SitemapError, 'No value set for host')
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should use the sitemap index url provided" do
|
161
|
+
index_url = 'http://example.com/index.xml'
|
162
|
+
ls = SitemapGenerator::LinkSet.new(:search_engines => { :google => 'http://google.com/?url=%s' })
|
163
|
+
ls.expects(:open).with("http://google.com/?url=#{CGI.escape(index_url)}")
|
164
|
+
ls.ping_search_engines(index_url)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should use the sitemap index url from the link set" do
|
168
|
+
ls = SitemapGenerator::LinkSet.new(
|
169
|
+
:default_host => default_host,
|
170
|
+
:search_engines => { :google => 'http://google.com/?url=%s' })
|
171
|
+
index_url = ls.sitemap_index_url
|
172
|
+
ls.expects(:open).with("http://google.com/?url=#{CGI.escape(index_url)}")
|
173
|
+
ls.ping_search_engines
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should include the given search engines" do
|
177
|
+
ls.search_engines = nil
|
178
|
+
ls.expects(:open).with(regexp_matches(/^http:\/\/newnegine\.com\?/))
|
179
|
+
ls.ping_search_engines(:newengine => 'http://newnegine.com?%s')
|
180
|
+
|
181
|
+
ls.expects(:open).with(regexp_matches(/^http:\/\/newnegine\.com\?/)).twice
|
182
|
+
ls.ping_search_engines(:newengine => 'http://newnegine.com?%s', :anotherengine => 'http://newnegine.com?%s')
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "verbose" do
|
187
|
+
it "should be set as an initialize option" do
|
188
|
+
SitemapGenerator::LinkSet.new(:default_host => default_host, :verbose => false).verbose.should be_false
|
189
|
+
SitemapGenerator::LinkSet.new(:default_host => default_host, :verbose => true).verbose.should be_true
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should be set as an accessor" do
|
193
|
+
ls.verbose = true
|
194
|
+
ls.verbose.should be_true
|
195
|
+
ls.verbose = false
|
196
|
+
ls.verbose.should be_false
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should use SitemapGenerator.verbose as a default" do
|
200
|
+
SitemapGenerator.expects(:verbose).returns(true).at_least_once
|
201
|
+
SitemapGenerator::LinkSet.new.verbose.should be_true
|
202
|
+
SitemapGenerator.expects(:verbose).returns(false).at_least_once
|
203
|
+
SitemapGenerator::LinkSet.new.verbose.should be_false
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "when finalizing" do
|
208
|
+
let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :verbose => true, :create_index => true) }
|
209
|
+
|
210
|
+
it "should output summary lines" do
|
211
|
+
ls.sitemap.location.expects(:summary)
|
212
|
+
ls.sitemap_index.location.expects(:summary)
|
213
|
+
ls.finalize!
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "sitemaps host" do
|
218
|
+
let(:new_host) { 'http://wowza.com' }
|
219
|
+
|
220
|
+
it "should have a host" do
|
221
|
+
ls.default_host = default_host
|
222
|
+
ls.default_host.should == default_host
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should default to default host" do
|
226
|
+
ls.sitemaps_host.should == ls.default_host
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should update the host in the sitemaps when changed" do
|
230
|
+
ls.sitemaps_host = new_host
|
231
|
+
ls.sitemaps_host.should == new_host
|
232
|
+
ls.sitemap.location.host.should == ls.sitemaps_host
|
233
|
+
ls.sitemap_index.location.host.should == ls.sitemaps_host
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should not change the default host for links" do
|
237
|
+
ls.sitemaps_host = new_host
|
238
|
+
ls.default_host.should == default_host
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "with a sitemap index specified" do
|
243
|
+
before :each do
|
244
|
+
@index = SitemapGenerator::Builder::SitemapIndexFile.new(:host => default_host)
|
245
|
+
@ls = SitemapGenerator::LinkSet.new(:sitemap_index => @index, :sitemaps_host => 'http://newhost.com')
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should not modify the index" do
|
249
|
+
@ls.filename = :newname
|
250
|
+
@ls.sitemap.location.filename.should =~ /newname/
|
251
|
+
@ls.sitemap_index.location.filename =~ /sitemap/
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should not modify the index" do
|
255
|
+
@ls.sitemaps_host = 'http://newhost.com'
|
256
|
+
@ls.sitemap.location.host.should == 'http://newhost.com'
|
257
|
+
@ls.sitemap_index.location.host.should == default_host
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should not finalize the index" do
|
261
|
+
@ls.send(:finalize_sitemap_index!)
|
262
|
+
@ls.sitemap_index.finalized?.should be_false
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
describe "new group" do
|
267
|
+
describe "general behaviour" do
|
268
|
+
it "should return a LinkSet" do
|
269
|
+
ls.group.should be_a(SitemapGenerator::LinkSet)
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should inherit the index" do
|
273
|
+
ls.group.sitemap_index.should == ls.sitemap_index
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should protect the sitemap_index" do
|
277
|
+
ls.group.instance_variable_get(:@protect_index).should be_true
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should not allow chaning the public_path" do
|
281
|
+
ls.group(:public_path => 'new/path/').public_path.to_s.should == ls.public_path.to_s
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
describe "include_index" do
|
286
|
+
it "should set the value" do
|
287
|
+
ls.group(:include_index => !ls.include_index).include_index.should_not == ls.include_index
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should default to false" do
|
291
|
+
ls.group.include_index.should be_false
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
describe "include_root" do
|
296
|
+
it "should set the value" do
|
297
|
+
ls.group(:include_root => !ls.include_root).include_root.should_not == ls.include_root
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should default to false" do
|
301
|
+
ls.group.include_root.should be_false
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
describe "filename" do
|
306
|
+
it "should inherit the value" do
|
307
|
+
ls.group.filename.should == :sitemap
|
308
|
+
end
|
309
|
+
|
310
|
+
it "should set the value" do
|
311
|
+
group = ls.group(:filename => :xxx)
|
312
|
+
group.filename.should == :xxx
|
313
|
+
group.sitemap.location.filename.should =~ /xxx/
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
describe "verbose" do
|
318
|
+
it "should inherit the value" do
|
319
|
+
ls.group.verbose.should == ls.verbose
|
320
|
+
end
|
321
|
+
|
322
|
+
it "should set the value" do
|
323
|
+
ls.group(:verbose => !ls.verbose).verbose.should_not == ls.verbose
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
describe "sitemaps_path" do
|
328
|
+
it "should inherit the sitemaps_path" do
|
329
|
+
group = ls.group
|
330
|
+
group.sitemaps_path.should == ls.sitemaps_path
|
331
|
+
group.sitemap.location.sitemaps_path.should == ls.sitemap.location.sitemaps_path
|
332
|
+
end
|
333
|
+
|
334
|
+
it "should set the sitemaps_path" do
|
335
|
+
path = 'new/path'
|
336
|
+
group = ls.group(:sitemaps_path => path)
|
337
|
+
group.sitemaps_path.should == path
|
338
|
+
group.sitemap.location.sitemaps_path.to_s.should == 'new/path/'
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
describe "default_host" do
|
343
|
+
it "should inherit the default_host" do
|
344
|
+
ls.group.default_host.should == default_host
|
345
|
+
end
|
346
|
+
|
347
|
+
it "should set the default_host" do
|
348
|
+
host = 'http://defaulthost.com'
|
349
|
+
group = ls.group(:default_host => host)
|
350
|
+
group.default_host.should == host
|
351
|
+
group.sitemap.location.host.should == host
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
describe "sitemaps_host" do
|
356
|
+
it "should set the sitemaps host" do
|
357
|
+
@host = 'http://sitemaphost.com'
|
358
|
+
@group = ls.group(:sitemaps_host => @host)
|
359
|
+
@group.sitemaps_host.should == @host
|
360
|
+
@group.sitemap.location.host.should == @host
|
361
|
+
end
|
362
|
+
|
363
|
+
it "should finalize the sitemap if it is the only option" do
|
364
|
+
ls.expects(:finalize_sitemap!)
|
365
|
+
ls.group(:sitemaps_host => 'http://test.com') {}
|
366
|
+
end
|
367
|
+
|
368
|
+
it "should use the same namer" do
|
369
|
+
@group = ls.group(:sitemaps_host => 'http://test.com') {}
|
370
|
+
@group.sitemap.location.namer.should == ls.sitemap.location.namer
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
describe "namer" do
|
375
|
+
it "should inherit the value" do
|
376
|
+
ls.group.namer.should == ls.namer
|
377
|
+
ls.group.sitemap.location.namer.should == ls.namer
|
378
|
+
end
|
379
|
+
|
380
|
+
it "should set the value" do
|
381
|
+
namer = SitemapGenerator::SimpleNamer.new(:xxx)
|
382
|
+
group = ls.group(:namer => namer)
|
383
|
+
group.namer.should == namer
|
384
|
+
group.sitemap.location.namer.should == namer
|
385
|
+
group.sitemap.location.filename.should =~ /xxx/
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
describe "create_index" do
|
390
|
+
it "should inherit the value" do
|
391
|
+
ls.group.create_index.should == ls.create_index
|
392
|
+
ls.create_index = :some_value
|
393
|
+
ls.group.create_index.should == :some_value
|
394
|
+
end
|
395
|
+
|
396
|
+
it "should set the value" do
|
397
|
+
group = ls.group(:create_index => :some_value)
|
398
|
+
group.create_index.should == :some_value
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
describe "should share the current sitemap" do
|
403
|
+
it "if only default_host is passed" do
|
404
|
+
group = ls.group(:default_host => 'http://newhost.com')
|
405
|
+
group.sitemap.should == ls.sitemap
|
406
|
+
group.sitemap.location.host.should == 'http://newhost.com'
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
describe "should not share the current sitemap" do
|
411
|
+
{
|
412
|
+
:filename => :xxx,
|
413
|
+
:sitemaps_path => 'en/',
|
414
|
+
:filename => :example,
|
415
|
+
:namer => SitemapGenerator::SimpleNamer.new(:sitemap)
|
416
|
+
}.each do |key, value|
|
417
|
+
it "if #{key} is present" do
|
418
|
+
ls.group(key => value).sitemap.should_not == ls.sitemap
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
describe "finalizing" do
|
424
|
+
it "should only finalize the sitemaps if a block is passed" do
|
425
|
+
@group = ls.group
|
426
|
+
@group.sitemap.finalized?.should be_false
|
427
|
+
end
|
428
|
+
|
429
|
+
it "should not finalize the sitemap if a group is created" do
|
430
|
+
ls.create { group {} }
|
431
|
+
ls.sitemap.empty?.should be_true
|
432
|
+
ls.sitemap.finalized?.should be_false
|
433
|
+
end
|
434
|
+
|
435
|
+
{:sitemaps_path => 'en/',
|
436
|
+
:filename => :example,
|
437
|
+
:namer => SitemapGenerator::SimpleNamer.new(:sitemap)
|
438
|
+
}.each do |k, v|
|
439
|
+
|
440
|
+
it "should not finalize the sitemap if #{k} is present" do
|
441
|
+
ls.expects(:finalize_sitemap!).never
|
442
|
+
ls.group(k => v) { }
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
describe "adapter" do
|
448
|
+
it "should inherit the current adapter" do
|
449
|
+
ls.adapter = mock('adapter')
|
450
|
+
group = ls.group
|
451
|
+
group.should_not be(ls)
|
452
|
+
group.adapter.should be(ls.adapter)
|
453
|
+
end
|
454
|
+
|
455
|
+
it "should set the value" do
|
456
|
+
adapter = mock('adapter')
|
457
|
+
group = ls.group(:adapter => adapter)
|
458
|
+
group.adapter.should be(adapter)
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
describe "after create" do
|
464
|
+
it "should finalize the sitemap index" do
|
465
|
+
ls.create {}
|
466
|
+
ls.sitemap_index.finalized?.should be_true
|
467
|
+
end
|
468
|
+
|
469
|
+
it "should finalize the sitemap" do
|
470
|
+
ls.create {}
|
471
|
+
ls.sitemap.finalized?.should be_true
|
472
|
+
end
|
473
|
+
|
474
|
+
it "should not finalize the sitemap if a group was created" do
|
475
|
+
ls.instance_variable_set(:@created_group, true)
|
476
|
+
ls.send(:finalize_sitemap!)
|
477
|
+
ls.sitemap.finalized?.should be_false
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
describe "options to create" do
|
482
|
+
before :each do
|
483
|
+
ls.stubs(:finalize!)
|
484
|
+
end
|
485
|
+
|
486
|
+
it "should set include_index" do
|
487
|
+
original = ls.include_index
|
488
|
+
ls.create(:include_index => !original).include_index.should_not == original
|
489
|
+
end
|
490
|
+
|
491
|
+
it "should set include_root" do
|
492
|
+
original = ls.include_root
|
493
|
+
ls.create(:include_root => !original).include_root.should_not == original
|
494
|
+
end
|
495
|
+
|
496
|
+
it "should set the filename" do
|
497
|
+
ls.create(:filename => :xxx)
|
498
|
+
ls.filename.should == :xxx
|
499
|
+
ls.sitemap.location.filename.should =~ /xxx/
|
500
|
+
end
|
501
|
+
|
502
|
+
it "should set verbose" do
|
503
|
+
original = ls.verbose
|
504
|
+
ls.create(:verbose => !original).verbose.should_not == original
|
505
|
+
end
|
506
|
+
|
507
|
+
it "should set the sitemaps_path" do
|
508
|
+
path = 'new/path'
|
509
|
+
ls.create(:sitemaps_path => path)
|
510
|
+
ls.sitemaps_path.should == path
|
511
|
+
ls.sitemap.location.sitemaps_path.to_s.should == 'new/path/'
|
512
|
+
end
|
513
|
+
|
514
|
+
it "should set the default_host" do
|
515
|
+
host = 'http://defaulthost.com'
|
516
|
+
ls.create(:default_host => host)
|
517
|
+
ls.default_host.should == host
|
518
|
+
ls.sitemap.location.host.should == host
|
519
|
+
end
|
520
|
+
|
521
|
+
it "should set the sitemaps host" do
|
522
|
+
host = 'http://sitemaphost.com'
|
523
|
+
ls.create(:sitemaps_host => host)
|
524
|
+
ls.sitemaps_host.should == host
|
525
|
+
ls.sitemap.location.host.should == host
|
526
|
+
end
|
527
|
+
|
528
|
+
it "should set the namer" do
|
529
|
+
namer = SitemapGenerator::SimpleNamer.new(:xxx)
|
530
|
+
ls.create(:namer => namer)
|
531
|
+
ls.namer.should == namer
|
532
|
+
ls.sitemap.location.namer.should == namer
|
533
|
+
ls.sitemap.location.filename.should =~ /xxx/
|
534
|
+
end
|
535
|
+
|
536
|
+
it "should support both namer and filename options" do
|
537
|
+
namer = SitemapGenerator::SimpleNamer.new("sitemap2")
|
538
|
+
ls.create(:namer => namer, :filename => "sitemap1")
|
539
|
+
ls.namer.should == namer
|
540
|
+
ls.sitemap.location.namer.should == namer
|
541
|
+
ls.sitemap.location.filename.should =~ /^sitemap2/
|
542
|
+
ls.sitemap_index.location.filename.should =~ /^sitemap2/
|
543
|
+
end
|
544
|
+
|
545
|
+
it "should support both namer and filename options no matter the order" do
|
546
|
+
options = {
|
547
|
+
:namer => SitemapGenerator::SimpleNamer.new('sitemap1'),
|
548
|
+
:filename => 'sitemap2'
|
549
|
+
}
|
550
|
+
ls.create(options)
|
551
|
+
ls.sitemap.location.filename.should =~ /^sitemap1/
|
552
|
+
ls.sitemap_index.location.filename.should =~ /^sitemap1/
|
553
|
+
end
|
554
|
+
|
555
|
+
it "should not modify the options hash" do
|
556
|
+
options = { :filename => 'sitemaptest', :verbose => false }
|
557
|
+
ls.create(options)
|
558
|
+
options.should == { :filename => 'sitemaptest', :verbose => false }
|
559
|
+
end
|
560
|
+
|
561
|
+
it "should set create_index" do
|
562
|
+
ls.create(:create_index => :auto)
|
563
|
+
ls.create_index.should == :auto
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
describe "reset!" do
|
568
|
+
it "should reset the sitemap namer" do
|
569
|
+
SitemapGenerator::Sitemap.namer.expects(:reset)
|
570
|
+
SitemapGenerator::Sitemap.create(:default_host => 'http://cnn.com')
|
571
|
+
end
|
572
|
+
|
573
|
+
it "should reset the default link variable" do
|
574
|
+
SitemapGenerator::Sitemap.instance_variable_set(:@added_default_links, true)
|
575
|
+
SitemapGenerator::Sitemap.create(:default_host => 'http://cnn.com')
|
576
|
+
SitemapGenerator::Sitemap.instance_variable_set(:@added_default_links, false)
|
577
|
+
end
|
578
|
+
end
|
579
|
+
|
580
|
+
describe "include_root?" do
|
581
|
+
it "should return false" do
|
582
|
+
ls.include_root = false
|
583
|
+
ls.include_root.should be_false
|
584
|
+
end
|
585
|
+
|
586
|
+
it "should return true" do
|
587
|
+
ls.include_root = true
|
588
|
+
ls.include_root.should be_true
|
589
|
+
end
|
590
|
+
end
|
591
|
+
|
592
|
+
describe "include_index?" do
|
593
|
+
let(:sitemaps_host) { 'http://amazon.com' }
|
594
|
+
|
595
|
+
it "should be true if no sitemaps_host set, or it is the same" do
|
596
|
+
ls.include_index = true
|
597
|
+
ls.sitemaps_host = default_host
|
598
|
+
ls.include_index?.should be_true
|
599
|
+
|
600
|
+
ls.sitemaps_host = nil
|
601
|
+
ls.include_index?.should be_true
|
602
|
+
end
|
603
|
+
|
604
|
+
it "should be false if include_index is false or sitemaps_host differs" do
|
605
|
+
ls.include_index = false
|
606
|
+
ls.sitemaps_host = default_host
|
607
|
+
ls.include_index?.should be_false
|
608
|
+
|
609
|
+
ls.include_index = true
|
610
|
+
ls.sitemaps_host = sitemaps_host
|
611
|
+
ls.include_index?.should be_false
|
612
|
+
end
|
613
|
+
|
614
|
+
it "should return false" do
|
615
|
+
ls = SitemapGenerator::LinkSet.new(:default_host => default_host, :sitemaps_host => sitemaps_host)
|
616
|
+
ls.include_index?.should be_false
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
describe "output" do
|
621
|
+
it "should not output" do
|
622
|
+
ls.verbose = false
|
623
|
+
ls.expects(:puts).never
|
624
|
+
ls.send(:output, '')
|
625
|
+
end
|
626
|
+
|
627
|
+
it "should print the given string" do
|
628
|
+
ls.verbose = true
|
629
|
+
ls.expects(:puts).with('')
|
630
|
+
ls.send(:output, '')
|
631
|
+
end
|
632
|
+
end
|
633
|
+
|
634
|
+
describe "yield_sitemap" do
|
635
|
+
it "should default to the value of SitemapGenerator.yield_sitemap?" do
|
636
|
+
SitemapGenerator.expects(:yield_sitemap?).returns(true)
|
637
|
+
ls.yield_sitemap?.should be_true
|
638
|
+
SitemapGenerator.expects(:yield_sitemap?).returns(false)
|
639
|
+
ls.yield_sitemap?.should be_false
|
640
|
+
end
|
641
|
+
|
642
|
+
it "should be settable as an option" do
|
643
|
+
SitemapGenerator.expects(:yield_sitemap?).never
|
644
|
+
SitemapGenerator::LinkSet.new(:yield_sitemap => true).yield_sitemap?.should be_true
|
645
|
+
SitemapGenerator::LinkSet.new(:yield_sitemap => false).yield_sitemap?.should be_false
|
646
|
+
end
|
647
|
+
|
648
|
+
it "should be settable as an attribute" do
|
649
|
+
ls.yield_sitemap = true
|
650
|
+
ls.yield_sitemap?.should be_true
|
651
|
+
ls.yield_sitemap = false
|
652
|
+
ls.yield_sitemap?.should be_false
|
653
|
+
end
|
654
|
+
|
655
|
+
it "should yield the sitemap in the call to create" do
|
656
|
+
ls.send(:interpreter).expects(:eval).with(:yield_sitemap => true)
|
657
|
+
ls.yield_sitemap = true
|
658
|
+
ls.create
|
659
|
+
ls.send(:interpreter).expects(:eval).with(:yield_sitemap => false)
|
660
|
+
ls.yield_sitemap = false
|
661
|
+
ls.create
|
662
|
+
end
|
663
|
+
end
|
664
|
+
|
665
|
+
describe "add" do
|
666
|
+
it "should not modify the options hash" do
|
667
|
+
options = { :host => 'http://newhost.com' }
|
668
|
+
ls.add('/home', options)
|
669
|
+
options.should == { :host => 'http://newhost.com' }
|
670
|
+
end
|
671
|
+
|
672
|
+
it "should add the link to the sitemap and include the default host" do
|
673
|
+
ls.stubs(:add_default_links)
|
674
|
+
ls.sitemap.expects(:add).with('/home', :host => ls.default_host)
|
675
|
+
ls.add('/home')
|
676
|
+
end
|
677
|
+
|
678
|
+
it "should allow setting of a custom host" do
|
679
|
+
ls.stubs(:add_default_links)
|
680
|
+
ls.sitemap.expects(:add).with('/home', :host => 'http://newhost.com')
|
681
|
+
ls.add('/home', :host => 'http://newhost.com')
|
682
|
+
end
|
683
|
+
|
684
|
+
it "should add the default links if they have not been added" do
|
685
|
+
ls.expects(:add_default_links)
|
686
|
+
ls.add('/home')
|
687
|
+
end
|
688
|
+
end
|
689
|
+
|
690
|
+
describe "add_to_index" do
|
691
|
+
it "should add the link to the sitemap index and pass options" do
|
692
|
+
ls.sitemap_index.expects(:add).with('/test', has_entry(:option => 'value'))
|
693
|
+
ls.add_to_index('/test', :option => 'value')
|
694
|
+
end
|
695
|
+
|
696
|
+
it "should not modify the options hash" do
|
697
|
+
options = { :host => 'http://newhost.com' }
|
698
|
+
ls.add_to_index('/home', options)
|
699
|
+
options.should == { :host => 'http://newhost.com' }
|
700
|
+
end
|
701
|
+
|
702
|
+
describe "host" do
|
703
|
+
it "should be the sitemaps_host" do
|
704
|
+
ls.sitemaps_host = 'http://sitemapshost.com'
|
705
|
+
ls.sitemap_index.expects(:add).with('/home', :host => 'http://sitemapshost.com')
|
706
|
+
ls.add_to_index('/home')
|
707
|
+
end
|
708
|
+
|
709
|
+
it "should be the default_host if no sitemaps_host set" do
|
710
|
+
ls.sitemap_index.expects(:add).with('/home', :host => ls.default_host)
|
711
|
+
ls.add_to_index('/home')
|
712
|
+
end
|
713
|
+
|
714
|
+
it "should allow setting a custom host" do
|
715
|
+
ls.sitemap_index.expects(:add).with('/home', :host => 'http://newhost.com')
|
716
|
+
ls.add_to_index('/home', :host => 'http://newhost.com')
|
717
|
+
end
|
718
|
+
end
|
719
|
+
end
|
720
|
+
|
721
|
+
describe "create_index" do
|
722
|
+
let(:location) { SitemapGenerator::SitemapLocation.new(:namer => SitemapGenerator::SimpleNamer.new(:sitemap), :public_path => 'tmp/', :sitemaps_path => 'test/', :host => 'http://example.com/') }
|
723
|
+
let(:sitemap) { SitemapGenerator::Builder::SitemapFile.new(location) }
|
724
|
+
|
725
|
+
describe "when false" do
|
726
|
+
let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :create_index => false) }
|
727
|
+
|
728
|
+
it "should not write the index" do
|
729
|
+
ls.send(:finalize_sitemap_index!)
|
730
|
+
ls.sitemap_index.written?.should be_false
|
731
|
+
end
|
732
|
+
|
733
|
+
it "should still add finalized sitemaps to the index (but the index is never finalized)" do
|
734
|
+
ls.expects(:add_to_index).with(ls.sitemap).once
|
735
|
+
ls.send(:finalize_sitemap!)
|
736
|
+
end
|
737
|
+
end
|
738
|
+
|
739
|
+
describe "when true" do
|
740
|
+
let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :create_index => true) }
|
741
|
+
|
742
|
+
it "should always finalize the index" do
|
743
|
+
ls.send(:finalize_sitemap_index!)
|
744
|
+
ls.sitemap_index.finalized?.should be_true
|
745
|
+
end
|
746
|
+
|
747
|
+
it "should add finalized sitemaps to the index" do
|
748
|
+
ls.expects(:add_to_index).with(ls.sitemap).once
|
749
|
+
ls.send(:finalize_sitemap!)
|
750
|
+
end
|
751
|
+
end
|
752
|
+
|
753
|
+
describe "when :auto" do
|
754
|
+
let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :create_index => :auto) }
|
755
|
+
|
756
|
+
it "should not write the index when it is empty" do
|
757
|
+
ls.sitemap_index.empty?.should be_true
|
758
|
+
ls.send(:finalize_sitemap_index!)
|
759
|
+
ls.sitemap_index.written?.should be_false
|
760
|
+
end
|
761
|
+
|
762
|
+
it "should add finalized sitemaps to the index" do
|
763
|
+
ls.expects(:add_to_index).with(ls.sitemap).once
|
764
|
+
ls.send(:finalize_sitemap!)
|
765
|
+
end
|
766
|
+
|
767
|
+
it "should write the index when a link is added manually" do
|
768
|
+
ls.sitemap_index.add '/test'
|
769
|
+
ls.sitemap_index.empty?.should be_false
|
770
|
+
ls.send(:finalize_sitemap_index!)
|
771
|
+
ls.sitemap_index.written?.should be_true
|
772
|
+
|
773
|
+
# Test that the index url is reported correctly
|
774
|
+
ls.sitemap_index.index_url.should == 'http://example.com/sitemap.xml.gz'
|
775
|
+
end
|
776
|
+
|
777
|
+
it "should not write the index when only one sitemap is added (considered internal usage)" do
|
778
|
+
ls.sitemap_index.add sitemap
|
779
|
+
ls.sitemap_index.empty?.should be_false
|
780
|
+
ls.send(:finalize_sitemap_index!)
|
781
|
+
ls.sitemap_index.written?.should be_false
|
782
|
+
|
783
|
+
# Test that the index url is reported correctly
|
784
|
+
ls.sitemap_index.index_url.should == sitemap.location.url
|
785
|
+
end
|
786
|
+
|
787
|
+
it "should write the index when more than one sitemap is added (considered internal usage)" do
|
788
|
+
ls.sitemap_index.add sitemap
|
789
|
+
ls.sitemap_index.add sitemap.new
|
790
|
+
ls.send(:finalize_sitemap_index!)
|
791
|
+
ls.sitemap_index.written?.should be_true
|
792
|
+
|
793
|
+
# Test that the index url is reported correctly
|
794
|
+
ls.sitemap_index.index_url.should == ls.sitemap_index.location.url
|
795
|
+
ls.sitemap_index.index_url.should == 'http://example.com/sitemap.xml.gz'
|
796
|
+
end
|
797
|
+
|
798
|
+
it "should write the index when it has more than one link" do
|
799
|
+
ls.sitemap_index.add '/test1'
|
800
|
+
ls.sitemap_index.add '/test2'
|
801
|
+
ls.send(:finalize_sitemap_index!)
|
802
|
+
ls.sitemap_index.written?.should be_true
|
803
|
+
|
804
|
+
# Test that the index url is reported correctly
|
805
|
+
ls.sitemap_index.index_url.should == 'http://example.com/sitemap.xml.gz'
|
806
|
+
end
|
807
|
+
end
|
808
|
+
end
|
809
|
+
|
810
|
+
describe "when sitemap empty" do
|
811
|
+
before :each do
|
812
|
+
ls.include_root = false
|
813
|
+
end
|
814
|
+
|
815
|
+
it "should not be written" do
|
816
|
+
ls.sitemap.empty?.should be_true
|
817
|
+
ls.expects(:add_to_index).never
|
818
|
+
ls.send(:finalize_sitemap!)
|
819
|
+
end
|
820
|
+
|
821
|
+
it "should be written" do
|
822
|
+
ls.sitemap.add '/test'
|
823
|
+
ls.sitemap.empty?.should be_false
|
824
|
+
ls.expects(:add_to_index).with(ls.sitemap)
|
825
|
+
ls.send(:finalize_sitemap!)
|
826
|
+
end
|
827
|
+
end
|
828
|
+
|
829
|
+
describe "compress" do
|
830
|
+
it "should be true by default" do
|
831
|
+
ls.compress.should be_true
|
832
|
+
end
|
833
|
+
|
834
|
+
it "should be set on the location objects" do
|
835
|
+
ls.sitemap.location[:compress].should be_true
|
836
|
+
ls.sitemap_index.location[:compress].should be_true
|
837
|
+
end
|
838
|
+
|
839
|
+
it "should be settable and gettable" do
|
840
|
+
ls.compress = false
|
841
|
+
ls.compress.should be_false
|
842
|
+
ls.compress = :all_but_first
|
843
|
+
ls.compress.should == :all_but_first
|
844
|
+
end
|
845
|
+
|
846
|
+
it "should update the location objects when set" do
|
847
|
+
ls.compress = false
|
848
|
+
ls.sitemap.location[:compress].should be_false
|
849
|
+
ls.sitemap_index.location[:compress].should be_false
|
850
|
+
end
|
851
|
+
|
852
|
+
describe "in groups" do
|
853
|
+
it "should inherit the current compress setting" do
|
854
|
+
ls.compress = false
|
855
|
+
ls.group.compress.should be_false
|
856
|
+
end
|
857
|
+
|
858
|
+
it "should set the compress value" do
|
859
|
+
group = ls.group(:compress => false)
|
860
|
+
group.compress.should be_false
|
861
|
+
end
|
862
|
+
end
|
863
|
+
end
|
864
|
+
end
|