sitemap_generator 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ./
3
3
  specs:
4
- sitemap_generator (3.0.0)
4
+ sitemap_generator (3.1.0)
5
5
  builder
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -36,6 +36,7 @@ Create `sitemap.rb`:
36
36
  add '/home', :changefreq => 'daily', :priority => 0.9
37
37
  add '/contact_us', :changefreq => 'weekly'
38
38
  end
39
+ SitemapGenerator::Sitemap.ping_search_engines # called for you when you use the rake task
39
40
 
40
41
  Run it:
41
42
 
@@ -48,6 +49,11 @@ Output:
48
49
  + sitemap_index.xml.gz 1 sitemaps / 228 Bytes
49
50
  Sitemap stats: 4 links / 1 sitemaps / 0m00s
50
51
 
52
+ Successful ping of Google
53
+ Successful ping of Ask
54
+ Successful ping of Bing
55
+ Successful ping of Sitemap Writer
56
+
51
57
  Contribute
52
58
  -------
53
59
 
@@ -58,6 +64,7 @@ Does your website use SitemapGenerator to generate Sitemaps? Where would you be
58
64
  Changelog
59
65
  -------
60
66
 
67
+ - v3.1.0: Add `add_to_index` method to add links to the sitemap index. Add `sitemap` method for accessing the LinkSet instance from within `create()`. Don't modify options hashes passed to methods. Fix and improve `yield_sitemap` option handling.
61
68
  - **v3.0.0: Framework agnostic**; fix alignment in output, show directory sitemaps are being generated into, only show sitemap compressed file size; toggle output using VERBOSE environment variable; remove tasks/ directory because it's deprecated in Rails 2; Simplify dependencies.
62
69
  - v2.2.1: Support adding new search engines to ping and modifying the default search engines.
63
70
  Allow the URL of the sitemap index to be passed as an argument to `ping_search_engines`. See **Pinging Search Engines**.
@@ -450,7 +457,7 @@ You can read more about `add` in the [XML Specification](http://sitemaps.org/pro
450
457
 
451
458
  Host to use when building the URL. Example:
452
459
 
453
- add '/login', :host => 'https://securehost.com/login'
460
+ add '/login', :host => 'https://securehost.com'
454
461
 
455
462
  * `priority` - Default: `0.5` (Float).
456
463
 
@@ -458,6 +465,55 @@ You can read more about `add` in the [XML Specification](http://sitemaps.org/pro
458
465
 
459
466
  add '/about', :priority => 0.75
460
467
 
468
+ Adding Links to the Sitemap Index
469
+ ----------
470
+
471
+ Sometimes you may need to manually add some links to the sitemap index file. For example if you are generating your sitemaps incrementally you may want to create a sitemap index which includes the files which have already been generated. To achieve this you can use the `add_to_index` method which works exactly the same as the `add` method described above.
472
+
473
+ It supports the same options as `add`, namely:
474
+
475
+ * `changefreq`
476
+ * `lastmod`
477
+ * `host`
478
+
479
+ The value for `host` defaults to whatever you have set as your `sitemaps_host`. Remember that the `sitemaps_host` is the host where your sitemaps reside. If your sitemaps are on the same host as your `default_host`, then the value for `default_host` is used. Example:
480
+
481
+ add_to_index '/mysitemap1.xml.gz', :host => 'http://sitemaphostingserver.com'
482
+
483
+ * `priority`
484
+
485
+ An example:
486
+
487
+ SitemapGenerator::Sitemap.default_host = "http://www.example.com"
488
+ SitemapGenerator::Sitemap.create do
489
+ add_to_index '/mysitemap1.xml.gz'
490
+ add_to_index '/mysitemap2.xml.gz'
491
+ ...
492
+ end
493
+
494
+ Accessing the LinkSet instance
495
+ ----------
496
+
497
+ Sometimes you need to mess with the internals to do custom stuff. If you need access to the LinkSet instance from within `create()` you can use the `sitemap` method to do so.
498
+
499
+ In this example, say we have already pre-generated three sitemap files: `sitemap1.xml.gz`, `sitemap2.xml.gz`, `sitemap3.xml.gz`. Now we want to start the sitemap generation at `sitemap4.xml.gz` and create a bunch of new sitemaps. There are a few ways we can do this, but this is an easy way:
500
+
501
+ SitemapGenerator::Sitemap.default_host = "http://www.example.com"
502
+ SitemapGenerator::Sitemap.create do
503
+ 3.times do |i|
504
+ add_to_index sitemap.sitemaps_namer.to_s
505
+ sitemap.sitemaps_namer.next
506
+ end
507
+ add '/home'
508
+ add '/another'
509
+ end
510
+
511
+ The output looks something like this:
512
+
513
+ In /Users/karl/projects/sitemap_generator-test/public/
514
+ + sitemap4.xml.gz 4 links / 347 Bytes
515
+ + sitemap_index.xml.gz 4 sitemaps / 242 Bytes
516
+ Sitemap stats: 4 links / 4 sitemaps / 0m00s
461
517
 
462
518
  Speeding Things Up
463
519
  ----------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.1.0
@@ -61,7 +61,7 @@ module SitemapGenerator
61
61
 
62
62
  # Returns true if we should yield the sitemap instance to the block, false otherwise.
63
63
  def self.yield_sitemap?
64
- !!@yeild_sitemap
64
+ !!@yield_sitemap
65
65
  end
66
66
 
67
67
  self.root = File.expand_path(File.join(File.dirname(__FILE__), '../')) # Root of the install dir, not the Rails app
@@ -6,7 +6,7 @@ module SitemapGenerator
6
6
 
7
7
  def initialize(path, options={})
8
8
  if index = path.is_a?(SitemapGenerator::Builder::SitemapIndexFile) && path
9
- SitemapGenerator::Utilities.reverse_merge!(options, :host => index.location.host, :lastmod => Time.now, :changefreq => 'always', :priority => 1.0)
9
+ options = SitemapGenerator::Utilities.reverse_merge(options, :host => index.location.host, :lastmod => Time.now, :changefreq => 'always', :priority => 1.0)
10
10
  path = index.location.path_in_public
11
11
  super(path, options)
12
12
  else
@@ -27,6 +27,7 @@ module SitemapGenerator
27
27
  # * +geo+
28
28
  # * +news+
29
29
  def initialize(path, options={})
30
+ options = options.dup
30
31
  if sitemap = path.is_a?(SitemapGenerator::Builder::SitemapFile) && path
31
32
  SitemapGenerator::Utilities.reverse_merge!(options, :host => sitemap.location.host, :lastmod => sitemap.lastmod)
32
33
  path = sitemap.location.path_in_public
@@ -21,7 +21,7 @@ module SitemapGenerator
21
21
  #
22
22
  # All other options are passed to the LinkSet by setting them using accessor methods.
23
23
  def initialize(opts={}, &block)
24
- SitemapGenerator::Utilities.reverse_merge!(opts, :link_set => SitemapGenerator::Sitemap)
24
+ opts = SitemapGenerator::Utilities.reverse_merge(opts, :link_set => SitemapGenerator::Sitemap)
25
25
  @linkset = opts.delete :link_set
26
26
  @linkset.send(:set_options, opts)
27
27
  eval(&block) if block_given?
@@ -31,6 +31,10 @@ module SitemapGenerator
31
31
  @linkset.add(*args)
32
32
  end
33
33
 
34
+ def add_to_index(*args)
35
+ @linkset.add_to_index(*args)
36
+ end
37
+
34
38
  # Start a new group of sitemaps. Any of the options to SitemapGenerator.new may
35
39
  # be passed. Pass a block with calls to +add+ to add links to the sitemaps.
36
40
  #
@@ -39,12 +43,18 @@ module SitemapGenerator
39
43
  @linkset.group(*args, &block)
40
44
  end
41
45
 
46
+ # Return the LinkSet instance so that you can access it from within the `create` block
47
+ # without having to use the yield_sitemap option.
48
+ def sitemap
49
+ @linkset
50
+ end
51
+
42
52
  # Evaluate the block in the interpreter. Pass :yield_sitemap => true to
43
53
  # yield the Interpreter instance to the block...for old-style calling.
44
54
  def eval(opts={}, &block)
45
55
  if block_given?
46
56
  if opts[:yield_sitemap]
47
- yield self
57
+ yield @linkset
48
58
  else
49
59
  instance_eval(&block)
50
60
  end
@@ -59,6 +69,7 @@ module SitemapGenerator
59
69
  # Default is config/sitemap.rb in your application's root directory.
60
70
  # All other options are passed to +new+.
61
71
  def self.run(opts={}, &block)
72
+ opts = opts.dup
62
73
  config_file = opts.delete(:config_file)
63
74
  config_file ||= SitemapGenerator.app.root + 'config/sitemap.rb'
64
75
  interpreter = self.new(opts)
@@ -8,7 +8,7 @@ module SitemapGenerator
8
8
  @@new_location_opts = [:filename, :sitemaps_path, :sitemaps_namer]
9
9
 
10
10
  attr_reader :default_host, :sitemaps_path, :filename
11
- attr_accessor :verbose, :yahoo_app_id, :include_root, :include_index, :sitemaps_host, :adapter
11
+ attr_accessor :verbose, :yahoo_app_id, :include_root, :include_index, :sitemaps_host, :adapter, :yield_sitemap
12
12
 
13
13
  # Create a new sitemap index and sitemap files. Pass a block calls to the following
14
14
  # methods:
@@ -36,7 +36,7 @@ module SitemapGenerator
36
36
  start_time = Time.now
37
37
  puts "In #{sitemap_index.location.public_path}"
38
38
  end
39
- interpreter.eval(:yield_sitemap => @yield_sitemap || SitemapGenerator.yield_sitemap?, &block)
39
+ interpreter.eval(:yield_sitemap => yield_sitemap?, &block)
40
40
  finalize!
41
41
  end_time = Time.now if verbose
42
42
  output(sitemap_index.stats_summary(:time_taken => end_time - start_time)) if verbose
@@ -45,9 +45,10 @@ module SitemapGenerator
45
45
 
46
46
  # Dreprecated. Use create.
47
47
  def add_links(&block)
48
+ original_value = @yield_sitemap
48
49
  @yield_sitemap = true
49
50
  create(&block)
50
- @yield_sitemap = false
51
+ @yield_sitemap = original_value
51
52
  end
52
53
 
53
54
  # Constructor
@@ -99,7 +100,7 @@ module SitemapGenerator
99
100
  # * <tt>:verbose</tt> - If +true+, output a summary line for each sitemap and sitemap
100
101
  # index that is created. Default is +false+.
101
102
  def initialize(options={})
102
- SitemapGenerator::Utilities.reverse_merge!(options,
103
+ options = SitemapGenerator::Utilities.reverse_merge(options,
103
104
  :include_root => true,
104
105
  :include_index => true,
105
106
  :filename => :sitemap,
@@ -127,7 +128,7 @@ module SitemapGenerator
127
128
  # host - host for the link, defaults to your <tt>default_host</tt>.
128
129
  def add(link, options={})
129
130
  add_default_links if !@added_default_links
130
- sitemap.add(link, SitemapGenerator::Utilities.reverse_merge!(options, :host => @default_host))
131
+ sitemap.add(link, SitemapGenerator::Utilities.reverse_merge(options, :host => @default_host))
131
132
  rescue SitemapGenerator::SitemapFullError
132
133
  finalize_sitemap!
133
134
  retry
@@ -136,6 +137,16 @@ module SitemapGenerator
136
137
  retry
137
138
  end
138
139
 
140
+ # Add a link to the Sitemap Index.
141
+ # * link - A string link e.g. '/sitemaps/sitemap1.xml.gz' or a SitemapFile instance.
142
+ # * options - A hash of options including `:lastmod`, ':priority`, ':changefreq` and `:host`
143
+ #
144
+ # The `:host` option defaults to the value of `sitemaps_host` which is the host where your
145
+ # sitemaps reside. If no `sitemaps_host` is set, the `default_host` is used.
146
+ def add_to_index(link, options={})
147
+ sitemap_index.add(link, SitemapGenerator::Utilities.reverse_merge(options, :host => sitemaps_host))
148
+ end
149
+
139
150
  # Create a new group of sitemap files.
140
151
  #
141
152
  # Returns a new LinkSet instance with the options passed in set on it. All groups
@@ -310,6 +321,11 @@ module SitemapGenerator
310
321
  @verbose
311
322
  end
312
323
 
324
+ # Return a boolean indicating whether or not to yield the sitemap.
325
+ def yield_sitemap?
326
+ @yield_sitemap.nil? ? SitemapGenerator.yield_sitemap? : !!@yield_sitemap
327
+ end
328
+
313
329
  protected
314
330
 
315
331
  # Set each option on this instance using accessor methods. This will affect
@@ -318,6 +334,7 @@ module SitemapGenerator
318
334
  # If both `filename` and `sitemaps_namer` are passed, set filename first so it
319
335
  # doesn't override the latter.
320
336
  def set_options(opts={})
337
+ opts = opts.dup
321
338
  %w(filename sitemaps_namer).each do |key|
322
339
  if value = opts.delete(key.to_sym)
323
340
  send("#{key}=", value)
@@ -332,12 +349,12 @@ module SitemapGenerator
332
349
  # If <tt>:public_path</tt> is present in +opts+ it is removed because groups cannot
333
350
  # change the public path.
334
351
  def options_for_group(opts)
335
- opts.delete(:public_path)
336
- SitemapGenerator::Utilities.reverse_merge!(opts,
352
+ opts = SitemapGenerator::Utilities.reverse_merge(opts,
337
353
  :include_index => false,
338
354
  :include_root => false,
339
355
  :sitemap_index => sitemap_index
340
356
  )
357
+ opts.delete(:public_path)
341
358
 
342
359
  # Reverse merge the current settings
343
360
  current_settings = [
@@ -384,7 +401,7 @@ module SitemapGenerator
384
401
  def finalize_sitemap!
385
402
  add_default_links if !@added_default_links && !@created_group
386
403
  return if sitemap.finalized? || sitemap.empty? && @created_group
387
- sitemap_index.add(sitemap)
404
+ add_to_index(sitemap)
388
405
  output(sitemap.summary)
389
406
  end
390
407
 
@@ -543,7 +560,7 @@ module SitemapGenerator
543
560
  # Update the given attribute on the current sitemap index and sitemap file location objects.
544
561
  # But don't create the index or sitemap files yet if they are not already created.
545
562
  def update_location_info(attribute, value, opts={})
546
- SitemapGenerator::Utilities.reverse_merge!(opts, :include_index => !@protect_index)
563
+ opts = SitemapGenerator::Utilities.reverse_merge(opts, :include_index => !@protect_index)
547
564
  @sitemap_index.location[attribute] = value if opts[:include_index] && @sitemap_index && !@sitemap_index.finalized?
548
565
  @sitemap.location[attribute] = value if @sitemap && !@sitemap.finalized?
549
566
  end
@@ -2,6 +2,9 @@ require 'spec_helper'
2
2
  require 'sitemap_generator/interpreter'
3
3
 
4
4
  describe SitemapGenerator::Interpreter do
5
+ let(:link_set) { SitemapGenerator::LinkSet.new }
6
+ let(:interpreter) { SitemapGenerator::Interpreter.new(:link_set => link_set) }
7
+
5
8
  # The interpreter doesn't have the URL helpers included for some reason, so it
6
9
  # fails when adding links. That messes up later specs unless we reset the sitemap object.
7
10
  after :all do
@@ -21,4 +24,67 @@ describe SitemapGenerator::Interpreter do
21
24
  interpreter = SitemapGenerator::Interpreter.run(:verbose => true)
22
25
  interpreter.instance_variable_get(:@linkset).verbose.should be_true
23
26
  end
27
+
28
+ describe "link_set" do
29
+ it "should default to the default LinkSet" do
30
+ SitemapGenerator::Interpreter.new.sitemap.should be(SitemapGenerator::Sitemap)
31
+ end
32
+
33
+ it "should allow setting the LinkSet as an option" do
34
+ interpreter.sitemap.should be(link_set)
35
+ end
36
+ end
37
+
38
+ describe "public interface" do
39
+ describe "add" do
40
+ it "should add a link to the sitemap" do
41
+ link_set.expects(:add).with('test', :option => 'value')
42
+ interpreter.add('test', :option => 'value')
43
+ end
44
+ end
45
+
46
+ describe "group" do
47
+ it "should start a new group" do
48
+ link_set.expects(:group).with('test', :option => 'value')
49
+ interpreter.group('test', :option => 'value')
50
+ end
51
+ end
52
+
53
+ describe "sitemap" do
54
+ it "should return the LinkSet" do
55
+ interpreter.sitemap.should be(link_set)
56
+ end
57
+ end
58
+
59
+ describe "add_to_index" do
60
+ it "should add a link to the sitemap index" do
61
+ link_set.expects(:add_to_index).with('test', :option => 'value')
62
+ interpreter.add_to_index('test', :option => 'value')
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "eval" do
68
+ it "should yield the LinkSet to the block" do
69
+ interpreter.eval(:yield_sitemap => true) do |sitemap|
70
+ sitemap.should be(link_set)
71
+ end
72
+ end
73
+
74
+ it "should not yield the LinkSet to the block" do
75
+ local = interpreter # prevent undefined method
76
+ local_be = self.method(:be) # prevent undefined method
77
+ local.eval(:yield_sitemap => false) do
78
+ self.should local_be.call(local)
79
+ end
80
+ end
81
+
82
+ it "should not yield the LinkSet to the block by default" do
83
+ local = interpreter # prevent undefined method
84
+ local_be = self.method(:be) # prevent undefined method
85
+ local.eval do
86
+ self.should local_be.call(local)
87
+ end
88
+ end
89
+ end
24
90
  end
@@ -1,10 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SitemapGenerator::LinkSet do
4
- before :each do
5
- @default_host = 'http://example.com'
6
- @ls = SitemapGenerator::LinkSet.new
7
- end
4
+ let(:default_host) { 'http://example.com' }
5
+ let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host) }
8
6
 
9
7
  describe "initializer options" do
10
8
  options = [:public_path, :sitemaps_path, :default_host, :filename, :search_engines]
@@ -12,13 +10,15 @@ describe SitemapGenerator::LinkSet do
12
10
 
13
11
  options.zip(values).each do |option, value|
14
12
  it "should set #{option} to #{value}" do
15
- @ls = SitemapGenerator::LinkSet.new(option => value)
16
- @ls.send(option).should == value
13
+ ls = SitemapGenerator::LinkSet.new(option => value)
14
+ ls.send(option).should == value
17
15
  end
18
16
  end
19
17
  end
20
18
 
21
19
  describe "default options" do
20
+ let(:ls) { SitemapGenerator::LinkSet.new }
21
+
22
22
  default_options = {
23
23
  :filename => :sitemap,
24
24
  :sitemaps_path => nil,
@@ -30,84 +30,84 @@ describe SitemapGenerator::LinkSet do
30
30
 
31
31
  default_options.each do |option, value|
32
32
  it "#{option} should default to #{value}" do
33
- @ls.send(option).should == value
33
+ ls.send(option).should == value
34
34
  end
35
35
  end
36
36
  end
37
37
 
38
38
  describe "include_root include_index option" do
39
39
  it "should not include the root url" do
40
- @ls = SitemapGenerator::LinkSet.new(:default_host => @default_host, :include_root => false)
41
- @ls.include_root.should be_false
42
- @ls.include_index.should be_true
43
- @ls.add_links { |sitemap| }
44
- @ls.sitemap.link_count.should == 1
40
+ ls = SitemapGenerator::LinkSet.new(:default_host => default_host, :include_root => false)
41
+ ls.include_root.should be_false
42
+ ls.include_index.should be_true
43
+ ls.add_links { |sitemap| }
44
+ ls.sitemap.link_count.should == 1
45
45
  end
46
46
 
47
47
  it "should not include the sitemap index url" do
48
- @ls = SitemapGenerator::LinkSet.new(:default_host => @default_host, :include_index => false)
49
- @ls.include_root.should be_true
50
- @ls.include_index.should be_false
51
- @ls.add_links { |sitemap| }
52
- @ls.sitemap.link_count.should == 1
48
+ ls = SitemapGenerator::LinkSet.new(:default_host => default_host, :include_index => false)
49
+ ls.include_root.should be_true
50
+ ls.include_index.should be_false
51
+ ls.add_links { |sitemap| }
52
+ ls.sitemap.link_count.should == 1
53
53
  end
54
54
 
55
55
  it "should not include the root url or the sitemap index url" do
56
- @ls = SitemapGenerator::LinkSet.new(:default_host => @default_host, :include_root => false, :include_index => false)
57
- @ls.include_root.should be_false
58
- @ls.include_index.should be_false
59
- @ls.add_links { |sitemap| }
60
- @ls.sitemap.link_count.should == 0
56
+ ls = SitemapGenerator::LinkSet.new(:default_host => default_host, :include_root => false, :include_index => false)
57
+ ls.include_root.should be_false
58
+ ls.include_index.should be_false
59
+ ls.add_links { |sitemap| }
60
+ ls.sitemap.link_count.should == 0
61
61
  end
62
62
  end
63
63
 
64
64
  describe "sitemaps public_path" do
65
65
  it "should default to public/" do
66
- @ls.public_path.should == SitemapGenerator.app.root + 'public/'
67
- @ls.sitemap.location.public_path.should == @ls.public_path
68
- @ls.sitemap_index.location.public_path.should == @ls.public_path
66
+ ls.public_path.should == SitemapGenerator.app.root + 'public/'
67
+ ls.sitemap.location.public_path.should == ls.public_path
68
+ ls.sitemap_index.location.public_path.should == ls.public_path
69
69
  end
70
70
 
71
71
  it "should change when the public_path is changed" do
72
- @ls.public_path = 'tmp'
73
- @ls.sitemap.location.public_path.should == @ls.public_path
74
- @ls.sitemap_index.location.public_path.should == @ls.public_path
72
+ ls.public_path = 'tmp'
73
+ ls.sitemap.location.public_path.should == ls.public_path
74
+ ls.sitemap_index.location.public_path.should == ls.public_path
75
75
  end
76
76
  end
77
77
 
78
78
  describe "sitemaps url" do
79
79
  it "should change when the default_host is changed" do
80
- @ls.default_host = 'http://one.com'
81
- @ls.default_host.should == 'http://one.com'
82
- @ls.default_host.should == @ls.sitemap.location.host
83
- @ls.default_host.should == @ls.sitemap_index.location.host
80
+ ls.default_host = 'http://one.com'
81
+ ls.default_host.should == 'http://one.com'
82
+ ls.default_host.should == ls.sitemap.location.host
83
+ ls.default_host.should == ls.sitemap_index.location.host
84
84
  end
85
85
 
86
86
  it "should change when the sitemaps_path is changed" do
87
- @ls.default_host = 'http://one.com'
88
- @ls.sitemaps_path = 'sitemaps/'
89
- @ls.sitemap.location.url.should == 'http://one.com/sitemaps/sitemap1.xml.gz'
90
- @ls.sitemap_index.location.url.should == 'http://one.com/sitemaps/sitemap_index.xml.gz'
87
+ ls.default_host = 'http://one.com'
88
+ ls.sitemaps_path = 'sitemaps/'
89
+ ls.sitemap.location.url.should == 'http://one.com/sitemaps/sitemap1.xml.gz'
90
+ ls.sitemap_index.location.url.should == 'http://one.com/sitemaps/sitemap_index.xml.gz'
91
91
  end
92
92
  end
93
93
 
94
94
  describe "sitemap_index_url" do
95
95
  it "should return the url to the index file" do
96
- @ls.default_host = @default_host
97
- @ls.sitemap_index.location.url.should == "#{@default_host}/sitemap_index.xml.gz"
98
- @ls.sitemap_index_url.should == @ls.sitemap_index.location.url
96
+ ls.default_host = default_host
97
+ ls.sitemap_index.location.url.should == "#{default_host}/sitemap_index.xml.gz"
98
+ ls.sitemap_index_url.should == ls.sitemap_index.location.url
99
99
  end
100
100
  end
101
101
 
102
102
  describe "search_engines" do
103
103
  it "should have search engines by default" do
104
- @ls.search_engines.should be_a(Hash)
105
- @ls.search_engines.size.should == 4
104
+ ls.search_engines.should be_a(Hash)
105
+ ls.search_engines.size.should == 4
106
106
  end
107
107
 
108
108
  it "should support being modified" do
109
- @ls.search_engines[:newengine] = 'abc'
110
- @ls.search_engines.size.should == 5
109
+ ls.search_engines[:newengine] = 'abc'
110
+ ls.search_engines.size.should == 5
111
111
  end
112
112
 
113
113
  it "should support being set to nil" do
@@ -121,13 +121,9 @@ describe SitemapGenerator::LinkSet do
121
121
  end
122
122
 
123
123
  describe "ping search engines" do
124
- before do
125
- @ls = SitemapGenerator::LinkSet.new :default_host => 'http://one.com'
126
- end
127
-
128
124
  it "should not fail" do
129
- @ls.expects(:open).at_least_once
130
- lambda { @ls.ping_search_engines }.should_not raise_error
125
+ ls.expects(:open).at_least_once
126
+ lambda { ls.ping_search_engines }.should_not raise_error
131
127
  end
132
128
 
133
129
  it "should raise if no host is set" do
@@ -143,7 +139,7 @@ describe SitemapGenerator::LinkSet do
143
139
 
144
140
  it "should use the sitemap index url from the link set" do
145
141
  ls = SitemapGenerator::LinkSet.new(
146
- :default_host => 'http://one.com',
142
+ :default_host => default_host,
147
143
  :search_engines => { :google => 'http://google.com/?url=%s' })
148
144
  index_url = ls.sitemap_index_url
149
145
  ls.expects(:open).with("http://google.com/?url=#{CGI.escape(index_url)}")
@@ -151,30 +147,26 @@ describe SitemapGenerator::LinkSet do
151
147
  end
152
148
 
153
149
  it "should include the given search engines" do
154
- @ls.search_engines = nil
155
- @ls.expects(:open).with(regexp_matches(/^http:\/\/newnegine\.com\?/))
156
- @ls.ping_search_engines(:newengine => 'http://newnegine.com?%s')
150
+ ls.search_engines = nil
151
+ ls.expects(:open).with(regexp_matches(/^http:\/\/newnegine\.com\?/))
152
+ ls.ping_search_engines(:newengine => 'http://newnegine.com?%s')
157
153
 
158
- @ls.expects(:open).with(regexp_matches(/^http:\/\/newnegine\.com\?/)).twice
159
- @ls.ping_search_engines(:newengine => 'http://newnegine.com?%s', :anotherengine => 'http://newnegine.com?%s')
154
+ ls.expects(:open).with(regexp_matches(/^http:\/\/newnegine\.com\?/)).twice
155
+ ls.ping_search_engines(:newengine => 'http://newnegine.com?%s', :anotherengine => 'http://newnegine.com?%s')
160
156
  end
161
157
  end
162
158
 
163
159
  describe "verbose" do
164
- before do
165
- @ls = SitemapGenerator::LinkSet.new(:default_host => 'http://one.com')
166
- end
167
-
168
160
  it "should be set as an initialize option" do
169
- SitemapGenerator::LinkSet.new(:default_host => 'http://one.com', :verbose => false).verbose.should be_false
170
- SitemapGenerator::LinkSet.new(:default_host => 'http://one.com', :verbose => true).verbose.should be_true
161
+ SitemapGenerator::LinkSet.new(:default_host => default_host, :verbose => false).verbose.should be_false
162
+ SitemapGenerator::LinkSet.new(:default_host => default_host, :verbose => true).verbose.should be_true
171
163
  end
172
164
 
173
165
  it "should be set as an accessor" do
174
- @ls.verbose = true
175
- @ls.verbose.should be_true
176
- @ls.verbose = false
177
- @ls.verbose.should be_false
166
+ ls.verbose = true
167
+ ls.verbose.should be_true
168
+ ls.verbose = false
169
+ ls.verbose.should be_false
178
170
  end
179
171
 
180
172
  it "should use SitemapGenerator.verbose as a default" do
@@ -182,54 +174,49 @@ describe SitemapGenerator::LinkSet do
182
174
  SitemapGenerator::LinkSet.new.verbose.should be_true
183
175
  SitemapGenerator.expects(:verbose).returns(false).at_least_once
184
176
  SitemapGenerator::LinkSet.new.verbose.should be_false
185
- end
177
+ end
186
178
  end
187
179
 
188
180
  describe "when finalizing" do
189
- before do
190
- @ls = SitemapGenerator::LinkSet.new(:default_host => 'http://one.com', :verbose => true)
191
- end
181
+ let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host, :verbose => true) }
192
182
 
193
183
  it "should output summary lines" do
194
- @ls.sitemap.expects(:finalize!)
195
- @ls.sitemap.expects(:summary)
196
- @ls.sitemap_index.expects(:finalize!)
197
- @ls.sitemap_index.expects(:summary)
198
- @ls.finalize!
184
+ ls.sitemap.expects(:finalize!)
185
+ ls.sitemap.expects(:summary)
186
+ ls.sitemap_index.expects(:finalize!)
187
+ ls.sitemap_index.expects(:summary)
188
+ ls.finalize!
199
189
  end
200
190
  end
201
191
 
202
192
  describe "sitemaps host" do
203
- before do
204
- @new_host = 'http://wowza.com'
205
- @ls = SitemapGenerator::LinkSet.new(:default_host => @default_host)
206
- end
193
+ let(:new_host) { 'http://wowza.com' }
207
194
 
208
195
  it "should have a host" do
209
- @ls.default_host = @default_host
210
- @ls.default_host.should == @default_host
196
+ ls.default_host = default_host
197
+ ls.default_host.should == default_host
211
198
  end
212
199
 
213
200
  it "should default to default host" do
214
- @ls.sitemaps_host.should == @ls.default_host
201
+ ls.sitemaps_host.should == ls.default_host
215
202
  end
216
203
 
217
204
  it "should update the host in the sitemaps when changed" do
218
- @ls.sitemaps_host = @new_host
219
- @ls.sitemaps_host.should == @new_host
220
- @ls.sitemap.location.host.should == @ls.sitemaps_host
221
- @ls.sitemap_index.location.host.should == @ls.sitemaps_host
205
+ ls.sitemaps_host = new_host
206
+ ls.sitemaps_host.should == new_host
207
+ ls.sitemap.location.host.should == ls.sitemaps_host
208
+ ls.sitemap_index.location.host.should == ls.sitemaps_host
222
209
  end
223
210
 
224
211
  it "should not change the default host for links" do
225
- @ls.sitemaps_host = @new_host
226
- @ls.default_host.should == @default_host
212
+ ls.sitemaps_host = new_host
213
+ ls.default_host.should == default_host
227
214
  end
228
215
  end
229
216
 
230
217
  describe "with a sitemap index specified" do
231
218
  before :each do
232
- @index = SitemapGenerator::Builder::SitemapIndexFile.new(:host => @default_host)
219
+ @index = SitemapGenerator::Builder::SitemapIndexFile.new(:host => default_host)
233
220
  @ls = SitemapGenerator::LinkSet.new(:sitemap_index => @index, :sitemaps_host => 'http://newhost.com')
234
221
  end
235
222
 
@@ -242,7 +229,7 @@ describe SitemapGenerator::LinkSet do
242
229
  it "should not modify the index" do
243
230
  @ls.sitemaps_host = 'http://newhost.com'
244
231
  @ls.sitemap.location.host.should == 'http://newhost.com'
245
- @ls.sitemap_index.location.host.should == @default_host
232
+ @ls.sitemap_index.location.host.should == default_host
246
233
  end
247
234
 
248
235
  it "should not finalize the index" do
@@ -252,55 +239,51 @@ describe SitemapGenerator::LinkSet do
252
239
  end
253
240
 
254
241
  describe "new group" do
255
- before :each do
256
- @ls = SitemapGenerator::LinkSet.new(:default_host => @default_host)
257
- end
258
-
259
242
  describe "general behaviour" do
260
243
  it "should return a LinkSet" do
261
- @ls.group.should be_a(SitemapGenerator::LinkSet)
244
+ ls.group.should be_a(SitemapGenerator::LinkSet)
262
245
  end
263
246
 
264
247
  it "should inherit the index" do
265
- @ls.group.sitemap_index.should == @ls.sitemap_index
248
+ ls.group.sitemap_index.should == ls.sitemap_index
266
249
  end
267
250
 
268
251
  it "should protect the sitemap_index" do
269
- @ls.group.instance_variable_get(:@protect_index).should be_true
252
+ ls.group.instance_variable_get(:@protect_index).should be_true
270
253
  end
271
254
 
272
255
  it "should not allow chaning the public_path" do
273
- @ls.group(:public_path => 'new/path/').public_path.to_s.should == @ls.public_path.to_s
256
+ ls.group(:public_path => 'new/path/').public_path.to_s.should == ls.public_path.to_s
274
257
  end
275
258
  end
276
259
 
277
260
  describe "include_index" do
278
261
  it "should set the value" do
279
- @ls.group(:include_index => !@ls.include_index).include_index.should_not == @ls.include_index
262
+ ls.group(:include_index => !ls.include_index).include_index.should_not == ls.include_index
280
263
  end
281
264
 
282
265
  it "should default to false" do
283
- @ls.group.include_index.should be_false
266
+ ls.group.include_index.should be_false
284
267
  end
285
268
  end
286
269
 
287
270
  describe "include_root" do
288
271
  it "should set the value" do
289
- @ls.group(:include_root => !@ls.include_root).include_root.should_not == @ls.include_root
272
+ ls.group(:include_root => !ls.include_root).include_root.should_not == ls.include_root
290
273
  end
291
274
 
292
275
  it "should default to false" do
293
- @ls.group.include_root.should be_false
276
+ ls.group.include_root.should be_false
294
277
  end
295
278
  end
296
279
 
297
280
  describe "filename" do
298
281
  it "should inherit the value" do
299
- @ls.group.filename.should == :sitemap
282
+ ls.group.filename.should == :sitemap
300
283
  end
301
284
 
302
285
  it "should set the value" do
303
- group = @ls.group(:filename => :xxx)
286
+ group = ls.group(:filename => :xxx)
304
287
  group.filename.should == :xxx
305
288
  group.sitemap.location.filename.should =~ /xxx/
306
289
  end
@@ -308,24 +291,24 @@ describe SitemapGenerator::LinkSet do
308
291
 
309
292
  describe "verbose" do
310
293
  it "should inherit the value" do
311
- @ls.group.verbose.should == @ls.verbose
294
+ ls.group.verbose.should == ls.verbose
312
295
  end
313
296
 
314
297
  it "should set the value" do
315
- @ls.group(:verbose => !@ls.verbose).verbose.should_not == @ls.verbose
298
+ ls.group(:verbose => !ls.verbose).verbose.should_not == ls.verbose
316
299
  end
317
300
  end
318
301
 
319
302
  describe "sitemaps_path" do
320
303
  it "should inherit the sitemaps_path" do
321
- group = @ls.group
322
- group.sitemaps_path.should == @ls.sitemaps_path
323
- group.sitemap.location.sitemaps_path.should == @ls.sitemap.location.sitemaps_path
304
+ group = ls.group
305
+ group.sitemaps_path.should == ls.sitemaps_path
306
+ group.sitemap.location.sitemaps_path.should == ls.sitemap.location.sitemaps_path
324
307
  end
325
308
 
326
309
  it "should set the sitemaps_path" do
327
310
  path = 'new/path'
328
- group = @ls.group(:sitemaps_path => path)
311
+ group = ls.group(:sitemaps_path => path)
329
312
  group.sitemaps_path.should == path
330
313
  group.sitemap.location.sitemaps_path.to_s.should == path
331
314
  end
@@ -333,12 +316,12 @@ describe SitemapGenerator::LinkSet do
333
316
 
334
317
  describe "default_host" do
335
318
  it "should inherit the default_host" do
336
- @ls.group.default_host.should == @default_host
319
+ ls.group.default_host.should == default_host
337
320
  end
338
321
 
339
322
  it "should set the default_host" do
340
323
  host = 'http://defaulthost.com'
341
- group = @ls.group(:default_host => host)
324
+ group = ls.group(:default_host => host)
342
325
  group.default_host.should == host
343
326
  group.sitemap.location.host.should == host
344
327
  end
@@ -347,31 +330,31 @@ describe SitemapGenerator::LinkSet do
347
330
  describe "sitemaps_host" do
348
331
  it "should set the sitemaps host" do
349
332
  @host = 'http://sitemaphost.com'
350
- @group = @ls.group(:sitemaps_host => @host)
333
+ @group = ls.group(:sitemaps_host => @host)
351
334
  @group.sitemaps_host.should == @host
352
335
  @group.sitemap.location.host.should == @host
353
336
  end
354
337
 
355
338
  it "should finalize the sitemap if it is the only option" do
356
- @ls.expects(:finalize_sitemap!)
357
- @ls.group(:sitemaps_host => 'http://test.com') {}
339
+ ls.expects(:finalize_sitemap!)
340
+ ls.group(:sitemaps_host => 'http://test.com') {}
358
341
  end
359
342
 
360
343
  it "should use the same sitemaps_namer" do
361
- @group = @ls.group(:sitemaps_host => 'http://test.com') {}
362
- @group.sitemap.location.namer.should == @ls.sitemap.location.namer
344
+ @group = ls.group(:sitemaps_host => 'http://test.com') {}
345
+ @group.sitemap.location.namer.should == ls.sitemap.location.namer
363
346
  end
364
347
  end
365
348
 
366
349
  describe "sitemaps_namer" do
367
350
  it "should inherit the value" do
368
- @ls.group.sitemaps_namer.should == @ls.sitemaps_namer
369
- @ls.group.sitemap.location.namer.should == @ls.sitemaps_namer
351
+ ls.group.sitemaps_namer.should == ls.sitemaps_namer
352
+ ls.group.sitemap.location.namer.should == ls.sitemaps_namer
370
353
  end
371
354
 
372
355
  it "should set the value" do
373
356
  namer = SitemapGenerator::SitemapNamer.new(:xxx)
374
- group = @ls.group(:sitemaps_namer => namer)
357
+ group = ls.group(:sitemaps_namer => namer)
375
358
  group.sitemaps_namer.should == namer
376
359
  group.sitemap.location.namer.should == namer
377
360
  group.sitemap.location.filename.should =~ /xxx/
@@ -380,8 +363,8 @@ describe SitemapGenerator::LinkSet do
380
363
 
381
364
  describe "should share the current sitemap" do
382
365
  it "if only default_host is passed" do
383
- group = @ls.group(:default_host => 'http://newhost.com')
384
- group.sitemap.should == @ls.sitemap
366
+ group = ls.group(:default_host => 'http://newhost.com')
367
+ group.sitemap.should == ls.sitemap
385
368
  group.sitemap.location.host.should == 'http://newhost.com'
386
369
  end
387
370
  end
@@ -394,26 +377,26 @@ describe SitemapGenerator::LinkSet do
394
377
  :sitemaps_namer => SitemapGenerator::SitemapNamer.new(:sitemap)
395
378
  }.each do |key, value|
396
379
  it "if #{key} is present" do
397
- @ls.group(key => value).sitemap.should_not == @ls.sitemap
380
+ ls.group(key => value).sitemap.should_not == ls.sitemap
398
381
  end
399
382
  end
400
383
  end
401
384
 
402
385
  describe "finalizing" do
403
386
  it "should finalize the sitemaps if a block is passed" do
404
- @group = @ls.group
387
+ @group = ls.group
405
388
  @group.sitemap.finalized?.should be_false
406
389
  end
407
390
 
408
391
  it "should only finalize the sitemaps if a block is passed" do
409
- @group = @ls.group
392
+ @group = ls.group
410
393
  @group.sitemap.finalized?.should be_false
411
394
  end
412
395
 
413
396
  it "should not finalize the sitemap if a group is created" do
414
- @ls.create { group {} }
415
- @ls.sitemap.empty?.should be_true
416
- @ls.sitemap.finalized?.should be_false
397
+ ls.create { group {} }
398
+ ls.sitemap.empty?.should be_true
399
+ ls.sitemap.finalized?.should be_false
417
400
  end
418
401
 
419
402
  {:sitemaps_path => 'en/',
@@ -421,86 +404,81 @@ describe SitemapGenerator::LinkSet do
421
404
  :sitemaps_namer => SitemapGenerator::SitemapNamer.new(:sitemap)}.each do |k, v|
422
405
 
423
406
  it "should not finalize the sitemap if #{k} is present" do
424
- @ls.expects(:finalize_sitemap!).never
425
- @ls.group(k => v) { }
407
+ ls.expects(:finalize_sitemap!).never
408
+ ls.group(k => v) { }
426
409
  end
427
410
  end
428
411
  end
429
412
  end
430
413
 
431
414
  describe "after create" do
432
- before :each do
433
- @ls = SitemapGenerator::LinkSet.new :default_host => @default_host
434
- end
435
-
436
415
  it "should finalize the sitemap index" do
437
- @ls.create {}
438
- @ls.sitemap_index.finalized?.should be_true
416
+ ls.create {}
417
+ ls.sitemap_index.finalized?.should be_true
439
418
  end
440
419
 
441
420
  it "should finalize the sitemap" do
442
- @ls.create {}
443
- @ls.sitemap.finalized?.should be_true
421
+ ls.create {}
422
+ ls.sitemap.finalized?.should be_true
444
423
  end
445
424
 
446
425
  it "should not finalize the sitemap if a group was created" do
447
- @ls.instance_variable_set(:@created_group, true)
448
- @ls.send(:finalize_sitemap!)
449
- @ls.sitemap.finalized?.should be_false
426
+ ls.instance_variable_set(:@created_group, true)
427
+ ls.send(:finalize_sitemap!)
428
+ ls.sitemap.finalized?.should be_false
450
429
  end
451
430
  end
452
431
 
453
432
  describe "options to create" do
454
433
  before :each do
455
- @ls = SitemapGenerator::LinkSet.new(:default_host => @default_host)
456
- @ls.expects(:finalize!)
434
+ ls.stubs(:finalize!)
457
435
  end
458
436
 
459
437
  it "should set include_index" do
460
- original = @ls.include_index
461
- @ls.create(:include_index => !original).include_index.should_not == original
438
+ original = ls.include_index
439
+ ls.create(:include_index => !original).include_index.should_not == original
462
440
  end
463
441
 
464
442
  it "should set include_root" do
465
- original = @ls.include_root
466
- @ls.create(:include_root => !original).include_root.should_not == original
443
+ original = ls.include_root
444
+ ls.create(:include_root => !original).include_root.should_not == original
467
445
  end
468
446
 
469
447
  it "should set the filename" do
470
- ls = @ls.create(:filename => :xxx)
448
+ ls.create(:filename => :xxx)
471
449
  ls.filename.should == :xxx
472
450
  ls.sitemap.location.filename.should =~ /xxx/
473
451
  end
474
452
 
475
453
  it "should set verbose" do
476
- original = @ls.verbose
477
- @ls.create(:verbose => !original).verbose.should_not == original
454
+ original = ls.verbose
455
+ ls.create(:verbose => !original).verbose.should_not == original
478
456
  end
479
457
 
480
458
  it "should set the sitemaps_path" do
481
459
  path = 'new/path'
482
- ls = @ls.create(:sitemaps_path => path)
460
+ ls.create(:sitemaps_path => path)
483
461
  ls.sitemaps_path.should == path
484
462
  ls.sitemap.location.sitemaps_path.to_s.should == path
485
463
  end
486
464
 
487
465
  it "should set the default_host" do
488
466
  host = 'http://defaulthost.com'
489
- ls = @ls.create(:default_host => host)
467
+ ls.create(:default_host => host)
490
468
  ls.default_host.should == host
491
469
  ls.sitemap.location.host.should == host
492
470
  end
493
471
 
494
472
  it "should set the sitemaps host" do
495
- @host = 'http://sitemaphost.com'
496
- ls = @ls.create(:sitemaps_host => @host)
497
- ls.sitemaps_host.should == @host
498
- ls.sitemap.location.host.should == @host
473
+ host = 'http://sitemaphost.com'
474
+ ls.create(:sitemaps_host => host)
475
+ ls.sitemaps_host.should == host
476
+ ls.sitemap.location.host.should == host
499
477
  end
500
478
 
501
479
  it "should set the sitemaps_namer" do
502
480
  namer = SitemapGenerator::SitemapNamer.new(:xxx)
503
- ls = @ls.create(:sitemaps_namer => namer)
481
+ ls.create(:sitemaps_namer => namer)
504
482
  ls.sitemaps_namer.should == namer
505
483
  ls.sitemap.location.namer.should == namer
506
484
  ls.sitemap.location.filename.should =~ /xxx/
@@ -508,7 +486,7 @@ describe SitemapGenerator::LinkSet do
508
486
 
509
487
  it "should support both sitemaps_namer and filename options" do
510
488
  namer = SitemapGenerator::SitemapNamer.new("sitemap1_")
511
- ls = @ls.create(:sitemaps_namer => namer, :filename => "sitemap1")
489
+ ls.create(:sitemaps_namer => namer, :filename => "sitemap1")
512
490
  ls.sitemaps_namer.should == namer
513
491
  ls.sitemap.location.namer.should == namer
514
492
  ls.sitemap.location.filename.should =~ /sitemap1_1/
@@ -520,10 +498,16 @@ describe SitemapGenerator::LinkSet do
520
498
  options = {} #ActiveSupport::OrderedHash.new
521
499
  options[:sitemaps_namer] = namer
522
500
  options[:filename] = "sitemap1"
523
- ls = @ls.create(options)
501
+ ls.create(options)
524
502
  ls.sitemap.location.filename.should =~ /sitemap1_1/
525
503
  ls.sitemap_index.location.filename.should =~ /sitemap1_index/
526
504
  end
505
+
506
+ it "should not modify the options hash" do
507
+ options = { :filename => 'sitemaptest', :verbose => false }
508
+ ls.create(options)
509
+ options.should == { :filename => 'sitemaptest', :verbose => false }
510
+ end
527
511
  end
528
512
 
529
513
  describe "reset!" do
@@ -541,56 +525,50 @@ describe SitemapGenerator::LinkSet do
541
525
 
542
526
  describe "include_root?" do
543
527
  it "should return false" do
544
- @ls.include_root = false
545
- @ls.include_root.should be_false
528
+ ls.include_root = false
529
+ ls.include_root.should be_false
546
530
  end
547
531
 
548
532
  it "should return true" do
549
- @ls.include_root = true
550
- @ls.include_root.should be_true
533
+ ls.include_root = true
534
+ ls.include_root.should be_true
551
535
  end
552
536
  end
553
537
 
554
538
  describe "include_index?" do
555
539
  let(:sitemaps_host) { 'http://amazon.com' }
556
540
 
557
- before :each do
558
- @ls.default_host = @default_host
559
- end
560
-
561
541
  it "should be true if no sitemaps_host set, or it is the same" do
562
- @ls.include_index = true
563
- @ls.sitemaps_host = @default_host
564
- @ls.include_index?.should be_true
542
+ ls.include_index = true
543
+ ls.sitemaps_host = default_host
544
+ ls.include_index?.should be_true
565
545
 
566
- @ls.sitemaps_host = nil
567
- @ls.include_index?.should be_true
546
+ ls.sitemaps_host = nil
547
+ ls.include_index?.should be_true
568
548
  end
569
549
 
570
550
  it "should be false if include_index is false or sitemaps_host differs" do
571
- @ls.include_index = false
572
- @ls.sitemaps_host = @default_host
573
- @ls.include_index?.should be_false
551
+ ls.include_index = false
552
+ ls.sitemaps_host = default_host
553
+ ls.include_index?.should be_false
574
554
 
575
- @ls.include_index = true
576
- @ls.sitemaps_host = sitemaps_host
577
- @ls.include_index?.should be_false
555
+ ls.include_index = true
556
+ ls.sitemaps_host = sitemaps_host
557
+ ls.include_index?.should be_false
578
558
  end
579
559
 
580
560
  it "should return false" do
581
- ls = SitemapGenerator::LinkSet.new(:default_host => @default_host, :sitemaps_host => sitemaps_host)
561
+ ls = SitemapGenerator::LinkSet.new(:default_host => default_host, :sitemaps_host => sitemaps_host)
582
562
  ls.include_index?.should be_false
583
563
  end
584
564
 
585
565
  it "should return true" do
586
- ls = SitemapGenerator::LinkSet.new(:default_host => @default_host, :sitemaps_host => @default_host)
566
+ ls = SitemapGenerator::LinkSet.new(:default_host => default_host, :sitemaps_host => default_host)
587
567
  ls.include_index?.should be_true
588
568
  end
589
569
  end
590
570
 
591
571
  describe "output" do
592
- let(:ls) { SitemapGenerator::LinkSet.new }
593
-
594
572
  it "should not output" do
595
573
  ls.verbose = false
596
574
  ls.expects(:puts).never
@@ -603,4 +581,111 @@ describe SitemapGenerator::LinkSet do
603
581
  ls.send(:output, '')
604
582
  end
605
583
  end
584
+
585
+ describe "yield_sitemap" do
586
+ it "should default to the value of SitemapGenerator.yield_sitemap?" do
587
+ SitemapGenerator.expects(:yield_sitemap?).returns(true)
588
+ ls.yield_sitemap?.should be_true
589
+ SitemapGenerator.expects(:yield_sitemap?).returns(false)
590
+ ls.yield_sitemap?.should be_false
591
+ end
592
+
593
+ it "should be settable as an option" do
594
+ SitemapGenerator.expects(:yield_sitemap?).never
595
+ SitemapGenerator::LinkSet.new(:yield_sitemap => true).yield_sitemap?.should be_true
596
+ SitemapGenerator::LinkSet.new(:yield_sitemap => false).yield_sitemap?.should be_false
597
+ end
598
+
599
+ it "should be settable as an attribute" do
600
+ ls.yield_sitemap = true
601
+ ls.yield_sitemap?.should be_true
602
+ ls.yield_sitemap = false
603
+ ls.yield_sitemap?.should be_false
604
+ end
605
+
606
+ it "should yield the sitemap in the call to create" do
607
+ ls.send(:interpreter).expects(:eval).with(:yield_sitemap => true)
608
+ ls.yield_sitemap = true
609
+ ls.create
610
+ ls.send(:interpreter).expects(:eval).with(:yield_sitemap => false)
611
+ ls.yield_sitemap = false
612
+ ls.create
613
+ end
614
+ end
615
+
616
+ describe "add_links" do
617
+ it "should not change the value of yield_sitemap" do
618
+ ls.stubs(:create)
619
+ ls.yield_sitemap = false
620
+ ls.add_links
621
+ ls.yield_sitemap.should be_false
622
+ ls.yield_sitemap = true
623
+ ls.add_links
624
+ ls.yield_sitemap.should be_true
625
+ end
626
+
627
+ it "should always yield the sitemap instance" do
628
+ ls.send(:interpreter).expects(:eval).with(:yield_sitemap => true).twice
629
+ ls.yield_sitemap = false
630
+ ls.add_links
631
+ ls.yield_sitemap = true
632
+ ls.add_links
633
+ end
634
+ end
635
+
636
+ describe "add" do
637
+ it "should not modify the options hash" do
638
+ options = { :host => 'http://newhost.com' }
639
+ ls.add('/home', options)
640
+ options.should == { :host => 'http://newhost.com' }
641
+ end
642
+
643
+ it "should add the link to the sitemap and include the default host" do
644
+ ls.stubs(:add_default_links)
645
+ ls.sitemap.expects(:add).with('/home', :host => ls.default_host)
646
+ ls.add('/home')
647
+ end
648
+
649
+ it "should allow setting of a custom host" do
650
+ ls.stubs(:add_default_links)
651
+ ls.sitemap.expects(:add).with('/home', :host => 'http://newhost.com')
652
+ ls.add('/home', :host => 'http://newhost.com')
653
+ end
654
+
655
+ it "should add the default links if they have not been added" do
656
+ ls.expects(:add_default_links)
657
+ ls.add('/home')
658
+ end
659
+ end
660
+
661
+ describe "add_to_index", :focus do
662
+ it "should add the link to the sitemap index and pass options" do
663
+ ls.sitemap_index.expects(:add).with('/test', has_entry(:option => 'value'))
664
+ ls.add_to_index('/test', :option => 'value')
665
+ end
666
+
667
+ it "should not modify the options hash" do
668
+ options = { :host => 'http://newhost.com' }
669
+ ls.add_to_index('/home', options)
670
+ options.should == { :host => 'http://newhost.com' }
671
+ end
672
+
673
+ describe "host" do
674
+ it "should be the sitemaps_host" do
675
+ ls.sitemaps_host = 'http://sitemapshost.com'
676
+ ls.sitemap_index.expects(:add).with('/home', :host => 'http://sitemapshost.com')
677
+ ls.add_to_index('/home')
678
+ end
679
+
680
+ it "should be the default_host if no sitemaps_host set" do
681
+ ls.sitemap_index.expects(:add).with('/home', :host => ls.default_host)
682
+ ls.add_to_index('/home')
683
+ end
684
+
685
+ it "should allow setting a custom host" do
686
+ ls.sitemap_index.expects(:add).with('/home', :host => 'http://newhost.com')
687
+ ls.add_to_index('/home', :host => 'http://newhost.com')
688
+ end
689
+ end
690
+ end
606
691
  end