wovnrb 0.1.64 → 0.1.65
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wovnrb.rb +50 -2
- data/lib/wovnrb/services/url.rb +54 -8
- data/lib/wovnrb/version.rb +1 -1
- data/test/lib/headers_test.rb +5744 -0
- data/test/lib/wovnrb_test.rb +135 -0
- data/test/services/url_test.rb +163 -0
- data/wovnrb.gemspec +1 -0
- metadata +18 -2
data/test/lib/wovnrb_test.rb
CHANGED
@@ -2,6 +2,7 @@ require 'wovnrb'
|
|
2
2
|
require 'wovnrb/headers'
|
3
3
|
require 'minitest/autorun'
|
4
4
|
require 'pry'
|
5
|
+
require 'mocha/mini_test'
|
5
6
|
|
6
7
|
class WovnrbTest < Minitest::Test
|
7
8
|
|
@@ -22,4 +23,138 @@ class WovnrbTest < Minitest::Test
|
|
22
23
|
def get_app()
|
23
24
|
end
|
24
25
|
|
26
|
+
def test_add_lang_code_nil_href
|
27
|
+
i = Wovnrb::Interceptor.new(get_app)
|
28
|
+
assert_equal(nil, i.add_lang_code(nil,'path', 'en', nil))
|
29
|
+
end
|
30
|
+
def test_add_lang_code_absolute_different_host
|
31
|
+
i = Wovnrb::Interceptor.new(get_app)
|
32
|
+
headers = stub
|
33
|
+
headers.expects(:host).returns('google.com')
|
34
|
+
assert_equal('http://yahoo.co.jp', i.add_lang_code('http://yahoo.co.jp', 'path', 'fr', headers))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_add_lang_code_absolute_subdomain_no_subdomain
|
38
|
+
i = Wovnrb::Interceptor.new(get_app)
|
39
|
+
headers = stub
|
40
|
+
headers.expects(:host).returns('google.com')
|
41
|
+
assert_equal('http://fr.google.com', i.add_lang_code('http://google.com', 'subdomain', 'fr', headers))
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_add_lang_code_absolute_subdomain_with_subdomain
|
45
|
+
i = Wovnrb::Interceptor.new(get_app)
|
46
|
+
headers = stub
|
47
|
+
headers.expects(:host).returns('home.google.com')
|
48
|
+
assert_equal('http://fr.home.google.com', i.add_lang_code('http://home.google.com', 'subdomain', 'fr', headers))
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_add_lang_code_absolute_query_no_query
|
52
|
+
i = Wovnrb::Interceptor.new(get_app)
|
53
|
+
headers = stub
|
54
|
+
headers.expects(:host).returns('google.com')
|
55
|
+
assert_equal('http://google.com?wovn=fr', i.add_lang_code('http://google.com', 'query', 'fr', headers))
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_add_lang_code_absolute_query_with_query
|
59
|
+
i = Wovnrb::Interceptor.new(get_app)
|
60
|
+
headers = stub
|
61
|
+
headers.expects(:host).returns('google.com')
|
62
|
+
assert_equal('http://google.com?hey=yo&wovn=fr', i.add_lang_code('http://google.com?hey=yo', 'query', 'fr', headers))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_add_lang_code_absolute_path_no_pathname
|
66
|
+
i = Wovnrb::Interceptor.new(get_app)
|
67
|
+
headers = stub
|
68
|
+
headers.expects(:host).returns('google.com')
|
69
|
+
assert_equal('http://google.com/fr/', i.add_lang_code('http://google.com', 'path', 'fr', headers))
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_add_lang_code_absolute_path_with_pathname
|
73
|
+
i = Wovnrb::Interceptor.new(get_app)
|
74
|
+
headers = stub
|
75
|
+
headers.expects(:host).returns('google.com')
|
76
|
+
assert_equal('http://google.com/fr/index.html', i.add_lang_code('http://google.com/index.html', 'path', 'fr', headers))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_add_lang_code_absolute_path_with_long_pathname
|
80
|
+
i = Wovnrb::Interceptor.new(get_app)
|
81
|
+
headers = stub
|
82
|
+
headers.expects(:host).returns('google.com')
|
83
|
+
assert_equal('http://google.com/fr/hello/long/path/index.html', i.add_lang_code('http://google.com/hello/long/path/index.html', 'path', 'fr', headers))
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_add_lang_code_relative_subdomain_leading_slash
|
87
|
+
i = Wovnrb::Interceptor.new(get_app)
|
88
|
+
headers = stub
|
89
|
+
headers.expects(:protocol).returns('http')
|
90
|
+
headers.expects(:host).returns('google.com')
|
91
|
+
assert_equal('http://fr.google.com/', i.add_lang_code('/', 'subdomain', 'fr', headers))
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_add_lang_code_relative_subdomain_leading_slash_filename
|
95
|
+
i = Wovnrb::Interceptor.new(get_app)
|
96
|
+
headers = stub
|
97
|
+
headers.expects(:protocol).returns('http')
|
98
|
+
headers.expects(:host).returns('google.com')
|
99
|
+
assert_equal('http://fr.google.com/index.html', i.add_lang_code('/index.html', 'subdomain', 'fr', headers))
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_add_lang_code_relative_subdomain_no_leading_slash_filename
|
103
|
+
i = Wovnrb::Interceptor.new(get_app)
|
104
|
+
headers = stub
|
105
|
+
headers.expects(:protocol).returns('http')
|
106
|
+
headers.expects(:host).returns('google.com')
|
107
|
+
headers.expects(:pathname).returns('/')
|
108
|
+
assert_equal('http://fr.google.com/index.html', i.add_lang_code('index.html', 'subdomain', 'fr', headers))
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_add_lang_code_relative_subdomain_dot_filename
|
112
|
+
i = Wovnrb::Interceptor.new(get_app)
|
113
|
+
headers = stub
|
114
|
+
headers.expects(:protocol).returns('http')
|
115
|
+
headers.expects(:host).returns('google.com')
|
116
|
+
headers.expects(:pathname).returns('/')
|
117
|
+
assert_equal('http://fr.google.com/./index.html', i.add_lang_code('./index.html', 'subdomain', 'fr', headers))
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_add_lang_code_relative_subdomain_two_dots_filename_long_pathname
|
121
|
+
i = Wovnrb::Interceptor.new(get_app)
|
122
|
+
headers = stub
|
123
|
+
headers.expects(:protocol).returns('http')
|
124
|
+
headers.expects(:host).returns('google.com')
|
125
|
+
headers.expects(:pathname).returns('/home/hey/index.html')
|
126
|
+
assert_equal('http://fr.google.com/home/hey/../index.html', i.add_lang_code('../index.html', 'subdomain', 'fr', headers))
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_add_lang_code_relative_query_with_no_query
|
130
|
+
i = Wovnrb::Interceptor.new(get_app)
|
131
|
+
headers = stub
|
132
|
+
assert_equal('/index.html?wovn=fr', i.add_lang_code('/index.html', 'query', 'fr', headers))
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_add_lang_code_relative_query_with_query
|
136
|
+
i = Wovnrb::Interceptor.new(get_app)
|
137
|
+
headers = stub
|
138
|
+
assert_equal('/index.html?hey=yo&wovn=fr', i.add_lang_code('/index.html?hey=yo', 'query', 'fr', headers))
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_add_lang_code_relative_path_with_leading_slash
|
142
|
+
i = Wovnrb::Interceptor.new(get_app)
|
143
|
+
headers = stub
|
144
|
+
assert_equal('/fr/index.html', i.add_lang_code('/index.html', 'path', 'fr', headers))
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_add_lang_code_relative_path_without_leading_slash_different_pathname
|
148
|
+
i = Wovnrb::Interceptor.new(get_app)
|
149
|
+
headers = stub
|
150
|
+
headers.expects(:pathname).returns('/hello/tab.html')
|
151
|
+
assert_equal('/fr/hello/index.html', i.add_lang_code('index.html', 'path', 'fr', headers))
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_add_lang_code_relative_path_without_leading_slash_different_pathname2
|
155
|
+
i = Wovnrb::Interceptor.new(get_app)
|
156
|
+
headers = stub
|
157
|
+
headers.expects(:pathname).returns('/hello/tab.html')
|
158
|
+
assert_equal('/fr/hello/hey/index.html', i.add_lang_code('hey/index.html', 'path', 'fr', headers))
|
159
|
+
end
|
25
160
|
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'wovnrb/services/URL'
|
2
|
+
|
3
|
+
class URLTest < Minitest::Test
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
def test_prepend_path
|
8
|
+
assert_equal('http://www.google.com/new_dir/test/', Wovnrb::URL.prepend_path('http://www.google.com/test/', 'new_dir'))
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_prepend_path_long_path
|
12
|
+
assert_equal('http://www.google.com/new_dir/test/try/again/', Wovnrb::URL.prepend_path('http://www.google.com/test/try/again/', 'new_dir'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_prepend_path_no_trailing_slash
|
16
|
+
assert_equal('http://www.google.com/new_dir/test', Wovnrb::URL.prepend_path('http://www.google.com/test', 'new_dir'))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_prepend_path_long_path_no_trailing_slash
|
20
|
+
assert_equal('http://www.google.com/new_dir/test/try/again', Wovnrb::URL.prepend_path('http://www.google.com/test/try/again', 'new_dir'))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_prepend_path_no_path
|
24
|
+
assert_equal('http://www.google.com/new_dir/', Wovnrb::URL.prepend_path('http://www.google.com/', 'new_dir'))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_prepend_path_no_path_no_trailing_slash
|
28
|
+
assert_equal('http://www.google.com/new_dir', Wovnrb::URL.prepend_path('http://www.google.com', 'new_dir'))
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
def test_prepend_path_no_host
|
34
|
+
assert_equal('http://google.com/new_dir/test/', Wovnrb::URL.prepend_path('http://google.com/test/', 'new_dir'))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_prepend_path_no_host_long_path
|
38
|
+
assert_equal('http://google.com/new_dir/test/try/again/', Wovnrb::URL.prepend_path('http://google.com/test/try/again/', 'new_dir'))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_prepend_path_no_host_no_trailing_slash
|
42
|
+
assert_equal('http://google.com/new_dir/test', Wovnrb::URL.prepend_path('http://google.com/test', 'new_dir'))
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_prepend_path_no_host_long_path_no_trailing_slash
|
46
|
+
assert_equal('http://google.com/new_dir/test/try/again', Wovnrb::URL.prepend_path('http://google.com/test/try/again', 'new_dir'))
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_prepend_path_no_host_no_path
|
50
|
+
assert_equal('http://google.com/new_dir/', Wovnrb::URL.prepend_path('http://google.com/', 'new_dir'))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_prepend_path_no_host_no_path_no_trailing_slash
|
54
|
+
assert_equal('http://google.com/new_dir', Wovnrb::URL.prepend_path('http://google.com', 'new_dir'))
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
def test_prepend_path_no_protocol
|
60
|
+
assert_equal('www.facebook.com/dir/test/', Wovnrb::URL.prepend_path('www.facebook.com/test/', 'dir'))
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_prepend_path_no_protocol_long_path
|
64
|
+
assert_equal('www.facebook.com/dir/test/try/again/', Wovnrb::URL.prepend_path('www.facebook.com/test/try/again/', 'dir'))
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_prepend_path_no_protocol_no_trailing_slash
|
68
|
+
assert_equal('www.facebook.com/dir/test', Wovnrb::URL.prepend_path('www.facebook.com/test', 'dir'))
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_prepend_path_no_protocol_long_path_no_trailing_slash
|
72
|
+
assert_equal('www.facebook.com/dir/test/try/again', Wovnrb::URL.prepend_path('www.facebook.com/test/try/again', 'dir'))
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_prepend_path_no_protocol_no_path
|
76
|
+
assert_equal('www.facebook.com/dir/', Wovnrb::URL.prepend_path('www.facebook.com/', 'dir'))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_prepend_path_no_protocol_no_path_no_trailing_slash
|
80
|
+
assert_equal('www.facebook.com/dir', Wovnrb::URL.prepend_path('www.facebook.com', 'dir'))
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
def test_prepend_path_no_protocoli_no_host
|
86
|
+
assert_equal('facebook.com/dir/test/', Wovnrb::URL.prepend_path('facebook.com/test/', 'dir'))
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_prepend_path_no_protocol_no_host_long_path
|
90
|
+
assert_equal('facebook.com/dir/test/try/again/', Wovnrb::URL.prepend_path('facebook.com/test/try/again/', 'dir'))
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_prepend_path_no_protocol_no_host_no_trailing_slash
|
94
|
+
assert_equal('facebook.com/dir/test', Wovnrb::URL.prepend_path('facebook.com/test', 'dir'))
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_prepend_path_no_protocol_no_host_long_path_no_trailing_slash
|
98
|
+
assert_equal('facebook.com/dir/test/try/again', Wovnrb::URL.prepend_path('facebook.com/test/try/again', 'dir'))
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_prepend_path_no_protocol_no_host_no_path
|
102
|
+
assert_equal('facebook.com/dir/', Wovnrb::URL.prepend_path('facebook.com/', 'dir'))
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_prepend_path_no_protocol_no_host_no_path_no_trailing_slash
|
106
|
+
assert_equal('facebook.com/dir', Wovnrb::URL.prepend_path('facebook.com', 'dir'))
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
def test_prepend_path_no_protocol_with_double_slash
|
112
|
+
assert_equal('//www.yahoo.com/dir/test/', Wovnrb::URL.prepend_path('//www.yahoo.com/test/', 'dir'))
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_prepend_path_no_protocol_long_path_with_double_slash
|
116
|
+
assert_equal('//www.yahoo.com/dir/test/try/again/', Wovnrb::URL.prepend_path('//www.yahoo.com/test/try/again/', 'dir'))
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_prepend_path_no_protocol_no_trailing_slash_with_double_slash
|
120
|
+
assert_equal('//www.yahoo.com/dir/test', Wovnrb::URL.prepend_path('//www.yahoo.com/test', 'dir'))
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_prepend_path_no_protocol_long_path_no_trailing_slash_with_double_slash
|
124
|
+
assert_equal('//www.yahoo.com/dir/test/try/again', Wovnrb::URL.prepend_path('//www.yahoo.com/test/try/again', 'dir'))
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_prepend_path_no_protocol_no_path_with_double_slash
|
128
|
+
assert_equal('//www.yahoo.com/dir/', Wovnrb::URL.prepend_path('//www.yahoo.com/', 'dir'))
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_prepend_path_no_protocol_no_path_no_trailing_slash_with_double_slash
|
132
|
+
assert_equal('//www.yahoo.com/dir', Wovnrb::URL.prepend_path('//www.yahoo.com', 'dir'))
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
def test_prepend_path_no_protocol_no_host_with_double_slash
|
138
|
+
assert_equal('//yahoo.com/dir/test/', Wovnrb::URL.prepend_path('//yahoo.com/test/', 'dir'))
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_prepend_path_no_protocol_no_host_long_path_with_double_slash
|
142
|
+
assert_equal('//yahoo.com/dir/test/try/again/', Wovnrb::URL.prepend_path('//yahoo.com/test/try/again/', 'dir'))
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_prepend_path_no_protocol_no_host_no_trailing_slash_with_double_slash
|
146
|
+
assert_equal('//yahoo.com/dir/test', Wovnrb::URL.prepend_path('//yahoo.com/test', 'dir'))
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_prepend_path_no_protocol_no_host_long_path_no_trailing_slash_with_double_slash
|
150
|
+
assert_equal('//yahoo.com/dir/test/try/again', Wovnrb::URL.prepend_path('//yahoo.com/test/try/again', 'dir'))
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_prepend_path_no_protocol_no_host_no_path_with_double_slash
|
154
|
+
assert_equal('//yahoo.com/dir/', Wovnrb::URL.prepend_path('//yahoo.com/', 'dir'))
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_prepend_path_no_protocol_no_host_no_path_no_trailing_slash_with_double_slash
|
158
|
+
assert_equal('//yahoo.com/dir', Wovnrb::URL.prepend_path('//yahoo.com', 'dir'))
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
end
|
data/wovnrb.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 1.7"
|
32
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "mocha"
|
33
34
|
#spec.add_development_dependency "rspec"
|
34
35
|
#spec.add_development_dependency "rspec-nc"
|
35
36
|
spec.add_development_dependency "test-unit"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wovnrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.65
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Sandford
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-10-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogumbo
|
@@ -67,6 +67,20 @@ dependencies:
|
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '10.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: mocha
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
70
84
|
- !ruby/object:Gem::Dependency
|
71
85
|
name: test-unit
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -248,6 +262,7 @@ files:
|
|
248
262
|
- test/lib/lang_test.rb
|
249
263
|
- test/lib/services/url_test.rb
|
250
264
|
- test/lib/wovnrb_test.rb
|
265
|
+
- test/services/url_test.rb
|
251
266
|
- test/test_helper.rb
|
252
267
|
- values/values
|
253
268
|
- wovnrb.gemspec
|
@@ -282,4 +297,5 @@ test_files:
|
|
282
297
|
- test/lib/lang_test.rb
|
283
298
|
- test/lib/services/url_test.rb
|
284
299
|
- test/lib/wovnrb_test.rb
|
300
|
+
- test/services/url_test.rb
|
285
301
|
- test/test_helper.rb
|