addressabler 0.0.7 → 0.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.
@@ -0,0 +1,39 @@
1
+ require 'addressabler/uri_deprecation'
2
+
3
+ describe Addressabler, "deprecation" do
4
+ describe "TLDS" do
5
+ it "returns public TLDS" do
6
+ Addressabler::TLDS.should == Addressabler.public_tlds
7
+ end
8
+
9
+ it "warns about the deprecated TLD constant" do
10
+ Addressabler.should_receive(:deprecation_warning)
11
+ Addressabler::TLDS
12
+ end
13
+ end
14
+ end
15
+
16
+ describe Addressable::URI, "deprecation" do
17
+ describe "custom_tlds" do
18
+ it "returns the Addressabler custom_tlds" do
19
+ Addressabler.custom_tlds = {foo: "bar"}
20
+ Addressable::URI.custom_tlds.should == {foo: "bar"}
21
+ end
22
+
23
+ it "sets the Addressabler custom_tlds" do
24
+ Addressable::URI.custom_tlds = {gert: "B. Frobe"}
25
+ Addressabler.custom_tlds.should == {gert: "B. Frobe"}
26
+ end
27
+
28
+ it "warns about the deprecated custom_tlds getter" do
29
+ Addressabler.should_receive(:deprecation_warning)
30
+ Addressable::URI.custom_tlds
31
+ end
32
+
33
+ it "warns about the deprecated custom_tlds setter" do
34
+ Addressabler.should_receive(:deprecation_warning)
35
+ Addressable::URI.custom_tlds = {bring_me: "a sandwich"}
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,116 @@
1
+ require 'addressabler/uri'
2
+
3
+ describe Addressabler::URI do
4
+ it "does not prevent Addressable::URI from parsing" do
5
+ uri = Addressable::URI.parse("http://www.google.com/path?foo=bar#anchor")
6
+ uri.should be_instance_of(Addressable::URI)
7
+ end
8
+
9
+ it "resets when the host changes" do
10
+ uri = Addressable::URI.heuristic_parse("www.google.com")
11
+ uri.tld.should == 'com'
12
+ uri.domain.should == 'google'
13
+ uri.subdomain.should == 'www'
14
+ uri.host = 'www2.google.co.uk'
15
+ uri.tld.should == 'co.uk'
16
+ uri.domain.should == 'google'
17
+ uri.subdomain.should == 'www2'
18
+ end
19
+
20
+ it "does not explode on empty strings" do
21
+ uri = Addressable::URI.parse("")
22
+ uri.host.should be_nil
23
+ uri.domain.should be_nil
24
+ uri.tld.should be_nil
25
+ uri.subdomain.should be_nil
26
+ end
27
+
28
+ describe "#tld" do
29
+ it "returns a TLD" do
30
+ uri = Addressable::URI.parse("http://www.google.com/path?foo=bar#anchor")
31
+ uri.tld.should == 'com'
32
+ end
33
+
34
+ it "knows about complex TLDs" do
35
+ uri = Addressable::URI.parse("http://www.foo.bar.baz.co.uk/gjadgsg#sdgs?adg=f")
36
+ uri.tld.should == 'co.uk'
37
+ end
38
+
39
+ it "knows about newer TLDs" do
40
+ uri = Addressable::URI.parse("http://www.bart-blabla.cc")
41
+ uri.tld.should == 'cc'
42
+ end
43
+
44
+ it "doesn't know non-existant TLDs" do
45
+ uri = Addressable::URI.parse("http://www.bart-blabla.foobar")
46
+ uri.tld.should == ''
47
+ end
48
+
49
+ it "accepts custom TLDs" do
50
+ Addressabler.custom_tlds = { 'foobar' => {} }
51
+ uri = Addressable::URI.parse("http://www.bart-blabla.foobar")
52
+ uri.tld.should == 'foobar'
53
+ end
54
+
55
+ it "accepts nested custom TLDs" do
56
+ Addressabler.custom_tlds = { 'bar' => { 'foo' => {} } }
57
+ uri = Addressable::URI.parse("http://www.bart-blabla.foo.bar")
58
+ uri.tld.should == 'foo.bar'
59
+ end
60
+
61
+ it "is changeable" do
62
+ uri = Addressable::URI.heuristic_parse("www.google.com")
63
+ uri.tld = 'co.uk'
64
+ uri.to_s.should == 'http://www.google.co.uk'
65
+ end
66
+ end
67
+
68
+ describe "#domain" do
69
+ it "returns the domain" do
70
+ uri = Addressable::URI.heuristic_parse("i.am.a.subdomain.co.uk")
71
+ uri.domain.should == "subdomain"
72
+ end
73
+
74
+ it "is changeable" do
75
+ uri = Addressable::URI.heuristic_parse("www.google.com")
76
+ uri.domain = 'amazon'
77
+ uri.to_s.should == 'http://www.amazon.com'
78
+ end
79
+ end
80
+
81
+ describe "#subdomain" do
82
+ it "returns the subdomain" do
83
+ uri = Addressable::URI.heuristic_parse("i.am.a.subdomain.co.uk")
84
+ uri.subdomain.should == "i.am.a"
85
+ end
86
+
87
+ it "is changeable" do
88
+ uri = Addressable::URI.heuristic_parse("www.google.com")
89
+ uri.subdomain = 'www2'
90
+ uri.to_s.should == 'http://www2.google.com'
91
+ end
92
+
93
+ it "is blank when none exists" do
94
+ uri = Addressable::URI.parse("http://google.com")
95
+ uri.host.should == "google.com"
96
+ uri.domain.should == "google"
97
+ uri.tld.should == "com"
98
+ uri.subdomain.should == ""
99
+ end
100
+ end
101
+
102
+ describe "#query_hash" do
103
+ it "supports adding keys to the query" do
104
+ uri = Addressable::URI.parse("http://www.foo.bar.baz.co.uk/gjadgsg?adg=f")
105
+ uri.query_hash.should == {'adg' => 'f'}
106
+ uri.query_hash[:foo] = "bar"
107
+ uri.to_s.should == "http://www.foo.bar.baz.co.uk/gjadgsg?adg=f&foo=bar"
108
+ end
109
+
110
+ it "supports adding nested values to the query" do
111
+ uri = Addressable::URI.parse("http://www.amazon.ca")
112
+ uri.query_hash[:foo] = {:bar => "baz", :sommat => [:else, 1, true, false]}
113
+ uri.to_s.should == "http://www.amazon.ca?foo[bar]=baz&foo[sommat][]=else&foo[sommat][]=1&foo[sommat][]=true&foo[sommat][]=false"
114
+ end
115
+ end
116
+ end
@@ -1,115 +1,18 @@
1
- require 'addressabler'
1
+ require "addressabler"
2
2
 
3
3
  describe Addressabler do
4
- it "should still let me parse a URI" do
5
- uri = Addressable::URI.parse("http://www.google.com/path?foo=bar#anchor")
6
- uri.should be_instance_of(Addressable::URI)
7
- end
8
-
9
- it "should get the scheme of a URI" do
10
- uri = Addressable::URI.parse("http://www.google.com/path?foo=bar#anchor")
11
- uri.scheme.should == "http"
12
- end
13
-
14
- describe "TLD parsing" do
15
- it "returns a TLD" do
16
- uri = Addressable::URI.parse("http://www.google.com/path?foo=bar#anchor")
17
- uri.tld.should == 'com'
18
- end
19
-
20
- it "knows about complex TLDs" do
21
- uri = Addressable::URI.parse("http://www.foo.bar.baz.co.uk/gjadgsg#sdgs?adg=f")
22
- uri.tld.should == 'co.uk'
23
- end
24
-
25
- it "knows about newer TLDs" do
26
- uri = Addressable::URI.parse("http://www.bart-blabla.cc")
27
- uri.tld.should == 'cc'
4
+ describe ".parse_tlds" do
5
+ it "doesn't return private TLDs by default" do
6
+ host = 'fwefweewf.blogspot.com'
7
+ tld = Addressabler.parse_tld(host)
8
+ tld.should == 'com'
28
9
  end
29
10
 
30
- it "doesn't know non-existing TLDs" do
31
- uri = Addressable::URI.parse("http://www.bart-blabla.foobar")
32
- uri.tld.should == ''
11
+ it "can switch private tlds on" do
12
+ Addressabler.use_private_tlds = true
13
+ host = 'fwefweewf.blogspot.com'
14
+ tld = Addressabler.parse_tld(host)
15
+ tld.should == 'blogspot.com'
33
16
  end
34
-
35
- it "accepts custom TLDs" do
36
- Addressable::URI.custom_tlds = { 'foobar' => {} }
37
- uri = Addressable::URI.parse("http://www.bart-blabla.foobar")
38
- uri.tld.should == 'foobar'
39
- end
40
-
41
- it "accepts nested custom TLDs" do
42
- Addressable::URI.custom_tlds = { 'bar' => { 'foo' => {} } }
43
- uri = Addressable::URI.parse("http://www.bart-blabla.foo.bar")
44
- uri.tld.should == 'foo.bar'
45
- end
46
- end
47
-
48
- it "should support adding keys to the query" do
49
- uri = Addressable::URI.parse("http://www.foo.bar.baz.co.uk/gjadgsg?adg=f")
50
- uri.query_hash.should == {'adg' => 'f'}
51
- uri.query_hash[:foo] = "bar"
52
- uri.to_s.should == "http://www.foo.bar.baz.co.uk/gjadgsg?adg=f&foo=bar"
53
- end
54
-
55
- it "should support adding nested values to the query" do
56
- uri = Addressable::URI.parse("http://www.amazon.ca")
57
- uri.query_hash[:foo] = {:bar => "baz", :sommat => [:else, 1, true, false]}
58
- uri.to_s.should == "http://www.amazon.ca?foo[bar]=baz&foo[sommat][]=else&foo[sommat][]=1&foo[sommat][]=true&foo[sommat][]=false"
59
- end
60
-
61
- it "should support subdomains" do
62
- uri = Addressable::URI.heuristic_parse("i.am.a.subdomain.co.uk")
63
- uri.subdomain.should == "i.am.a"
64
- end
65
-
66
- it "should support domains" do
67
- uri = Addressable::URI.heuristic_parse("i.am.a.subdomain.co.uk")
68
- uri.domain.should == "subdomain"
69
- end
70
-
71
- it "should change stuff when the host changes" do
72
- uri = Addressable::URI.heuristic_parse("www.google.com")
73
- uri.tld.should == 'com'
74
- uri.domain.should == 'google'
75
- uri.subdomain.should == 'www'
76
- uri.host = 'www2.google.co.uk'
77
- uri.tld.should == 'co.uk'
78
- uri.domain.should == 'google'
79
- uri.subdomain.should == 'www2'
80
- end
81
-
82
- it "should let me change the subdomain" do
83
- uri = Addressable::URI.heuristic_parse("www.google.com")
84
- uri.subdomain = 'www2'
85
- uri.to_s.should == 'http://www2.google.com'
86
- end
87
-
88
- it "should let me change the domain" do
89
- uri = Addressable::URI.heuristic_parse("www.google.com")
90
- uri.domain = 'amazon'
91
- uri.to_s.should == 'http://www.amazon.com'
92
- end
93
-
94
- it "should let me change the tld" do
95
- uri = Addressable::URI.heuristic_parse("www.google.com")
96
- uri.tld = 'co.uk'
97
- uri.to_s.should == 'http://www.google.co.uk'
98
- end
99
-
100
- it "should handle things with no subdomain" do
101
- uri = Addressable::URI.parse("http://google.com")
102
- uri.host.should == "google.com"
103
- uri.domain.should == "google"
104
- uri.tld.should == "com"
105
- uri.subdomain.should == ""
106
- end
107
-
108
- it "should handle empty strings" do
109
- uri = Addressable::URI.parse("")
110
- uri.host.should be_nil
111
- uri.domain.should be_nil
112
- uri.tld.should be_nil
113
- uri.subdomain.should be_nil
114
17
  end
115
18
  end
metadata CHANGED
@@ -1,65 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressabler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Flip Sasser
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-02 00:00:00.000000000 Z
11
+ date: 2014-01-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: addressable
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: '2.3'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: '2.3'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
- version: '2.0'
33
+ version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
- version: '2.0'
40
+ version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
- name: addressable
42
+ name: jeweler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
- version: 2.2.2
54
- type: :runtime
47
+ version: '0'
48
+ type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
- version: 2.2.2
62
- description: ! "\n Addressabler extends the Addressable::URI class to provide information
54
+ version: '0'
55
+ description: "\n Addressabler extends the Addressable::URI class to provide information
63
56
  about, and manipulation of, specific parts of URI strings. It adds a `tld' method,
64
57
  a `domain' method,\n and a `subdomain' method.\n\nIt also allows users to easily
65
58
  modify the URL's query values as a hash.\n "
@@ -74,39 +67,47 @@ files:
74
67
  - LICENSE
75
68
  - lib/addressabler.rb
76
69
  - lib/addressabler/query.rb
70
+ - lib/addressabler/uri.rb
71
+ - lib/addressabler/uri_deprecation.rb
77
72
  - lib/tlds
78
73
  - README.md
74
+ - spec/addressable/idna_spec.rb
75
+ - spec/addressable/net_http_compat_spec.rb
76
+ - spec/addressable/template_spec.rb
77
+ - spec/addressable/uri_spec.rb
78
+ - spec/addressabler/uri_deprecation_spec.rb
79
+ - spec/addressabler/uri_spec.rb
79
80
  - spec/addressabler_spec.rb
80
81
  - spec/spec_helper.rb
81
- - spec/uri_spec.rb
82
82
  homepage: http://github.com/flipsasser/addressabler
83
83
  licenses: []
84
+ metadata: {}
84
85
  post_install_message:
85
86
  rdoc_options: []
86
87
  require_paths:
87
88
  - lib
88
89
  required_ruby_version: !ruby/object:Gem::Requirement
89
- none: false
90
90
  requirements:
91
- - - ! '>='
91
+ - - '='
92
92
  - !ruby/object:Gem::Version
93
- version: '0'
94
- segments:
95
- - 0
96
- hash: -879587546668061627
93
+ version: 1.9.3
97
94
  required_rubygems_version: !ruby/object:Gem::Requirement
98
- none: false
99
95
  requirements:
100
- - - ! '>='
96
+ - - '>='
101
97
  - !ruby/object:Gem::Version
102
98
  version: '0'
103
99
  requirements: []
104
100
  rubyforge_project:
105
- rubygems_version: 1.8.25
101
+ rubygems_version: 2.1.10
106
102
  signing_key:
107
- specification_version: 3
103
+ specification_version: 4
108
104
  summary: An Addressable::URI extension adding support for TLDs and query part editing
109
105
  test_files:
106
+ - spec/addressable/idna_spec.rb
107
+ - spec/addressable/net_http_compat_spec.rb
108
+ - spec/addressable/template_spec.rb
109
+ - spec/addressable/uri_spec.rb
110
+ - spec/addressabler/uri_deprecation_spec.rb
111
+ - spec/addressabler/uri_spec.rb
110
112
  - spec/addressabler_spec.rb
111
113
  - spec/spec_helper.rb
112
- - spec/uri_spec.rb