ur 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +2 -2
- data/lib/ur/content_type.rb +65 -41
- data/lib/ur/middleware.rb +2 -2
- data/lib/ur/request_and_response.rb +8 -4
- data/lib/ur/sub_ur.rb +1 -1
- data/lib/ur/version.rb +1 -1
- data/lib/ur/weblink.rb +125 -0
- data/lib/ur.rb +10 -9
- data/resources/ur.schema.yml +1 -0
- data/ur.gemspec +12 -15
- metadata +11 -152
- data/.simplecov +0 -1
- data/Rakefile.rb +0 -9
- data/resources/icons/LGPL-3.0.png +0 -0
- data/test/content_type_test.rb +0 -342
- data/test/test_helper.rb +0 -33
- data/test/ur_faraday_test.rb +0 -79
- data/test/ur_metadata_test.rb +0 -11
- data/test/ur_rack_test.rb +0 -25
- data/test/ur_test.rb +0 -105
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsi
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: addressable
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,148 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rack
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rack-test
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: faraday
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: faraday_middleware
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: activesupport
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rake
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: minitest
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: minitest-reporters
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: simplecov
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
41
|
description: ur provides a unified representation of a request and response. it can
|
168
42
|
be interpreted from rack, faraday, or potentially other sources, and provides a
|
169
43
|
consistent interface to access the attributes inherent to the request and additional
|
170
44
|
useful parsers and computation from the request.
|
171
45
|
email:
|
172
|
-
- ethan@unth
|
46
|
+
- ethan.ur@unth.net
|
173
47
|
executables: []
|
174
48
|
extensions: []
|
175
49
|
extra_rdoc_files: []
|
176
50
|
files:
|
177
|
-
- ".simplecov"
|
178
51
|
- ".yardopts"
|
179
52
|
- CHANGELOG.md
|
180
53
|
- LICENSE.md
|
181
54
|
- README.md
|
182
|
-
- Rakefile.rb
|
183
55
|
- lib/ur.rb
|
184
56
|
- lib/ur/content_type.rb
|
185
57
|
- lib/ur/faraday.rb
|
@@ -191,20 +63,14 @@ files:
|
|
191
63
|
- lib/ur/response.rb
|
192
64
|
- lib/ur/sub_ur.rb
|
193
65
|
- lib/ur/version.rb
|
194
|
-
-
|
66
|
+
- lib/ur/weblink.rb
|
195
67
|
- resources/ur.schema.yml
|
196
|
-
- test/content_type_test.rb
|
197
|
-
- test/test_helper.rb
|
198
|
-
- test/ur_faraday_test.rb
|
199
|
-
- test/ur_metadata_test.rb
|
200
|
-
- test/ur_rack_test.rb
|
201
|
-
- test/ur_test.rb
|
202
68
|
- ur.gemspec
|
203
69
|
homepage: https://github.com/notEthan/ur
|
204
70
|
licenses:
|
205
71
|
- LGPL-3.0
|
206
72
|
metadata: {}
|
207
|
-
post_install_message:
|
73
|
+
post_install_message:
|
208
74
|
rdoc_options: []
|
209
75
|
require_paths:
|
210
76
|
- lib
|
@@ -219,15 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
85
|
- !ruby/object:Gem::Version
|
220
86
|
version: '0'
|
221
87
|
requirements: []
|
222
|
-
rubygems_version: 3.
|
223
|
-
signing_key:
|
88
|
+
rubygems_version: 3.1.6
|
89
|
+
signing_key:
|
224
90
|
specification_version: 4
|
225
91
|
summary: 'ur: unified request representation'
|
226
|
-
test_files:
|
227
|
-
- test/content_type_test.rb
|
228
|
-
- test/test_helper.rb
|
229
|
-
- test/ur_faraday_test.rb
|
230
|
-
- test/ur_metadata_test.rb
|
231
|
-
- test/ur_rack_test.rb
|
232
|
-
- test/ur_test.rb
|
233
|
-
- ".simplecov"
|
92
|
+
test_files: []
|
data/.simplecov
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
SimpleCov.start
|
data/Rakefile.rb
DELETED
Binary file
|
data/test/content_type_test.rb
DELETED
@@ -1,342 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
|
3
|
-
describe 'Ur::ContentType' do
|
4
|
-
let(:content_type) { Ur::ContentType.new(content_type_str) }
|
5
|
-
describe 'application/vnd.github+json; charset="utf-8"' do
|
6
|
-
let(:content_type_str) { 'application/vnd.github+json; charset="utf-8"' }
|
7
|
-
it 'parses' do
|
8
|
-
assert_equal(content_type, content_type_str)
|
9
|
-
|
10
|
-
assert_equal('application/vnd.github+json', content_type.media_type)
|
11
|
-
|
12
|
-
assert_equal('application', content_type.type)
|
13
|
-
assert(content_type.type?('Application'))
|
14
|
-
assert(content_type.type_application?)
|
15
|
-
|
16
|
-
assert_equal('vnd.github+json', content_type.subtype)
|
17
|
-
assert_equal('vnd', content_type.facet)
|
18
|
-
assert_equal('json', content_type.suffix)
|
19
|
-
|
20
|
-
assert_equal({'charset' => 'utf-8'}, content_type.parameters)
|
21
|
-
assert_equal('utf-8', content_type.parameters['CharSet'])
|
22
|
-
end
|
23
|
-
end
|
24
|
-
describe 'no subtype' do
|
25
|
-
let(:content_type_str) { 'application; charset="utf-8"' }
|
26
|
-
it 'will allow it' do
|
27
|
-
assert_equal(content_type, content_type_str)
|
28
|
-
|
29
|
-
assert_equal('application', content_type.media_type)
|
30
|
-
|
31
|
-
assert_equal('application', content_type.type)
|
32
|
-
assert(content_type.type?('Application'))
|
33
|
-
|
34
|
-
assert_equal(nil, content_type.subtype)
|
35
|
-
assert_equal(nil, content_type.facet)
|
36
|
-
assert_equal(nil, content_type.suffix)
|
37
|
-
|
38
|
-
assert_equal({'charset' => 'utf-8'}, content_type.parameters)
|
39
|
-
assert_equal('utf-8', content_type.parameters['CharSet'])
|
40
|
-
end
|
41
|
-
end
|
42
|
-
describe 'no facet' do
|
43
|
-
let(:content_type_str) { 'application/github+json; charset="utf-8"' }
|
44
|
-
it 'parses' do
|
45
|
-
assert_equal(content_type, content_type_str)
|
46
|
-
|
47
|
-
assert_equal('application/github+json', content_type.media_type)
|
48
|
-
|
49
|
-
assert_equal('application', content_type.type)
|
50
|
-
assert(content_type.type?('Application'))
|
51
|
-
|
52
|
-
assert_equal('github+json', content_type.subtype)
|
53
|
-
assert_equal(nil, content_type.facet)
|
54
|
-
assert_equal('json', content_type.suffix)
|
55
|
-
|
56
|
-
assert_equal({'charset' => 'utf-8'}, content_type.parameters)
|
57
|
-
assert_equal('utf-8', content_type.parameters['CharSet'])
|
58
|
-
end
|
59
|
-
end
|
60
|
-
describe 'no suffix' do
|
61
|
-
let(:content_type_str) { 'application/vnd.github.json; charset="utf-8"' }
|
62
|
-
it 'parses' do
|
63
|
-
assert_equal(content_type, content_type_str)
|
64
|
-
|
65
|
-
assert_equal('application/vnd.github.json', content_type.media_type)
|
66
|
-
|
67
|
-
assert_equal('application', content_type.type)
|
68
|
-
assert(content_type.type?('Application'))
|
69
|
-
|
70
|
-
assert_equal('vnd.github.json', content_type.subtype)
|
71
|
-
assert_equal('vnd', content_type.facet)
|
72
|
-
assert_equal(nil, content_type.suffix)
|
73
|
-
|
74
|
-
assert_equal({'charset' => 'utf-8'}, content_type.parameters)
|
75
|
-
assert_equal('utf-8', content_type.parameters['CharSet'])
|
76
|
-
end
|
77
|
-
describe('[invalid] quote in type') do
|
78
|
-
let(:content_type_str) { 'applic"ation/foo; foo=bar' }
|
79
|
-
it('gives up') do
|
80
|
-
assert_equal('applic', content_type.type)
|
81
|
-
assert_equal(nil, content_type.subtype)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
describe('[invalid] backslash in type') do
|
85
|
-
let(:content_type_str) { 'applicati\on/foo; foo=bar' }
|
86
|
-
it('parses') do
|
87
|
-
assert_equal('applicati\\on', content_type.type)
|
88
|
-
assert_equal('foo', content_type.subtype)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
describe('[invalid] quote in subtype') do
|
92
|
-
let(:content_type_str) { 'application/f"oo; foo=bar' }
|
93
|
-
it('gives up') do
|
94
|
-
assert_equal('application', content_type.type)
|
95
|
-
assert_equal('f', content_type.subtype)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
describe('[invalid] backslash in subtype') do
|
99
|
-
let(:content_type_str) { 'application/fo\\o; foo=bar' }
|
100
|
-
it('parses') do
|
101
|
-
assert_equal('application', content_type.type)
|
102
|
-
assert_equal('fo\\o', content_type.subtype)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
describe 'parameters' do
|
107
|
-
describe 'basic usage' do
|
108
|
-
let(:content_type_str) { 'application/foo; charset="utf-8"; foo=bar' }
|
109
|
-
it('parses') do
|
110
|
-
assert_equal({'charset' => 'utf-8', 'foo' => 'bar'}, content_type.parameters)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
describe 'params with capitalization' do
|
114
|
-
let(:content_type_str) { 'application/foo; Charset="utf-8"; FOO=bar' }
|
115
|
-
it('parses') do
|
116
|
-
assert_equal({'charset' => 'utf-8', 'foo' => 'bar'}, content_type.parameters)
|
117
|
-
assert_equal('utf-8', content_type.parameters['CharSet'])
|
118
|
-
assert_equal('utf-8', content_type.parameters['Charset'])
|
119
|
-
assert_equal('bar', content_type.parameters['foo'])
|
120
|
-
assert_equal('bar', content_type.parameters['FOO'])
|
121
|
-
end
|
122
|
-
end
|
123
|
-
describe 'repeated params' do
|
124
|
-
let(:content_type_str) { 'application/foo; foo="first"; foo=second' }
|
125
|
-
it('will just overwrite') do
|
126
|
-
assert_equal({'foo' => 'second'}, content_type.parameters)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
describe 'repeated params, different capitalization' do
|
130
|
-
let(:content_type_str) { 'application/foo; FOO=first; Foo=second' }
|
131
|
-
it('will just overwrite') do
|
132
|
-
assert_equal({'foo' => 'second'}, content_type.parameters)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
describe 'empty strings' do
|
136
|
-
let(:content_type_str) { 'application/foo; empty1=; empty2=""' }
|
137
|
-
it('parses') do
|
138
|
-
assert_equal({'empty1' => '', 'empty2' => ''}, content_type.parameters)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
describe 'empty strings with whitespace' do
|
142
|
-
let(:content_type_str) { 'application/foo; empty1= ; empty2="" ' }
|
143
|
-
it('parses') do
|
144
|
-
assert_equal({'empty1' => '', 'empty2' => ''}, content_type.parameters)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
describe('[invalid] opening quote only') do
|
148
|
-
let(:content_type_str) { 'application/foo; foo=1; bar="' }
|
149
|
-
it('parses') do
|
150
|
-
assert_equal({'foo' => '1', 'bar' => ''}, content_type.parameters)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
describe('[invalid] backlash with no character') do
|
154
|
-
let(:content_type_str) { 'application/foo; foo=1; bar="\\' }
|
155
|
-
it('parses') do
|
156
|
-
assert_equal({'foo' => '1', 'bar' => ''}, content_type.parameters)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
describe('[invalid] extra following quoted string') do
|
160
|
-
let(:content_type_str) { 'application/foo; foo="1" 2; bar=3' }
|
161
|
-
it('sorta parses') do
|
162
|
-
assert_equal({'foo' => '1 2', 'bar' => '3'}, content_type.parameters)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
describe('[invalid] quotes silliness') do
|
166
|
-
let(:content_type_str) { 'application/foo; foo="1" 2 "3 4" "5 " ; bar=3' }
|
167
|
-
it('sorta parses') do
|
168
|
-
assert_equal({'foo' => '1 2 3 4 5 ', 'bar' => '3'}, content_type.parameters)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
describe('[invalid] backlash quote') do
|
172
|
-
let(:content_type_str) { 'application/foo; foo=1; bar="\\"' }
|
173
|
-
it('parses') do
|
174
|
-
assert_equal({'foo' => '1', 'bar' => '"'}, content_type.parameters)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
describe('[invalid] trailing ;') do
|
178
|
-
let(:content_type_str) { 'application/foo; foo=bar;' }
|
179
|
-
it('parses') do
|
180
|
-
assert_equal({'foo' => 'bar'}, content_type.parameters)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
describe('[invalid] extra ; inline') do
|
184
|
-
let(:content_type_str) { 'application/foo; ; ; foo=bar' }
|
185
|
-
it('parses') do
|
186
|
-
assert_equal({'foo' => 'bar'}, content_type.parameters)
|
187
|
-
end
|
188
|
-
end
|
189
|
-
describe('[invalid] whitespace around the =') do
|
190
|
-
let(:content_type_str) { 'application/foo; foo = bar; baz = qux' }
|
191
|
-
it('parses') do
|
192
|
-
assert_equal({'foo ' => ' bar', 'baz ' => ' qux'}, content_type.parameters)
|
193
|
-
end
|
194
|
-
end
|
195
|
-
describe('whitespace before the ;') do
|
196
|
-
let(:content_type_str) { 'application/foo; foo=bar ; baz=qux' }
|
197
|
-
it('parses') do
|
198
|
-
assert_equal({'foo' => 'bar', 'baz' => 'qux'}, content_type.parameters)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
describe('no media_type') do
|
202
|
-
let(:content_type_str) { '; foo=bar' }
|
203
|
-
it('parses') do
|
204
|
-
assert_equal({'foo' => 'bar'}, content_type.parameters)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
describe('[invalid] quote in parameter name') do
|
208
|
-
let(:content_type_str) { 'application/foo; fo"o=bar' }
|
209
|
-
it('gives up') do
|
210
|
-
assert_equal({}, content_type.parameters)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
describe('[invalid] backslash in parameter name') do
|
214
|
-
let(:content_type_str) { 'application/foo; fo\\o=bar' }
|
215
|
-
it('parses') do
|
216
|
-
assert_equal({'fo\\o' => 'bar'}, content_type.parameters)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
describe 'binary?' do
|
221
|
-
binary_content_type_strs = [
|
222
|
-
'audio/ogg',
|
223
|
-
'Audio/OGG; foo=bar',
|
224
|
-
'VIDEO/foo+bar',
|
225
|
-
]
|
226
|
-
binary_content_type_strs.each do |binary_content_type_str|
|
227
|
-
describe(binary_content_type_str) do
|
228
|
-
let(:content_type_str) { binary_content_type_str }
|
229
|
-
it 'is binary' do
|
230
|
-
assert(content_type.binary?(unknown: false))
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
not_binary_content_type_strs = [
|
235
|
-
'text/anything',
|
236
|
-
'TEXT/plain; charset=foo',
|
237
|
-
'application/JSON',
|
238
|
-
'media/foo+Json; foo="bar"',
|
239
|
-
]
|
240
|
-
not_binary_content_type_strs.each do |not_binary_content_type_str|
|
241
|
-
describe(not_binary_content_type_str) do
|
242
|
-
let(:content_type_str) { not_binary_content_type_str }
|
243
|
-
it 'is not binary' do
|
244
|
-
assert(!content_type.binary?(unknown: true))
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
unknown_content_type_strs = [
|
249
|
-
'foo',
|
250
|
-
'foo/bar; note="not application/json"',
|
251
|
-
'application/jsonisnotthis',
|
252
|
-
'application/octet-stream',
|
253
|
-
]
|
254
|
-
unknown_content_type_strs.each do |unknown_content_type_str|
|
255
|
-
describe(unknown_content_type_str) do
|
256
|
-
let(:content_type_str) { unknown_content_type_str }
|
257
|
-
it 'is unknown' do
|
258
|
-
assert(content_type.binary?(unknown: true))
|
259
|
-
assert(!content_type.binary?(unknown: false))
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
describe 'json?' do
|
265
|
-
json_content_type_strs = [
|
266
|
-
'application/json',
|
267
|
-
'Application/Json; charset=EBCDIC',
|
268
|
-
'Text/json',
|
269
|
-
'MEDIA/JSON',
|
270
|
-
'media/foo.bar+json',
|
271
|
-
'media/foo.bar+json; foo=',
|
272
|
-
]
|
273
|
-
json_content_type_strs.each do |json_content_type_str|
|
274
|
-
describe(json_content_type_str) do
|
275
|
-
let(:content_type_str) { json_content_type_str }
|
276
|
-
it 'is json' do
|
277
|
-
assert(content_type.json?)
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
not_json_content_type_strs = [
|
282
|
-
'json',
|
283
|
-
'foo/bar; note="not application/json"',
|
284
|
-
'application/jsonisnotthis',
|
285
|
-
'text/json+xml', # I don't even know what I'm trying for here
|
286
|
-
]
|
287
|
-
not_json_content_type_strs.each do |not_json_content_type_str|
|
288
|
-
describe(not_json_content_type_str) do
|
289
|
-
let(:content_type_str) { not_json_content_type_str }
|
290
|
-
it 'is not json' do
|
291
|
-
assert(!content_type.json?)
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|
296
|
-
describe 'xml?' do
|
297
|
-
xml_content_type_strs = [
|
298
|
-
'application/xml',
|
299
|
-
'Application/Xml; charset=EBCDIC',
|
300
|
-
'Text/xml',
|
301
|
-
'MEDIA/XML',
|
302
|
-
'media/foo.bar+xml',
|
303
|
-
'media/foo.bar+xml; foo=',
|
304
|
-
]
|
305
|
-
xml_content_type_strs.each do |xml_content_type_str|
|
306
|
-
describe(xml_content_type_str) do
|
307
|
-
let(:content_type_str) { xml_content_type_str }
|
308
|
-
it 'is xml' do
|
309
|
-
assert(content_type.xml?)
|
310
|
-
end
|
311
|
-
end
|
312
|
-
end
|
313
|
-
not_xml_content_type_strs = [
|
314
|
-
'xml',
|
315
|
-
'foo/bar; note="not application/xml"',
|
316
|
-
'application/xmlisnotthis',
|
317
|
-
'text/xml+json', # I don't even know what I'm trying for here
|
318
|
-
]
|
319
|
-
not_xml_content_type_strs.each do |not_xml_content_type_str|
|
320
|
-
describe(not_xml_content_type_str) do
|
321
|
-
let(:content_type_str) { not_xml_content_type_str }
|
322
|
-
it 'is not xml' do
|
323
|
-
assert(!content_type.xml?)
|
324
|
-
end
|
325
|
-
end
|
326
|
-
end
|
327
|
-
end
|
328
|
-
describe 'form_urlencoded?' do
|
329
|
-
describe('application/x-www-form-urlencoded') do
|
330
|
-
let(:content_type_str) { 'application/x-www-form-urlencoded' }
|
331
|
-
it 'is form_urlencoded' do
|
332
|
-
assert(content_type.form_urlencoded?)
|
333
|
-
end
|
334
|
-
end
|
335
|
-
describe('application/foo') do
|
336
|
-
let(:content_type_str) { 'application/foo' }
|
337
|
-
it 'is not form_urlencoded' do
|
338
|
-
assert(!content_type.form_urlencoded?)
|
339
|
-
end
|
340
|
-
end
|
341
|
-
end
|
342
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
proc { |p| $:.unshift(p) unless $:.any? { |lp| File.expand_path(lp) == p } }.call(File.expand_path('../lib', File.dirname(__FILE__)))
|
2
|
-
|
3
|
-
require 'simplecov'
|
4
|
-
require 'byebug'
|
5
|
-
|
6
|
-
# NO EXPECTATIONS
|
7
|
-
ENV["MT_NO_EXPECTATIONS"] = ''
|
8
|
-
|
9
|
-
require 'minitest/autorun'
|
10
|
-
require 'minitest/reporters'
|
11
|
-
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
12
|
-
|
13
|
-
class UrSpec < Minitest::Spec
|
14
|
-
if ENV['UR_TEST_ALPHA']
|
15
|
-
# :nocov:
|
16
|
-
define_singleton_method(:test_order) { :alpha }
|
17
|
-
# :nocov:
|
18
|
-
end
|
19
|
-
|
20
|
-
def assert_json_equal(exp, act, *a)
|
21
|
-
assert_equal(JSI::Typelike.as_json(exp), JSI::Typelike.as_json(act), *a)
|
22
|
-
end
|
23
|
-
|
24
|
-
def assert_equal exp, act, msg = nil
|
25
|
-
msg = message(msg, E) { diff exp, act }
|
26
|
-
assert exp == act, msg
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# register this to be the base class for specs instead of Minitest::Spec
|
31
|
-
Minitest::Spec.register_spec_type(//, UrSpec)
|
32
|
-
|
33
|
-
require 'ur'
|
data/test/ur_faraday_test.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
require 'faraday'
|
3
|
-
require 'faraday_middleware'
|
4
|
-
|
5
|
-
describe 'Ur faraday integration' do
|
6
|
-
it 'integrates, basic usage' do
|
7
|
-
ur = nil
|
8
|
-
faraday_conn = ::Faraday.new('https://ur.unth.net/') do |builder|
|
9
|
-
builder.use(Ur::FaradayMiddleware,
|
10
|
-
after_response: -> (ur_) { ur = ur_ },
|
11
|
-
)
|
12
|
-
builder.adapter(:rack, -> (env) { [200, {'Content-Type' => 'text/plain'}, ['ᚒ']] })
|
13
|
-
end
|
14
|
-
res = faraday_conn.get('/')
|
15
|
-
assert_equal('ᚒ', res.body)
|
16
|
-
assert_kind_of(Ur, ur)
|
17
|
-
assert_equal('get', ur.request['method'])
|
18
|
-
assert_equal('text/plain', ur.response.headers['Content-Type'])
|
19
|
-
assert_equal('ᚒ', ur.response.body)
|
20
|
-
assert(ur.validate)
|
21
|
-
end
|
22
|
-
it 'integrates, IO body' do
|
23
|
-
ur = nil
|
24
|
-
faraday_conn = ::Faraday.new('https://ur.unth.net/') do |builder|
|
25
|
-
builder.use(Ur::FaradayMiddleware,
|
26
|
-
after_response: -> (ur_) { ur = ur_ },
|
27
|
-
)
|
28
|
-
builder.adapter(:rack, -> (env) { [200, {'Content-Type' => 'text/plain'}, ['☺']] })
|
29
|
-
end
|
30
|
-
res = faraday_conn.post('/', StringIO.new('hello!'))
|
31
|
-
assert_equal('☺', res.body)
|
32
|
-
assert_kind_of(Ur, ur)
|
33
|
-
assert_equal('post', ur.request['method'])
|
34
|
-
assert_equal('hello!', ur.request.body)
|
35
|
-
assert_equal('text/plain', ur.response.headers['Content-Type'])
|
36
|
-
assert_equal('☺', ur.response.body)
|
37
|
-
assert(ur.validate)
|
38
|
-
end
|
39
|
-
it 'integrates, faraday middleware munges the json bodies but uses preserve_raw' do
|
40
|
-
ur = nil
|
41
|
-
faraday_conn = ::Faraday.new('https://ur.unth.net/') do |builder|
|
42
|
-
builder.request :json
|
43
|
-
builder.use(Ur::FaradayMiddleware,
|
44
|
-
after_response: -> (ur_) { ur = ur_ },
|
45
|
-
)
|
46
|
-
builder.response :json, preserve_raw: true
|
47
|
-
builder.adapter(:rack, -> (env) { [200, {'Content-Type' => 'application/json'}, ['{}']] })
|
48
|
-
end
|
49
|
-
res = faraday_conn.post('/', {'a' => 'b'})
|
50
|
-
assert_equal({}, res.body)
|
51
|
-
assert_kind_of(Ur, ur)
|
52
|
-
assert_equal('post', ur.request['method'])
|
53
|
-
assert_equal('{"a":"b"}', ur.request.body)
|
54
|
-
assert_equal('application/json', ur.response.headers['Content-Type'])
|
55
|
-
assert_equal('{}', ur.response.body)
|
56
|
-
assert(ur.validate)
|
57
|
-
end
|
58
|
-
it 'integrates, faraday middleware munges the json bodies and does not preserve_raw' do
|
59
|
-
ur = nil
|
60
|
-
faraday_conn = ::Faraday.new('https://ur.unth.net/') do |builder|
|
61
|
-
builder.use(Ur::FaradayMiddleware,
|
62
|
-
after_response: -> (ur_) { ur = ur_ },
|
63
|
-
)
|
64
|
-
builder.request :json
|
65
|
-
builder.response :json
|
66
|
-
builder.adapter(:rack, -> (env) { [200, {'Content-Type' => 'application/json'}, ['{}']] })
|
67
|
-
end
|
68
|
-
res = faraday_conn.post('/', {'a' => 'b'})
|
69
|
-
assert_equal({}, res.body)
|
70
|
-
assert_kind_of(Ur, ur)
|
71
|
-
assert_equal('post', ur.request['method'])
|
72
|
-
assert_nil(ur.request.body) # no good
|
73
|
-
assert_json_equal({"a" => "b"}, ur.request['body_parsed']) # best we get here
|
74
|
-
assert_equal('application/json', ur.response.headers['Content-Type'])
|
75
|
-
assert_nil(ur.response.body) # no good
|
76
|
-
assert_json_equal({}, ur.response['body_parsed']) # best we get here
|
77
|
-
assert(ur.validate)
|
78
|
-
end
|
79
|
-
end
|