sitemap_generator 5.2.0 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGES.md +250 -0
- data/README.md +156 -125
- data/VERSION +1 -1
- data/lib/capistrano/tasks/sitemap_generator.cap +21 -23
- data/lib/sitemap_generator.rb +1 -2
- data/lib/sitemap_generator/adapters/s3_adapter.rb +5 -0
- data/lib/sitemap_generator/application.rb +1 -1
- data/lib/sitemap_generator/builder/sitemap_file.rb +7 -3
- data/lib/sitemap_generator/builder/sitemap_url.rb +1 -10
- data/lib/sitemap_generator/link_set.rb +16 -10
- data/lib/sitemap_generator/{sitemap_namer.rb → simple_namer.rb} +1 -1
- data/lib/sitemap_generator/sitemap_location.rb +13 -1
- data/lib/sitemap_generator/tasks.rb +2 -2
- metadata +51 -123
- data/Gemfile +0 -13
- data/Gemfile.lock +0 -38
- data/Rakefile +0 -43
- data/spec/blueprint.rb +0 -15
- data/spec/files/sitemap.create.rb +0 -12
- data/spec/files/sitemap.groups.rb +0 -49
- data/spec/sitemap_generator/adapters/s3_adapter_spec.rb +0 -23
- data/spec/sitemap_generator/alternate_sitemap_spec.rb +0 -100
- data/spec/sitemap_generator/application_spec.rb +0 -69
- data/spec/sitemap_generator/builder/sitemap_file_spec.rb +0 -110
- data/spec/sitemap_generator/builder/sitemap_index_file_spec.rb +0 -124
- data/spec/sitemap_generator/builder/sitemap_index_url_spec.rb +0 -28
- data/spec/sitemap_generator/builder/sitemap_url_spec.rb +0 -192
- data/spec/sitemap_generator/core_ext/bigdecimal_spec.rb +0 -20
- data/spec/sitemap_generator/core_ext/numeric_spec.rb +0 -43
- data/spec/sitemap_generator/file_adaptor_spec.rb +0 -20
- data/spec/sitemap_generator/geo_sitemap_spec.rb +0 -30
- data/spec/sitemap_generator/helpers/number_helper_spec.rb +0 -196
- data/spec/sitemap_generator/interpreter_spec.rb +0 -90
- data/spec/sitemap_generator/link_set_spec.rb +0 -864
- data/spec/sitemap_generator/mobile_sitemap_spec.rb +0 -27
- data/spec/sitemap_generator/news_sitemap_spec.rb +0 -42
- data/spec/sitemap_generator/pagemap_sitemap_spec.rb +0 -57
- data/spec/sitemap_generator/sitemap_generator_spec.rb +0 -591
- data/spec/sitemap_generator/sitemap_groups_spec.rb +0 -144
- data/spec/sitemap_generator/sitemap_location_spec.rb +0 -210
- data/spec/sitemap_generator/sitemap_namer_spec.rb +0 -96
- data/spec/sitemap_generator/templates_spec.rb +0 -24
- data/spec/sitemap_generator/utilities/existence_spec.rb +0 -26
- data/spec/sitemap_generator/utilities/hash_spec.rb +0 -57
- data/spec/sitemap_generator/utilities/rounding_spec.rb +0 -31
- data/spec/sitemap_generator/utilities_spec.rb +0 -101
- data/spec/sitemap_generator/video_sitemap_spec.rb +0 -117
- data/spec/spec_helper.rb +0 -24
- data/spec/support/file_macros.rb +0 -39
- data/spec/support/schemas/siteindex.xsd +0 -73
- data/spec/support/schemas/sitemap-geo.xsd +0 -41
- data/spec/support/schemas/sitemap-mobile.xsd +0 -32
- data/spec/support/schemas/sitemap-news.xsd +0 -159
- data/spec/support/schemas/sitemap-pagemap.xsd +0 -97
- data/spec/support/schemas/sitemap-video.xsd +0 -643
- data/spec/support/schemas/sitemap.xsd +0 -115
- data/spec/support/xml_macros.rb +0 -67
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "SitemapGenerator" do
|
4
|
-
|
5
|
-
it "should add the mobile sitemap element" do
|
6
|
-
loc = 'http://www.example.com/mobile_page.html'
|
7
|
-
format = 'html'
|
8
|
-
|
9
|
-
mobile_xml_fragment = SitemapGenerator::Builder::SitemapUrl.new('mobile_page.html',
|
10
|
-
:host => 'http://www.example.com',
|
11
|
-
:mobile => true
|
12
|
-
).to_xml
|
13
|
-
|
14
|
-
# Check that the options were parsed correctly
|
15
|
-
doc = Nokogiri::XML.parse("<root xmlns:mobile='#{SitemapGenerator::SCHEMAS['mobile']}'>#{mobile_xml_fragment}</root>")
|
16
|
-
url = doc.at_xpath("//url")
|
17
|
-
url.should_not be_nil
|
18
|
-
url.at_xpath("loc").text.should == loc
|
19
|
-
|
20
|
-
mobile = url.at_xpath("mobile:mobile")
|
21
|
-
mobile.should_not be_nil
|
22
|
-
|
23
|
-
# Google's documentation and published schema don't match some valid elements may
|
24
|
-
# not validate.
|
25
|
-
xml_fragment_should_validate_against_schema(mobile, 'sitemap-mobile', 'xmlns:mobile' => SitemapGenerator::SCHEMAS['mobile'])
|
26
|
-
end
|
27
|
-
end
|
@@ -1,42 +0,0 @@
|
|
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='#{SitemapGenerator::SCHEMAS['news']}'>#{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, 'sitemap-news', 'xmlns:news' => SitemapGenerator::SCHEMAS['news'])
|
41
|
-
end
|
42
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "SitemapGenerator" do
|
4
|
-
let(:schema) { SitemapGenerator::SCHEMAS['pagemap'] }
|
5
|
-
|
6
|
-
it "should add the pagemap sitemap element" do
|
7
|
-
pagemap_xml_fragment = SitemapGenerator::Builder::SitemapUrl.new('my_page.html', {
|
8
|
-
:host => 'http://www.example.com',
|
9
|
-
|
10
|
-
:pagemap => {
|
11
|
-
:dataobjects => [
|
12
|
-
{
|
13
|
-
:type => 'document',
|
14
|
-
:id => 'hibachi',
|
15
|
-
:attributes => [
|
16
|
-
{:name => 'name', :value => 'Dragon'},
|
17
|
-
{:name => 'review', :value => 3.5},
|
18
|
-
]
|
19
|
-
},
|
20
|
-
{
|
21
|
-
:type => 'stats',
|
22
|
-
:attributes => [
|
23
|
-
{:name => 'installs', :value => 2000},
|
24
|
-
{:name => 'comments', :value => 200},
|
25
|
-
]
|
26
|
-
}
|
27
|
-
]
|
28
|
-
}
|
29
|
-
}).to_xml
|
30
|
-
|
31
|
-
# Nokogiri is a fickle beast. We have to add the namespace and define
|
32
|
-
# the prefix in order for XPath queries to work. And then we have to
|
33
|
-
# reingest because otherwise Nokogiri doesn't use it.
|
34
|
-
doc = Nokogiri::XML.parse(pagemap_xml_fragment)
|
35
|
-
doc.root.add_namespace_definition('pagemap', schema)
|
36
|
-
doc = Nokogiri::XML.parse(doc.to_xml)
|
37
|
-
|
38
|
-
url = doc.at_xpath("//url")
|
39
|
-
loc = url.at_xpath("loc")
|
40
|
-
loc.text.should == 'http://www.example.com/my_page.html'
|
41
|
-
|
42
|
-
pagemap = doc.at_xpath('//pagemap:PageMap', 'pagemap' => schema)
|
43
|
-
pagemap.element_children.count.should == 2
|
44
|
-
dataobject = pagemap.at_xpath('//pagemap:DataObject')
|
45
|
-
dataobject.attributes['type'].value.should == 'document'
|
46
|
-
dataobject.attributes['id'].value.should == 'hibachi'
|
47
|
-
dataobject.element_children.count.should == 2
|
48
|
-
first_attribute = dataobject.element_children.first
|
49
|
-
second_attribute = dataobject.element_children.last
|
50
|
-
first_attribute.text.should == 'Dragon'
|
51
|
-
first_attribute.attributes['name'].value.should == 'name'
|
52
|
-
second_attribute.text.should == '3.5'
|
53
|
-
second_attribute.attributes['name'].value.should == 'review'
|
54
|
-
|
55
|
-
xml_fragment_should_validate_against_schema(pagemap, 'sitemap-pagemap', 'xmlns:pagemap' => schema)
|
56
|
-
end
|
57
|
-
end
|
@@ -1,591 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'cgi'
|
3
|
-
|
4
|
-
class Holder
|
5
|
-
class << self
|
6
|
-
attr_accessor :executed
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def with_max_links(num)
|
11
|
-
original = SitemapGenerator::MAX_SITEMAP_LINKS
|
12
|
-
SitemapGenerator::Utilities.with_warnings(nil) do
|
13
|
-
SitemapGenerator.const_set(:MAX_SITEMAP_LINKS, num)
|
14
|
-
end
|
15
|
-
yield
|
16
|
-
SitemapGenerator::Utilities.with_warnings(nil) do
|
17
|
-
SitemapGenerator.const_set(:MAX_SITEMAP_LINKS, original)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "SitemapGenerator" do
|
22
|
-
|
23
|
-
describe "reset!" do
|
24
|
-
before :each do
|
25
|
-
SitemapGenerator::Sitemap.default_host # Force initialization of the LinkSet
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should set a new LinkSet instance" do
|
29
|
-
first = SitemapGenerator::Sitemap.instance_variable_get(:@link_set)
|
30
|
-
first.should be_a(SitemapGenerator::LinkSet)
|
31
|
-
SitemapGenerator::Sitemap.reset!
|
32
|
-
second = SitemapGenerator::Sitemap.instance_variable_get(:@link_set)
|
33
|
-
second.should be_a(SitemapGenerator::LinkSet)
|
34
|
-
first.should_not be(second)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "root" do
|
39
|
-
it "should be set to the root of the gem" do
|
40
|
-
SitemapGenerator.root.should == File.expand_path('../../../' , __FILE__)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "generate sitemap with normal config" do
|
45
|
-
before :all do
|
46
|
-
SitemapGenerator::Sitemap.reset!
|
47
|
-
clean_sitemap_files_from_rails_app
|
48
|
-
copy_sitemap_file_to_rails_app(:create)
|
49
|
-
with_max_links(10) { execute_sitemap_config }
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should create sitemaps" do
|
53
|
-
file_should_exist(rails_path('public/sitemap.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
|
58
|
-
|
59
|
-
it "should have 13 links" do
|
60
|
-
SitemapGenerator::Sitemap.link_count.should == 13
|
61
|
-
end
|
62
|
-
|
63
|
-
it "index XML should validate" do
|
64
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
|
65
|
-
end
|
66
|
-
|
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
|
71
|
-
|
72
|
-
it "index XML should not have excess whitespace" do
|
73
|
-
gzipped_xml_file_should_have_minimal_whitespace rails_path('public/sitemap.xml.gz')
|
74
|
-
end
|
75
|
-
|
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
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "sitemap with groups" do
|
82
|
-
before :all do
|
83
|
-
SitemapGenerator::Sitemap.reset!
|
84
|
-
clean_sitemap_files_from_rails_app
|
85
|
-
copy_sitemap_file_to_rails_app(:groups)
|
86
|
-
with_max_links(2) { execute_sitemap_config }
|
87
|
-
@expected = %w[
|
88
|
-
public/en/xxx.xml.gz
|
89
|
-
public/fr/abc3.xml.gz
|
90
|
-
public/fr/abc4.xml.gz
|
91
|
-
public/fr/def.xml.gz
|
92
|
-
public/fr/new_sitemaps.xml.gz
|
93
|
-
public/fr/new_sitemaps1.xml.gz
|
94
|
-
public/fr/new_sitemaps2.xml.gz
|
95
|
-
public/fr/new_sitemaps3.xml.gz
|
96
|
-
public/fr/new_sitemaps4.xml.gz]
|
97
|
-
@sitemaps = (@expected - %w[public/fr/new_sitemaps.xml.gz])
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should create sitemaps" do
|
101
|
-
@expected.each { |file| file_should_exist(rails_path(file)) }
|
102
|
-
file_should_not_exist(rails_path('public/fr/new_sitemaps5.xml.gz'))
|
103
|
-
file_should_not_exist(rails_path('public/en/xxx1.xml.gz'))
|
104
|
-
file_should_not_exist(rails_path('public/fr/abc5.xml.gz'))
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should have 16 links" do
|
108
|
-
SitemapGenerator::Sitemap.link_count.should == 16
|
109
|
-
end
|
110
|
-
|
111
|
-
it "index XML should validate" do
|
112
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/fr/new_sitemaps.xml.gz'), 'siteindex'
|
113
|
-
end
|
114
|
-
|
115
|
-
it "index XML should not have excess whitespace" do
|
116
|
-
gzipped_xml_file_should_have_minimal_whitespace rails_path('public/fr/new_sitemaps.xml.gz')
|
117
|
-
end
|
118
|
-
|
119
|
-
it "sitemaps XML should validate" do
|
120
|
-
@sitemaps.each { |file| gzipped_xml_file_should_validate_against_schema(rails_path(file), 'sitemap') }
|
121
|
-
end
|
122
|
-
|
123
|
-
it "sitemap XML should not have excess whitespace" do
|
124
|
-
@sitemaps.each { |file| gzipped_xml_file_should_have_minimal_whitespace(rails_path(file)) }
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "should handle links added manually" do
|
129
|
-
before :each do
|
130
|
-
clean_sitemap_files_from_rails_app
|
131
|
-
::SitemapGenerator::Sitemap.reset!
|
132
|
-
::SitemapGenerator::Sitemap.default_host = "http://www.example.com"
|
133
|
-
::SitemapGenerator::Sitemap.namer = ::SitemapGenerator::SimpleNamer.new(:sitemap, :start => 4)
|
134
|
-
::SitemapGenerator::Sitemap.create do
|
135
|
-
3.times do |i|
|
136
|
-
add_to_index "sitemap#{i}.xml.gz"
|
137
|
-
end
|
138
|
-
add '/home'
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should create the index and start the sitemap numbering from 4" do
|
143
|
-
file_should_exist(rails_path('public/sitemap.xml.gz'))
|
144
|
-
file_should_exist(rails_path('public/sitemap4.xml.gz'))
|
145
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
|
146
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap4.xml.gz'), 'sitemap'
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "should handle links added manually" do
|
151
|
-
before :each do
|
152
|
-
clean_sitemap_files_from_rails_app
|
153
|
-
::SitemapGenerator::Sitemap.reset!
|
154
|
-
::SitemapGenerator::Sitemap.default_host = "http://www.example.com"
|
155
|
-
::SitemapGenerator::Sitemap.include_root = false
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should create the index" do
|
159
|
-
with_max_links(1) {
|
160
|
-
::SitemapGenerator::Sitemap.create do
|
161
|
-
add_to_index "customsitemap.xml.gz"
|
162
|
-
add '/one'
|
163
|
-
add '/two'
|
164
|
-
end
|
165
|
-
}
|
166
|
-
file_should_exist(rails_path('public/sitemap.xml.gz'))
|
167
|
-
file_should_exist(rails_path('public/sitemap1.xml.gz'))
|
168
|
-
file_should_exist(rails_path('public/sitemap2.xml.gz'))
|
169
|
-
file_should_not_exist(rails_path('public/sitemap3.xml.gz'))
|
170
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should create the index" do
|
174
|
-
with_max_links(1) {
|
175
|
-
::SitemapGenerator::Sitemap.create do
|
176
|
-
add '/one'
|
177
|
-
add_to_index "customsitemap.xml.gz"
|
178
|
-
add '/two'
|
179
|
-
end
|
180
|
-
}
|
181
|
-
file_should_exist(rails_path('public/sitemap.xml.gz'))
|
182
|
-
file_should_exist(rails_path('public/sitemap1.xml.gz'))
|
183
|
-
file_should_exist(rails_path('public/sitemap2.xml.gz'))
|
184
|
-
file_should_not_exist(rails_path('public/sitemap3.xml.gz'))
|
185
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
|
186
|
-
end
|
187
|
-
|
188
|
-
it "should create an index when only manually added links" do
|
189
|
-
with_max_links(1) {
|
190
|
-
::SitemapGenerator::Sitemap.create(:create_index => :auto) do
|
191
|
-
add_to_index "customsitemap1.xml.gz"
|
192
|
-
end
|
193
|
-
}
|
194
|
-
file_should_exist(rails_path('public/sitemap.xml.gz'))
|
195
|
-
file_should_not_exist(rails_path('public/sitemap1.xml.gz'))
|
196
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should create an index when only manually added links" do
|
200
|
-
with_max_links(1) {
|
201
|
-
::SitemapGenerator::Sitemap.create(:create_index => :auto) do
|
202
|
-
add_to_index "customsitemap1.xml.gz"
|
203
|
-
add_to_index "customsitemap2.xml.gz"
|
204
|
-
add_to_index "customsitemap3.xml.gz"
|
205
|
-
end
|
206
|
-
}
|
207
|
-
file_should_exist(rails_path('public/sitemap.xml.gz'))
|
208
|
-
file_should_not_exist(rails_path('public/sitemap1.xml.gz'))
|
209
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should not create an index" do
|
213
|
-
# Create index is explicity turned off and no links added to sitemap,
|
214
|
-
# respect the setting and don't create the index. There is no sitemap file either.
|
215
|
-
::SitemapGenerator::Sitemap.create(:create_index => false) do
|
216
|
-
add_to_index "customsitemap1.xml.gz"
|
217
|
-
add_to_index "customsitemap2.xml.gz"
|
218
|
-
add_to_index "customsitemap3.xml.gz"
|
219
|
-
end
|
220
|
-
file_should_not_exist(rails_path('public/sitemap.xml.gz'))
|
221
|
-
file_should_not_exist(rails_path('public/sitemap1.xml.gz'))
|
222
|
-
end
|
223
|
-
|
224
|
-
it "should not create an index" do
|
225
|
-
::SitemapGenerator::Sitemap.create(:create_index => false) do
|
226
|
-
add '/one'
|
227
|
-
end
|
228
|
-
file_should_exist(rails_path('public/sitemap.xml.gz')) # the sitemap, not an index
|
229
|
-
file_should_not_exist(rails_path('public/sitemap1.xml.gz'))
|
230
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'sitemap'
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
describe "sitemap path" do
|
235
|
-
before :each do
|
236
|
-
clean_sitemap_files_from_rails_app
|
237
|
-
::SitemapGenerator::Sitemap.reset!
|
238
|
-
::SitemapGenerator::Sitemap.default_host = 'http://test.local'
|
239
|
-
::SitemapGenerator::Sitemap.filename = 'sitemap'
|
240
|
-
::SitemapGenerator::Sitemap.create_index = true
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should allow changing of the filename" do
|
244
|
-
::SitemapGenerator::Sitemap.create(:filename => :geo_sitemap) do
|
245
|
-
add '/goerss', :geo => { :format => 'georss' }
|
246
|
-
add '/kml', :geo => { :format => 'kml' }
|
247
|
-
end
|
248
|
-
file_should_exist(rails_path('public/geo_sitemap.xml.gz'))
|
249
|
-
file_should_exist(rails_path('public/geo_sitemap1.xml.gz'))
|
250
|
-
end
|
251
|
-
|
252
|
-
it "should support setting a sitemap path" do
|
253
|
-
directory_should_not_exist(rails_path('public/sitemaps/'))
|
254
|
-
|
255
|
-
sm = ::SitemapGenerator::Sitemap
|
256
|
-
sm.sitemaps_path = 'sitemaps/'
|
257
|
-
sm.create do
|
258
|
-
add '/'
|
259
|
-
add '/another'
|
260
|
-
end
|
261
|
-
|
262
|
-
file_should_exist(rails_path('public/sitemaps/sitemap.xml.gz'))
|
263
|
-
file_should_exist(rails_path('public/sitemaps/sitemap1.xml.gz'))
|
264
|
-
end
|
265
|
-
|
266
|
-
it "should support setting a deeply nested sitemap path" do
|
267
|
-
directory_should_not_exist(rails_path('public/sitemaps/deep/directory'))
|
268
|
-
|
269
|
-
sm = ::SitemapGenerator::Sitemap
|
270
|
-
sm.sitemaps_path = 'sitemaps/deep/directory/'
|
271
|
-
sm.create do
|
272
|
-
add '/'
|
273
|
-
add '/another'
|
274
|
-
add '/yet-another'
|
275
|
-
end
|
276
|
-
|
277
|
-
file_should_exist(rails_path('public/sitemaps/deep/directory/sitemap.xml.gz'))
|
278
|
-
file_should_exist(rails_path('public/sitemaps/deep/directory/sitemap1.xml.gz'))
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
describe "external dependencies" do
|
283
|
-
it "should work outside of Rails" do
|
284
|
-
Object.stubs(:Rails => nil)
|
285
|
-
lambda { ::SitemapGenerator::LinkSet.new }.should_not raise_exception
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
describe "verbose" do
|
290
|
-
it "should be set via ENV['VERBOSE']" do
|
291
|
-
original = SitemapGenerator.verbose
|
292
|
-
SitemapGenerator.verbose = nil
|
293
|
-
ENV['VERBOSE'] = 'true'
|
294
|
-
SitemapGenerator.verbose.should be_true
|
295
|
-
SitemapGenerator.verbose = nil
|
296
|
-
ENV['VERBOSE'] = 'false'
|
297
|
-
SitemapGenerator.verbose.should be_false
|
298
|
-
SitemapGenerator.verbose = original
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
describe "yield_sitemap" do
|
303
|
-
it "should set the yield_sitemap flag" do
|
304
|
-
SitemapGenerator.yield_sitemap = false
|
305
|
-
SitemapGenerator.yield_sitemap?.should be_false
|
306
|
-
SitemapGenerator.yield_sitemap = true
|
307
|
-
SitemapGenerator.yield_sitemap?.should be_true
|
308
|
-
SitemapGenerator.yield_sitemap = false
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
describe "create_index" do
|
313
|
-
before :each do
|
314
|
-
clean_sitemap_files_from_rails_app
|
315
|
-
end
|
316
|
-
|
317
|
-
describe "when true" do
|
318
|
-
let(:ls) {
|
319
|
-
SitemapGenerator::LinkSet.new(
|
320
|
-
:include_root => false,
|
321
|
-
:default_host => 'http://example.com',
|
322
|
-
:create_index => true)
|
323
|
-
}
|
324
|
-
|
325
|
-
it "should always create index" do
|
326
|
-
with_max_links(1) do
|
327
|
-
ls.create { add('/one') }
|
328
|
-
end
|
329
|
-
ls.sitemap_index.link_count.should == 1 # one sitemap
|
330
|
-
file_should_exist(rails_path('public/sitemap.xml.gz'))
|
331
|
-
file_should_exist(rails_path('public/sitemap1.xml.gz'))
|
332
|
-
file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
|
333
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
|
334
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap1.xml.gz'), 'sitemap'
|
335
|
-
|
336
|
-
# Test that the index url is reported correctly
|
337
|
-
ls.search_engines = { :google => 'http://google.com/?url=%s' }
|
338
|
-
ls.expects(:open).with("http://google.com/?url=#{CGI.escape('http://example.com/sitemap.xml.gz')}")
|
339
|
-
ls.ping_search_engines
|
340
|
-
end
|
341
|
-
|
342
|
-
it "should always create index" do
|
343
|
-
with_max_links(1) do
|
344
|
-
ls.create { add('/one'); add('/two') }
|
345
|
-
end
|
346
|
-
ls.sitemap_index.link_count.should == 2 # two sitemaps
|
347
|
-
file_should_exist(rails_path('public/sitemap.xml.gz'))
|
348
|
-
file_should_exist(rails_path('public/sitemap1.xml.gz'))
|
349
|
-
file_should_exist(rails_path('public/sitemap2.xml.gz'))
|
350
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
|
351
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap1.xml.gz'), 'sitemap'
|
352
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap2.xml.gz'), 'sitemap'
|
353
|
-
|
354
|
-
# Test that the index url is reported correctly
|
355
|
-
ls.search_engines = { :google => 'http://google.com/?url=%s' }
|
356
|
-
ls.expects(:open).with("http://google.com/?url=#{CGI.escape('http://example.com/sitemap.xml.gz')}")
|
357
|
-
ls.ping_search_engines
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
# Technically when there's no index, the first sitemap is the "index"
|
362
|
-
# regardless of how many sitemaps were created, or if create_index is false.
|
363
|
-
describe "when false" do
|
364
|
-
let(:ls) { SitemapGenerator::LinkSet.new(:include_root => false, :default_host => 'http://example.com', :create_index => false) }
|
365
|
-
|
366
|
-
it "should never create index" do
|
367
|
-
with_max_links(1) do
|
368
|
-
ls.create { add('/one') }
|
369
|
-
end
|
370
|
-
ls.sitemap_index.link_count.should == 1 # one sitemap
|
371
|
-
file_should_exist(rails_path('public/sitemap.xml.gz'))
|
372
|
-
file_should_not_exist(rails_path('public/sitemap1.xml.gz'))
|
373
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'sitemap'
|
374
|
-
|
375
|
-
# Test that the index url is reported correctly
|
376
|
-
ls.search_engines = { :google => 'http://google.com/?url=%s' }
|
377
|
-
ls.expects(:open).with("http://google.com/?url=#{CGI.escape('http://example.com/sitemap.xml.gz')}")
|
378
|
-
ls.ping_search_engines
|
379
|
-
end
|
380
|
-
|
381
|
-
it "should never create index" do
|
382
|
-
with_max_links(1) do
|
383
|
-
ls.create { add('/one'); add('/two') }
|
384
|
-
end
|
385
|
-
ls.sitemap_index.link_count.should == 2 # two sitemaps
|
386
|
-
file_should_exist(rails_path('public/sitemap.xml.gz'))
|
387
|
-
file_should_exist(rails_path('public/sitemap1.xml.gz'))
|
388
|
-
file_should_not_exist(rails_path('public/sitemap2.xml.gz'))
|
389
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'sitemap'
|
390
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap1.xml.gz'), 'sitemap'
|
391
|
-
|
392
|
-
# Test that the index url is reported correctly
|
393
|
-
ls.search_engines = { :google => 'http://google.com/?url=%s' }
|
394
|
-
ls.expects(:open).with("http://google.com/?url=#{CGI.escape('http://example.com/sitemap.xml.gz')}")
|
395
|
-
ls.ping_search_engines
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
describe "when :auto" do
|
400
|
-
let(:ls) { SitemapGenerator::LinkSet.new(:include_root => false, :default_host => 'http://example.com', :create_index => :auto) }
|
401
|
-
|
402
|
-
it "should not create index if only one sitemap file" do
|
403
|
-
with_max_links(1) do
|
404
|
-
ls.create { add('/one') }
|
405
|
-
end
|
406
|
-
ls.sitemap_index.link_count.should == 1 # one sitemap
|
407
|
-
file_should_exist(rails_path('public/sitemap.xml.gz'))
|
408
|
-
file_should_not_exist(rails_path('public/sitemap1.xml.gz'))
|
409
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'sitemap'
|
410
|
-
|
411
|
-
# Test that the index url is reported correctly
|
412
|
-
ls.search_engines = { :google => 'http://google.com/?url=%s' }
|
413
|
-
ls.expects(:open).with("http://google.com/?url=#{CGI.escape('http://example.com/sitemap.xml.gz')}")
|
414
|
-
ls.ping_search_engines
|
415
|
-
end
|
416
|
-
|
417
|
-
it "should create index if more than one sitemap file" do
|
418
|
-
with_max_links(1) do
|
419
|
-
ls.create { add('/one'); add('/two') }
|
420
|
-
end
|
421
|
-
ls.sitemap_index.link_count.should == 2 # two sitemaps
|
422
|
-
file_should_exist(rails_path('public/sitemap.xml.gz'))
|
423
|
-
file_should_exist(rails_path('public/sitemap1.xml.gz'))
|
424
|
-
file_should_exist(rails_path('public/sitemap2.xml.gz'))
|
425
|
-
file_should_not_exist(rails_path('public/sitemap3.xml.gz'))
|
426
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
|
427
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap1.xml.gz'), 'sitemap'
|
428
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap2.xml.gz'), 'sitemap'
|
429
|
-
|
430
|
-
# Test that the index url is reported correctly
|
431
|
-
ls.search_engines = { :google => 'http://google.com/?url=%s' }
|
432
|
-
ls.expects(:open).with("http://google.com/?url=#{CGI.escape('http://example.com/sitemap.xml.gz')}")
|
433
|
-
ls.ping_search_engines
|
434
|
-
end
|
435
|
-
|
436
|
-
it "should create index if more than one group" do
|
437
|
-
with_max_links(1) do
|
438
|
-
ls.create do
|
439
|
-
group(:filename => :group1) { add('/one') };
|
440
|
-
group(:filename => :group2) { add('/two') };
|
441
|
-
end
|
442
|
-
end
|
443
|
-
ls.sitemap_index.link_count.should == 2 # two sitemaps
|
444
|
-
file_should_exist(rails_path('public/sitemap.xml.gz'))
|
445
|
-
file_should_exist(rails_path('public/group1.xml.gz'))
|
446
|
-
file_should_exist(rails_path('public/group2.xml.gz'))
|
447
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/sitemap.xml.gz'), 'siteindex'
|
448
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/group1.xml.gz'), 'sitemap'
|
449
|
-
gzipped_xml_file_should_validate_against_schema rails_path('public/group2.xml.gz'), 'sitemap'
|
450
|
-
|
451
|
-
# Test that the index url is reported correctly
|
452
|
-
ls.search_engines = { :google => 'http://google.com/?url=%s' }
|
453
|
-
ls.expects(:open).with("http://google.com/?url=#{CGI.escape('http://example.com/sitemap.xml.gz')}")
|
454
|
-
ls.ping_search_engines
|
455
|
-
end
|
456
|
-
end
|
457
|
-
end
|
458
|
-
|
459
|
-
describe "compress" do
|
460
|
-
let(:ls) { SitemapGenerator::LinkSet.new(:default_host => 'http://test.local', :include_root => false) }
|
461
|
-
|
462
|
-
before :each do
|
463
|
-
clean_sitemap_files_from_rails_app
|
464
|
-
end
|
465
|
-
|
466
|
-
describe "when false" do
|
467
|
-
before :each do
|
468
|
-
ls.compress = false
|
469
|
-
end
|
470
|
-
|
471
|
-
it "should not compress files" do
|
472
|
-
with_max_links(1) do
|
473
|
-
ls.create do
|
474
|
-
add('/one')
|
475
|
-
add('/two')
|
476
|
-
group(:filename => :group) {
|
477
|
-
add('/group1')
|
478
|
-
add('/group2')
|
479
|
-
}
|
480
|
-
end
|
481
|
-
end
|
482
|
-
file_should_exist(rails_path('public/sitemap.xml'))
|
483
|
-
file_should_exist(rails_path('public/sitemap1.xml'))
|
484
|
-
file_should_exist(rails_path('public/group.xml'))
|
485
|
-
file_should_exist(rails_path('public/group1.xml'))
|
486
|
-
end
|
487
|
-
end
|
488
|
-
|
489
|
-
describe "when :all_but_first" do
|
490
|
-
before :each do
|
491
|
-
ls.compress = :all_but_first
|
492
|
-
end
|
493
|
-
|
494
|
-
it "should not compress first file" do
|
495
|
-
with_max_links(1) do
|
496
|
-
ls.create do
|
497
|
-
add('/one')
|
498
|
-
add('/two')
|
499
|
-
add('/three')
|
500
|
-
group(:filename => :group) {
|
501
|
-
add('/group1')
|
502
|
-
add('/group2')
|
503
|
-
}
|
504
|
-
group(:filename => :group2, :compress => true) {
|
505
|
-
add('/group1')
|
506
|
-
add('/group2')
|
507
|
-
}
|
508
|
-
group(:filename => :group2, :compress => false) {
|
509
|
-
add('/group1')
|
510
|
-
add('/group2')
|
511
|
-
}
|
512
|
-
end
|
513
|
-
end
|
514
|
-
file_should_exist(rails_path('public/sitemap.xml'))
|
515
|
-
file_should_exist(rails_path('public/sitemap1.xml.gz'))
|
516
|
-
file_should_exist(rails_path('public/sitemap2.xml.gz'))
|
517
|
-
file_should_exist(rails_path('public/group.xml'))
|
518
|
-
file_should_exist(rails_path('public/group1.xml.gz'))
|
519
|
-
file_should_exist(rails_path('public/group2.xml.gz'))
|
520
|
-
file_should_exist(rails_path('public/group21.xml.gz'))
|
521
|
-
end
|
522
|
-
end
|
523
|
-
|
524
|
-
describe "in groups" do
|
525
|
-
it "should respect passed in compress option" do
|
526
|
-
with_max_links(1) do
|
527
|
-
ls.create do
|
528
|
-
group(:filename => :group1, :compress => :all_but_first) {
|
529
|
-
add('/group1')
|
530
|
-
add('/group2')
|
531
|
-
}
|
532
|
-
group(:filename => :group2, :compress => true) {
|
533
|
-
add('/group1')
|
534
|
-
add('/group2')
|
535
|
-
}
|
536
|
-
group(:filename => :group3, :compress => false) {
|
537
|
-
add('/group1')
|
538
|
-
add('/group2')
|
539
|
-
}
|
540
|
-
end
|
541
|
-
end
|
542
|
-
file_should_exist(rails_path('public/group1.xml'))
|
543
|
-
file_should_exist(rails_path('public/group11.xml.gz'))
|
544
|
-
file_should_exist(rails_path('public/group2.xml.gz'))
|
545
|
-
file_should_exist(rails_path('public/group21.xml.gz'))
|
546
|
-
file_should_exist(rails_path('public/group3.xml'))
|
547
|
-
file_should_exist(rails_path('public/group31.xml'))
|
548
|
-
end
|
549
|
-
end
|
550
|
-
end
|
551
|
-
|
552
|
-
describe "respond_to?" do
|
553
|
-
it "should correctly identify the methods that it responds to" do
|
554
|
-
SitemapGenerator::Sitemap.respond_to?(:create).should be_true
|
555
|
-
SitemapGenerator::Sitemap.respond_to?(:adapter).should be_true
|
556
|
-
SitemapGenerator::Sitemap.respond_to?(:default_host).should be_true
|
557
|
-
SitemapGenerator::Sitemap.respond_to?(:invalid_func).should be_false
|
558
|
-
end
|
559
|
-
end
|
560
|
-
|
561
|
-
protected
|
562
|
-
|
563
|
-
#
|
564
|
-
# Helpers
|
565
|
-
#
|
566
|
-
|
567
|
-
def rails_path(file)
|
568
|
-
SitemapGenerator.app.root + file
|
569
|
-
end
|
570
|
-
|
571
|
-
def copy_sitemap_file_to_rails_app(extension)
|
572
|
-
FileUtils.cp(File.join(SitemapGenerator.root, "spec/files/sitemap.#{extension}.rb"), SitemapGenerator.app.root + 'config/sitemap.rb')
|
573
|
-
end
|
574
|
-
|
575
|
-
def delete_sitemap_file_from_rails_app
|
576
|
-
FileUtils.remove(SitemapGenerator.app.root + 'config/sitemap.rb')
|
577
|
-
rescue
|
578
|
-
nil
|
579
|
-
end
|
580
|
-
|
581
|
-
def clean_sitemap_files_from_rails_app
|
582
|
-
FileUtils.rm_rf(rails_path('public/'))
|
583
|
-
FileUtils.mkdir_p(rails_path('public/'))
|
584
|
-
end
|
585
|
-
|
586
|
-
# Better would be to just invoke the environment task and use
|
587
|
-
# the interpreter.
|
588
|
-
def execute_sitemap_config(opts={})
|
589
|
-
SitemapGenerator::Interpreter.run(opts)
|
590
|
-
end
|
591
|
-
end
|