sitemap_generator_ftbpro 5.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,144 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
def with_max_links(num)
|
4
|
+
SitemapGenerator::Utilities.with_warnings(nil) do
|
5
|
+
original = SitemapGenerator::MAX_SITEMAP_LINKS
|
6
|
+
SitemapGenerator.const_set(:MAX_SITEMAP_LINKS, num)
|
7
|
+
yield
|
8
|
+
SitemapGenerator.const_set(:MAX_SITEMAP_LINKS, original)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Sitemap Groups" do
|
13
|
+
let(:linkset) { ::SitemapGenerator::LinkSet.new(:default_host => 'http://test.com') }
|
14
|
+
|
15
|
+
before :each do
|
16
|
+
FileUtils.rm_rf(SitemapGenerator.app.root + 'public/')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not finalize the default sitemap if using groups" do
|
20
|
+
linkset.create do
|
21
|
+
group(:filename => :sitemap_en) do
|
22
|
+
add '/en'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
26
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap_en.xml.gz')
|
27
|
+
file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should not write out empty groups" do
|
31
|
+
linkset.create do
|
32
|
+
group(:filename => :sitemap_en) { }
|
33
|
+
end
|
34
|
+
file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap_en.xml.gz')
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should add default links if no groups are created" do
|
38
|
+
linkset.create do
|
39
|
+
end
|
40
|
+
linkset.link_count.should == 1
|
41
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
42
|
+
file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should add links to the default sitemap" do
|
46
|
+
linkset.create do
|
47
|
+
add '/before'
|
48
|
+
group(:filename => :sitemap_en) do
|
49
|
+
add '/link'
|
50
|
+
end
|
51
|
+
add '/after'
|
52
|
+
end
|
53
|
+
linkset.link_count.should == 4
|
54
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
55
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
56
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap_en.xml.gz')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should rollover when sitemaps are full" do
|
60
|
+
with_max_links(1) {
|
61
|
+
linkset.include_index = false
|
62
|
+
linkset.include_root = false
|
63
|
+
linkset.create do
|
64
|
+
add '/before'
|
65
|
+
group(:filename => :sitemap_en, :sitemaps_path => 'en/') do
|
66
|
+
add '/one'
|
67
|
+
add '/two'
|
68
|
+
end
|
69
|
+
add '/after'
|
70
|
+
end
|
71
|
+
}
|
72
|
+
linkset.link_count.should == 4
|
73
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
74
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
75
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap2.xml.gz')
|
76
|
+
file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap3.xml.gz')
|
77
|
+
file_should_exist(SitemapGenerator.app.root + 'public/en/sitemap_en.xml.gz')
|
78
|
+
file_should_exist(SitemapGenerator.app.root + 'public/en/sitemap_en1.xml.gz')
|
79
|
+
file_should_not_exist(SitemapGenerator.app.root + 'public/en/sitemap_en2.xml.gz')
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should support multiple groups" do
|
83
|
+
linkset.create do
|
84
|
+
group(:filename => :sitemap_en, :sitemaps_path => 'en/') do
|
85
|
+
add '/one'
|
86
|
+
end
|
87
|
+
group(:filename => :sitemap_fr, :sitemaps_path => 'fr/') do
|
88
|
+
add '/one'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
linkset.link_count.should == 2
|
92
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
93
|
+
file_should_exist(SitemapGenerator.app.root + 'public/en/sitemap_en.xml.gz')
|
94
|
+
file_should_exist(SitemapGenerator.app.root + 'public/fr/sitemap_fr.xml.gz')
|
95
|
+
end
|
96
|
+
|
97
|
+
it "the sitemap shouldn't be finalized until the end if the groups don't conflict" do
|
98
|
+
linkset.create do
|
99
|
+
add 'one'
|
100
|
+
group(:filename => :first) { add '/two' }
|
101
|
+
add 'three'
|
102
|
+
group(:filename => :second) { add '/four' }
|
103
|
+
add 'five'
|
104
|
+
end
|
105
|
+
linkset.link_count.should == 6
|
106
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
107
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
108
|
+
file_should_exist(SitemapGenerator.app.root + 'public/first.xml.gz')
|
109
|
+
file_should_exist(SitemapGenerator.app.root + 'public/second.xml.gz')
|
110
|
+
gzipped_xml_file_should_validate_against_schema(SitemapGenerator.app.root + 'public/sitemap.xml.gz', 'siteindex')
|
111
|
+
gzipped_xml_file_should_validate_against_schema(SitemapGenerator.app.root + 'public/sitemap1.xml.gz', 'sitemap')
|
112
|
+
end
|
113
|
+
|
114
|
+
it "groups should share the sitemap if the sitemap location is unchanged" do
|
115
|
+
linkset.create do
|
116
|
+
add 'one'
|
117
|
+
group(:default_host => 'http://newhost.com') { add '/two' }
|
118
|
+
add 'three'
|
119
|
+
group(:default_host => 'http://betterhost.com') { add '/four' }
|
120
|
+
add 'five'
|
121
|
+
end
|
122
|
+
linkset.link_count.should == 6
|
123
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
124
|
+
file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
125
|
+
gzipped_xml_file_should_validate_against_schema(SitemapGenerator.app.root + 'public/sitemap.xml.gz', 'sitemap')
|
126
|
+
end
|
127
|
+
|
128
|
+
it "sitemaps should be finalized if virtual location settings are changed" do
|
129
|
+
linkset.create do
|
130
|
+
add 'one'
|
131
|
+
group(:sitemaps_path => :en) { add '/two' }
|
132
|
+
add 'three'
|
133
|
+
group(:sitemaps_host => 'http://newhost.com') { add '/four' }
|
134
|
+
add 'five'
|
135
|
+
end
|
136
|
+
linkset.link_count.should == 6
|
137
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap.xml.gz')
|
138
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap1.xml.gz')
|
139
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap2.xml.gz')
|
140
|
+
file_should_exist(SitemapGenerator.app.root + 'public/sitemap3.xml.gz')
|
141
|
+
file_should_not_exist(SitemapGenerator.app.root + 'public/sitemap4.xml.gz')
|
142
|
+
file_should_exist(SitemapGenerator.app.root + 'public/en/sitemap.xml.gz')
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SitemapGenerator::SitemapLocation do
|
4
|
+
let(:default_host) { 'http://example.com' }
|
5
|
+
let(:location) { SitemapGenerator::SitemapLocation.new }
|
6
|
+
|
7
|
+
it "public_path should default to the public directory in the application root" do
|
8
|
+
location.public_path.should == SitemapGenerator.app.root + 'public/'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a default namer" do
|
12
|
+
location[:namer].should_not be_nil
|
13
|
+
location[:filename].should be_nil
|
14
|
+
location.filename.should == 'sitemap1.xml.gz'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should require a filename" do
|
18
|
+
location[:filename] = nil
|
19
|
+
lambda {
|
20
|
+
location.filename.should be_nil
|
21
|
+
}.should raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should require a namer" do
|
25
|
+
location[:namer] = nil
|
26
|
+
lambda {
|
27
|
+
location.filename.should be_nil
|
28
|
+
}.should raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should require a host" do
|
32
|
+
location = SitemapGenerator::SitemapLocation.new(:filename => nil, :namer => nil)
|
33
|
+
lambda {
|
34
|
+
location.host.should be_nil
|
35
|
+
}.should raise_error
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should accept a Namer option" do
|
39
|
+
@namer = SitemapGenerator::SimpleNamer.new(:xxx)
|
40
|
+
location = SitemapGenerator::SitemapLocation.new(:namer => @namer)
|
41
|
+
location.filename.should == @namer.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should protect the filename from further changes in the Namer" do
|
45
|
+
@namer = SitemapGenerator::SimpleNamer.new(:xxx)
|
46
|
+
location = SitemapGenerator::SitemapLocation.new(:namer => @namer)
|
47
|
+
location.filename.should == @namer.to_s
|
48
|
+
@namer.next
|
49
|
+
location.filename.should == @namer.previous.to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should allow changing the namer" do
|
53
|
+
@namer1 = SitemapGenerator::SimpleNamer.new(:xxx)
|
54
|
+
location = SitemapGenerator::SitemapLocation.new(:namer => @namer1)
|
55
|
+
location.filename.should == @namer1.to_s
|
56
|
+
@namer2 = SitemapGenerator::SimpleNamer.new(:yyy)
|
57
|
+
location[:namer] = @namer2
|
58
|
+
location.filename.should == @namer2.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "testing options and #with" do
|
62
|
+
|
63
|
+
# Array of tuples with instance options and expected method return values
|
64
|
+
tests = [
|
65
|
+
[{
|
66
|
+
:sitemaps_path => nil,
|
67
|
+
:public_path => '/public',
|
68
|
+
:filename => 'sitemap.xml.gz',
|
69
|
+
:host => 'http://test.com' },
|
70
|
+
{ :url => 'http://test.com/sitemap.xml.gz',
|
71
|
+
:directory => '/public',
|
72
|
+
:path => '/public/sitemap.xml.gz',
|
73
|
+
:path_in_public => 'sitemap.xml.gz'
|
74
|
+
}],
|
75
|
+
[{
|
76
|
+
:sitemaps_path => 'sitemaps/en/',
|
77
|
+
:public_path => '/public/system/',
|
78
|
+
:filename => 'sitemap.xml.gz',
|
79
|
+
:host => 'http://test.com/plus/extra/' },
|
80
|
+
{ :url => 'http://test.com/plus/extra/sitemaps/en/sitemap.xml.gz',
|
81
|
+
:directory => '/public/system/sitemaps/en',
|
82
|
+
:path => '/public/system/sitemaps/en/sitemap.xml.gz',
|
83
|
+
:path_in_public => 'sitemaps/en/sitemap.xml.gz'
|
84
|
+
}]
|
85
|
+
]
|
86
|
+
tests.each do |opts, returns|
|
87
|
+
returns.each do |method, value|
|
88
|
+
it "#{method} should return #{value}" do
|
89
|
+
location.with(opts).send(method).should == value
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "when duplicated" do
|
96
|
+
it "should not inherit some objects" do
|
97
|
+
location = SitemapGenerator::SitemapLocation.new(:filename => 'xxx', :host => default_host, :public_path => 'public/')
|
98
|
+
location.url.should == default_host+'/xxx'
|
99
|
+
location.public_path.to_s.should == 'public/'
|
100
|
+
dup = location.dup
|
101
|
+
dup.url.should == location.url
|
102
|
+
dup.url.should_not be(location.url)
|
103
|
+
dup.public_path.to_s.should == location.public_path.to_s
|
104
|
+
dup.public_path.should_not be(location.public_path)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "filesize" do
|
109
|
+
it "should read the size of the file at path" do
|
110
|
+
location.expects(:path).returns('/somepath')
|
111
|
+
File.expects(:size?).with('/somepath')
|
112
|
+
location.filesize
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "public_path" do
|
117
|
+
it "should append a trailing slash" do
|
118
|
+
location = SitemapGenerator::SitemapLocation.new(:public_path => 'public/google')
|
119
|
+
location.public_path.to_s.should == 'public/google/'
|
120
|
+
location[:public_path] = 'new/path'
|
121
|
+
location.public_path.to_s.should == 'new/path/'
|
122
|
+
location[:public_path] = 'already/slashed/'
|
123
|
+
location.public_path.to_s.should == 'already/slashed/'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "sitemaps_path" do
|
128
|
+
it "should append a trailing slash" do
|
129
|
+
location = SitemapGenerator::SitemapLocation.new(:sitemaps_path => 'public/google')
|
130
|
+
location.sitemaps_path.to_s.should == 'public/google/'
|
131
|
+
location[:sitemaps_path] = 'new/path'
|
132
|
+
location.sitemaps_path.to_s.should == 'new/path/'
|
133
|
+
location[:sitemaps_path] = 'already/slashed/'
|
134
|
+
location.sitemaps_path.to_s.should == 'already/slashed/'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "url" do
|
139
|
+
it "should handle paths not ending in slash" do
|
140
|
+
location = SitemapGenerator::SitemapLocation.new(
|
141
|
+
:public_path => 'public/google', :filename => 'xxx',
|
142
|
+
:host => default_host, :sitemaps_path => 'sub/dir')
|
143
|
+
location.url.should == default_host + '/sub/dir/xxx'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "write" do
|
148
|
+
it "should output summary line when verbose" do
|
149
|
+
location = SitemapGenerator::SitemapLocation.new(:public_path => 'public/', :verbose => true)
|
150
|
+
location.adapter.stubs(:write)
|
151
|
+
location.expects(:summary)
|
152
|
+
location.write('data', 1)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should not output summary line when not verbose" do
|
156
|
+
location = SitemapGenerator::SitemapLocation.new(:public_path => 'public/', :verbose => false)
|
157
|
+
location.adapter.stubs(:write)
|
158
|
+
location.expects(:summary).never
|
159
|
+
location.write('data', 1)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "filename" do
|
164
|
+
it "should strip gz extension if not compressing" do
|
165
|
+
location = SitemapGenerator::SitemapLocation.new(:namer => SitemapGenerator::SimpleNamer.new(:sitemap), :compress => false)
|
166
|
+
location.filename.should == 'sitemap.xml'
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should not strip gz extension if compressing" do
|
170
|
+
location = SitemapGenerator::SitemapLocation.new(:namer => SitemapGenerator::SimpleNamer.new(:sitemap), :compress => true)
|
171
|
+
location.filename.should == 'sitemap.xml.gz'
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should strip gz extension if :all_but_first and first file" do
|
175
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap)
|
176
|
+
namer.stubs(:start?).returns(true)
|
177
|
+
location = SitemapGenerator::SitemapLocation.new(:namer => namer, :compress => :all_but_first)
|
178
|
+
location.filename.should == 'sitemap.xml'
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should strip gz extension if :all_but_first and first file" do
|
182
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap)
|
183
|
+
namer.stubs(:start?).returns(false)
|
184
|
+
location = SitemapGenerator::SitemapLocation.new(:namer => namer, :compress => :all_but_first)
|
185
|
+
location.filename.should == 'sitemap.xml.gz'
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "when not compressing" do
|
190
|
+
it "the URL should point to the uncompressed file" do
|
191
|
+
location = SitemapGenerator::SitemapLocation.new(
|
192
|
+
:namer => SitemapGenerator::SimpleNamer.new(:sitemap),
|
193
|
+
:host => 'http://example.com',
|
194
|
+
:compress => false
|
195
|
+
)
|
196
|
+
location.url.should == 'http://example.com/sitemap.xml'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe SitemapGenerator::SitemapIndexLocation do
|
202
|
+
let(:location) { SitemapGenerator::SitemapIndexLocation.new }
|
203
|
+
|
204
|
+
it "should have a default namer" do
|
205
|
+
location = SitemapGenerator::SitemapIndexLocation.new
|
206
|
+
location[:namer].should_not be_nil
|
207
|
+
location[:filename].should be_nil
|
208
|
+
location.filename.should == 'sitemap.xml.gz'
|
209
|
+
end
|
210
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SitemapGenerator::SimpleNamer do
|
4
|
+
it "should generate file names" do
|
5
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap)
|
6
|
+
namer.to_s.should == "sitemap.xml.gz"
|
7
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
8
|
+
namer.next.to_s.should == "sitemap2.xml.gz"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should set the file extension" do
|
12
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :extension => '.xyz')
|
13
|
+
namer.to_s.should == "sitemap.xyz"
|
14
|
+
namer.next.to_s.should == "sitemap1.xyz"
|
15
|
+
namer.next.to_s.should == "sitemap2.xyz"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set the starting index" do
|
19
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :start => 10)
|
20
|
+
namer.to_s.should == "sitemap.xml.gz"
|
21
|
+
namer.next.to_s.should == "sitemap10.xml.gz"
|
22
|
+
namer.next.to_s.should == "sitemap11.xml.gz"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should accept a string name" do
|
26
|
+
namer = SitemapGenerator::SimpleNamer.new('abc-def')
|
27
|
+
namer.to_s.should == "abc-def.xml.gz"
|
28
|
+
namer.next.to_s.should == "abc-def1.xml.gz"
|
29
|
+
namer.next.to_s.should == "abc-def2.xml.gz"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return previous name" do
|
33
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap)
|
34
|
+
namer.to_s.should == "sitemap.xml.gz"
|
35
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
36
|
+
namer.previous.to_s.should == "sitemap.xml.gz"
|
37
|
+
namer.next.next.to_s.should == "sitemap2.xml.gz"
|
38
|
+
namer.previous.to_s.should == "sitemap1.xml.gz"
|
39
|
+
namer.next.next.to_s.should == "sitemap3.xml.gz"
|
40
|
+
namer.previous.to_s.should == "sitemap2.xml.gz"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should raise if already at the start" do
|
44
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap)
|
45
|
+
namer.to_s.should == "sitemap.xml.gz"
|
46
|
+
lambda { namer.previous }.should raise_error
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should handle names with underscores" do
|
50
|
+
namer = SitemapGenerator::SimpleNamer.new("sitemap1_")
|
51
|
+
namer.to_s.should == "sitemap1_.xml.gz"
|
52
|
+
namer.next.to_s.should == "sitemap1_1.xml.gz"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should reset the namer" do
|
56
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap)
|
57
|
+
namer.to_s.should == "sitemap.xml.gz"
|
58
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
59
|
+
namer.reset
|
60
|
+
namer.to_s.should == "sitemap.xml.gz"
|
61
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "should handle the zero option" do
|
65
|
+
it "as a string" do
|
66
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :zero => "string")
|
67
|
+
namer.to_s.should == "sitemapstring.xml.gz"
|
68
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "as an integer" do
|
72
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :zero => 0)
|
73
|
+
namer.to_s.should == "sitemap0.xml.gz"
|
74
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "as a string" do
|
78
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :zero => "_index")
|
79
|
+
namer.to_s.should == "sitemap_index.xml.gz"
|
80
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "as a symbol" do
|
84
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :zero => :index)
|
85
|
+
namer.to_s.should == "sitemapindex.xml.gz"
|
86
|
+
namer.next.to_s.should == "sitemap1.xml.gz"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "with a starting index" do
|
90
|
+
namer = SitemapGenerator::SimpleNamer.new(:sitemap, :zero => 'abc', :start => 10)
|
91
|
+
namer.to_s.should == "sitemapabc.xml.gz"
|
92
|
+
namer.next.to_s.should == "sitemap10.xml.gz"
|
93
|
+
namer.next.to_s.should == "sitemap11.xml.gz"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Templates class" do
|
4
|
+
|
5
|
+
it "should provide method access to each template" do
|
6
|
+
SitemapGenerator::Templates::FILES.each do |name, file|
|
7
|
+
SitemapGenerator.templates.send(name).should_not be(nil)
|
8
|
+
SitemapGenerator.templates.send(name).should == File.read(File.join(SitemapGenerator.root, 'templates', file))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "templates" do
|
13
|
+
before :each do
|
14
|
+
SitemapGenerator.templates.sitemap_sample = nil
|
15
|
+
File.expects(:read).returns('read file')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should only be read once" do
|
19
|
+
File.expects(:read).once
|
20
|
+
SitemapGenerator.templates.sitemap_sample
|
21
|
+
SitemapGenerator.templates.sitemap_sample
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class EmptyTrue
|
4
|
+
def empty?() true; end
|
5
|
+
end
|
6
|
+
|
7
|
+
class EmptyFalse
|
8
|
+
def empty?() false; end
|
9
|
+
end
|
10
|
+
|
11
|
+
BLANK = [ EmptyTrue.new, nil, false, '', ' ', " \n\t \r ", [], {} ]
|
12
|
+
NOT = [ EmptyFalse.new, Object.new, true, 0, 1, 'a', [nil], { nil => 0 } ]
|
13
|
+
|
14
|
+
describe Object do
|
15
|
+
let(:utils) { SitemapGenerator::Utilities }
|
16
|
+
|
17
|
+
it "should define blankness" do
|
18
|
+
BLANK.each { |v| utils.blank?(v).should be_true }
|
19
|
+
NOT.each { |v| utils.blank?(v).should be_false }
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should define presence" do
|
23
|
+
BLANK.each { |v| utils.present?(v).should be_false }
|
24
|
+
NOT.each { |v| utils.present?(v).should be_true }
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe SitemapGenerator::Utilities do
|
4
|
+
let(:utils) { SitemapGenerator::Utilities }
|
5
|
+
|
6
|
+
describe "assert_valid_keys" do
|
7
|
+
it "should raise" do
|
8
|
+
lambda do
|
9
|
+
utils.assert_valid_keys({ :failore => "stuff", :funny => "business" }, [ :failure, :funny])
|
10
|
+
utils.assert_valid_keys({ :failore => "stuff", :funny => "business" }, :failure, :funny)
|
11
|
+
end.should raise_error(ArgumentError, "Unknown key(s): failore")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not raise" do
|
15
|
+
lambda do
|
16
|
+
utils.assert_valid_keys({ :failure => "stuff", :funny => "business" }, [ :failure, :funny ])
|
17
|
+
utils.assert_valid_keys({ :failure => "stuff", :funny => "business" }, :failure, :funny)
|
18
|
+
end.should_not raise_error
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "keys" do
|
23
|
+
before :each do
|
24
|
+
@strings = { 'a' => 1, 'b' => 2 }
|
25
|
+
@symbols = { :a => 1, :b => 2 }
|
26
|
+
@mixed = { :a => 1, 'b' => 2 }
|
27
|
+
@fixnums = { 0 => 1, 1 => 2 }
|
28
|
+
if RUBY_VERSION < '1.9.0'
|
29
|
+
@illegal_symbols = { "\0" => 1, "" => 2, [] => 3 }
|
30
|
+
else
|
31
|
+
@illegal_symbols = { [] => 3 }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should symbolize_keys" do
|
36
|
+
utils.symbolize_keys(@symbols).should == @symbols
|
37
|
+
utils.symbolize_keys(@strings).should == @symbols
|
38
|
+
utils.symbolize_keys(@mixed).should == @symbols
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should symbolize_keys!" do
|
42
|
+
utils.symbolize_keys!(@symbols.dup).should == @symbols
|
43
|
+
utils.symbolize_keys!(@strings.dup).should == @symbols
|
44
|
+
utils.symbolize_keys!(@mixed.dup).should == @symbols
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should symbolize_keys_preserves_keys_that_cant_be_symbolized" do
|
48
|
+
utils.symbolize_keys(@illegal_symbols).should == @illegal_symbols
|
49
|
+
utils.symbolize_keys!(@illegal_symbols.dup).should == @illegal_symbols
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should symbolize_keys_preserves_fixnum_keys" do
|
53
|
+
utils.symbolize_keys(@fixnums).should == @fixnums
|
54
|
+
utils.symbolize_keys!(@fixnums.dup).should == @fixnums
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SitemapGenerator::Utilities do
|
4
|
+
describe "rounding" do
|
5
|
+
let(:utils) { SitemapGenerator::Utilities }
|
6
|
+
|
7
|
+
it "should round for positive number" do
|
8
|
+
utils.round(1.4) .should == 1
|
9
|
+
utils.round(1.6) .should == 2
|
10
|
+
utils.round(1.6, 0) .should == 2
|
11
|
+
utils.round(1.4, 1) .should == 1.4
|
12
|
+
utils.round(1.4, 3) .should == 1.4
|
13
|
+
utils.round(1.45, 1) .should == 1.5
|
14
|
+
utils.round(1.445, 2).should == 1.45
|
15
|
+
# Demonstrates a bug in the round method
|
16
|
+
# utils.round(9.995, 2).should == 10
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should round for negative number" do
|
20
|
+
utils.round(-1.4) .should == -1
|
21
|
+
utils.round(-1.6) .should == -2
|
22
|
+
utils.round(-1.4, 1) .should == -1.4
|
23
|
+
utils.round(-1.45, 1).should == -1.5
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should round with negative precision" do
|
27
|
+
utils.round(123456.0, -1).should == 123460.0
|
28
|
+
utils.round(123456.0, -2).should == 123500.0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|