absolutize 0.0.5 → 0.0.6

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.
@@ -1,5 +1,5 @@
1
1
 
2
- h1. Absolutize v0.0.5
2
+ h1. Absolutize v0.0.6
3
3
 
4
4
  h2. Intro
5
5
 
@@ -8,9 +8,9 @@ class Absolutize
8
8
  @base_url = base_url
9
9
  @options = options
10
10
 
11
- @options[:remove_anchors] = false
12
- @options[:force_escaping] = true
13
- @options[:output_debug] = false
11
+ @options[:remove_anchors] = false if @options[:remove_anchors].nil?
12
+ @options[:force_escaping] = true if @options[:force_escaping].nil?
13
+ @options[:output_debug] = false if @options[:output_debug].nil?
14
14
  end
15
15
 
16
16
  def url(relative_url)
@@ -8,9 +8,9 @@ class Absolutize
8
8
  @base_url = base_url
9
9
  @options = options
10
10
 
11
- @options[:remove_anchors] = false
12
- @options[:force_escaping] = true
13
- @options[:output_debug] = false
11
+ @options[:remove_anchors] = false if @options[:remove_anchors].nil?
12
+ @options[:force_escaping] = true if @options[:force_escaping].nil?
13
+ @options[:output_debug] = false if @options[:output_debug].nil?
14
14
  end
15
15
 
16
16
  def url(relative_url)
@@ -3,36 +3,59 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe Absolutize do
4
4
 
5
5
  before(:each) do
6
- @base_url = "http://www.baseurl.com/"
7
- @absolutize = Absolutize.new(@base_url)
6
+ @base_url = "http://www.baseurl.com/"
8
7
  end
9
8
 
10
- it "should create an Absolutize object" do
11
- @absolutize.should be_an_instance_of Absolutize
12
- end
9
+ describe "with default parameters" do
10
+ before(:each) do
11
+ @absolutize = Absolutize.new(@base_url)
12
+ end
13
13
 
14
- it "should return the same url for an absolute url" do
15
- @absolutize.url("http://www.bbc.co.uk/").to_s.should == "http://www.bbc.co.uk/"
16
- end
17
- it "should return the same url for an absolute url" do
18
- @absolutize.url("http://www.bbc.co.uk//asdf/asdf.html").to_s.should == "http://www.bbc.co.uk/asdf/asdf.html"
19
- end
20
- it "should return the absolute url for a relative to root url" do
21
- @absolutize.url("/asdf.html").to_s.should == "http://www.baseurl.com/asdf.html"
22
- end
23
- it "should return the absolute url for a relative to folder url" do
24
- @absolutize.url("asdf.html").to_s.should == "http://www.baseurl.com/asdf.html"
25
- end
26
- it "should handle urls with spaces" do
27
- @absolutize.url("/root folder/asdf.html").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html"
14
+ it "should create an Absolutize object" do
15
+ @absolutize.should be_an_instance_of Absolutize
16
+ end
17
+
18
+ it "should return the same url for an absolute url" do
19
+ @absolutize.url("http://www.bbc.co.uk/").to_s.should == "http://www.bbc.co.uk/"
20
+ end
21
+ it "should return the same url for an absolute url" do
22
+ @absolutize.url("http://www.bbc.co.uk//asdf/asdf.html").to_s.should == "http://www.bbc.co.uk/asdf/asdf.html"
23
+ end
24
+ it "should return the absolute url for a relative to root url" do
25
+ @absolutize.url("/asdf.html").to_s.should == "http://www.baseurl.com/asdf.html"
26
+ end
27
+ it "should return the absolute url for a relative to folder url" do
28
+ @absolutize.url("asdf.html").to_s.should == "http://www.baseurl.com/asdf.html"
29
+ end
30
+ it "should handle urls with spaces" do
31
+ @absolutize.url("/root folder/asdf.html").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html"
32
+ end
33
+ it "should handle urls with ['s" do
34
+ @absolutize.url("/folder/asdf.html?id=[asdf]").to_s.should == "http://www.baseurl.com/folder/asdf.html?id=%5Basdf%5D"
35
+ end
36
+ it "should not encode urls with %'s" do
37
+ @absolutize.url("/root%20folder/asdf.html?id=asdf").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html?id=asdf"
38
+ end
39
+ it "should not encode existing encoded characters" do
40
+ @absolutize.url("/root%20folder/asdf.html?id=[asdf]").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html?id=%5Basdf%5D"
41
+ end
28
42
  end
29
- it "should handle urls with ['s" do
30
- @absolutize.url("/folder/asdf.html?id=[asdf]").to_s.should == "http://www.baseurl.com/folder/asdf.html?id=%5Basdf%5D"
31
- end
32
- it "should not encode urls with %'s" do
33
- @absolutize.url("/root%20folder/asdf.html?id=asdf").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html?id=asdf"
43
+
44
+ describe "with remove_anchors true" do
45
+ before(:each) do
46
+ @absolutize = Absolutize.new(@base_url, :remove_anchors => true)
47
+ end
48
+ it "should remove an anchor" do
49
+ @absolutize.url("/root folder/asdf.html#anchor").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html"
50
+ end
34
51
  end
35
- it "should not encode existing encoded characters" do
36
- @absolutize.url("/root%20folder/asdf.html?id=[asdf]").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html?id=%5Basdf%5D"
52
+
53
+ describe "with force_escaping false" do
54
+ before(:each) do
55
+ @absolutize = Absolutize.new(@base_url, :force_escaping => false)
56
+ end
57
+ it "should not escape invalid characters" do
58
+ lambda { @absolutize.url("/root folder/asdf.html#anchor")}.should raise_error
59
+ end
37
60
  end
38
61
  end
@@ -3,34 +3,59 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe Absolutize do
4
4
 
5
5
  before(:each) do
6
- @base_url = "http://www.baseurl.com/"
7
- @absolutize = Absolutize.new(@base_url)
6
+ @base_url = "http://www.baseurl.com/"
8
7
  end
9
8
 
10
- it "should create an Absolutize object" do
11
- @absolutize.should be_an_instance_of Absolutize
12
- end
9
+ describe "with default parameters" do
10
+ before(:each) do
11
+ @absolutize = Absolutize.new(@base_url)
12
+ end
13
13
 
14
- it "should return the same url for an absolute url" do
15
- @absolutize.url("http://www.bbc.co.uk/").to_s.should == "http://www.bbc.co.uk/"
16
- end
17
- it "should return the same url for an absolute url" do
18
- @absolutize.url("http://www.bbc.co.uk//asdf/asdf.html").to_s.should == "http://www.bbc.co.uk/asdf/asdf.html"
19
- end
20
- it "should return the absolute url for a relative to root url" do
21
- @absolutize.url("/asdf.html").to_s.should == "http://www.baseurl.com/asdf.html"
22
- end
23
- it "should return the absolute url for a relative to folder url" do
24
- @absolutize.url("asdf.html").to_s.should == "http://www.baseurl.com/asdf.html"
25
- end
26
- it "should handle urls with spaces" do
27
- @absolutize.url("/root folder/asdf.html").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html"
14
+ it "should create an Absolutize object" do
15
+ @absolutize.should be_an_instance_of Absolutize
16
+ end
17
+
18
+ it "should return the same url for an absolute url" do
19
+ @absolutize.url("http://www.bbc.co.uk/").to_s.should == "http://www.bbc.co.uk/"
20
+ end
21
+ it "should return the same url for an absolute url" do
22
+ @absolutize.url("http://www.bbc.co.uk//asdf/asdf.html").to_s.should == "http://www.bbc.co.uk/asdf/asdf.html"
23
+ end
24
+ it "should return the absolute url for a relative to root url" do
25
+ @absolutize.url("/asdf.html").to_s.should == "http://www.baseurl.com/asdf.html"
26
+ end
27
+ it "should return the absolute url for a relative to folder url" do
28
+ @absolutize.url("asdf.html").to_s.should == "http://www.baseurl.com/asdf.html"
29
+ end
30
+ it "should handle urls with spaces" do
31
+ @absolutize.url("/root folder/asdf.html").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html"
32
+ end
33
+ it "should handle urls with ['s" do
34
+ @absolutize.url("/folder/asdf.html?id=[asdf]").to_s.should == "http://www.baseurl.com/folder/asdf.html?id=%5Basdf%5D"
35
+ end
36
+ it "should not encode urls with %'s" do
37
+ @absolutize.url("/root%20folder/asdf.html?id=asdf").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html?id=asdf"
38
+ end
39
+ it "should not encode existing encoded characters" do
40
+ @absolutize.url("/root%20folder/asdf.html?id=[asdf]").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html?id=%5Basdf%5D"
41
+ end
28
42
  end
29
- it "should handle urls with ['s" do
30
- @absolutize.url("/folder/asdf.html?id=[asdf]").to_s.should == "http://www.baseurl.com/folder/asdf.html?id=%5Basdf%5D"
43
+
44
+ describe "with remove_anchors true" do
45
+ before(:each) do
46
+ @absolutize = Absolutize.new(@base_url, :remove_anchors => true)
47
+ end
48
+ it "should remove an anchor" do
49
+ @absolutize.url("/root folder/asdf.html#anchor").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html"
50
+ end
31
51
  end
32
- it "should not encode urls with %'s" do
33
- @absolutize.url("/root%20folder/asdf.html?id=asdf").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html?id=asdf"
52
+
53
+ describe "with force_escaping false" do
54
+ before(:each) do
55
+ @absolutize = Absolutize.new(@base_url, :force_escaping => false)
56
+ end
57
+ it "should not escape invalid characters" do
58
+ lambda { @absolutize.url("/root folder/asdf.html#anchor")}.should raise_error
59
+ end
34
60
  end
35
-
36
61
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: absolutize
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stewart McKee