woah 1.2.2 → 1.2.3
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.
- checksums.yaml +4 -4
- data/lib/woah/base.rb +173 -171
- data/lib/woah/route.rb +34 -32
- data/lib/woah/version.rb +2 -2
- data/test/basic_verbs_test.rb +23 -23
- data/test/before_after_test.rb +14 -14
- data/test/cookie_test.rb +51 -51
- data/test/on_method_test.rb +79 -79
- data/test/redirect_test.rb +17 -17
- data/test/test_app.rb +36 -36
- data/test/test_helper.rb +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddb6b67913b808a98ad7c48a4382979b17b21b8ef0b1850b9a35095a60c492a4
|
4
|
+
data.tar.gz: d62145c5797169caf6168b9e731aa398988ea52a65820e5e6f1d98482f86dc87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8d3e98403cd86bdad62c2bfdda6ca74f02b6af31c1dd5da0e20874deb70be12805bf1f881222807b0139fb4dc1a39f3f0250b443b5678af42c15067a369b670
|
7
|
+
data.tar.gz: f60a750ca74dde1147300f4e3fff67936ade336d82a8f89556e7831cdd5f255897f1c141be38722b6b3a88355768f2a0a58af3f55d13522196948bfabf10ad8e
|
data/lib/woah/base.rb
CHANGED
@@ -1,175 +1,177 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Woah
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
4
|
+
# Base for apps.
|
5
|
+
class Base
|
6
|
+
@@before = nil
|
7
|
+
@@after = nil
|
8
|
+
@@routes = []
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@@override = {}
|
12
|
+
@@match = nil
|
13
|
+
@@request = nil
|
14
|
+
@@response = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
# Answer the phone.
|
18
|
+
# Finds a relevant route for the parameters in env,
|
19
|
+
# and builds a response.
|
20
|
+
def call(env)
|
21
|
+
initialize
|
22
|
+
|
23
|
+
@@request = Rack::Request.new env
|
24
|
+
|
25
|
+
@@before&.call
|
26
|
+
|
27
|
+
@@response = resolve_route env['REQUEST_URI'], env['REQUEST_METHOD']
|
28
|
+
|
29
|
+
@@after&.call
|
30
|
+
|
31
|
+
override_values
|
32
|
+
|
33
|
+
# make sure we do not give nil bodies to the server
|
34
|
+
@@response[:body] ||= ''
|
35
|
+
@@response[:body] = [@@response[:body]]
|
36
|
+
|
37
|
+
@@response.values
|
38
|
+
end
|
39
|
+
|
40
|
+
# Applies user overrides.
|
41
|
+
def override_values
|
42
|
+
%i[status headers body].each do |r|
|
43
|
+
@@response[r] = @@override[r] unless @@override[r].nil?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Resolves and executes a round.
|
48
|
+
# @param path [String, Regexp] the path to respond to
|
49
|
+
# @param method [String] the HTTP method to use
|
50
|
+
# @return [Hash] the route's response
|
51
|
+
def resolve_route(path, method)
|
52
|
+
route = @@routes.select { |r| r.matches?(method, path) }[0]
|
53
|
+
|
54
|
+
if route.nil?
|
55
|
+
return {
|
56
|
+
status: 404,
|
57
|
+
headers: { 'Content-Type' => 'text/html; charset=utf-8' },
|
58
|
+
body: 'not found L:'
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
@@match = route.match if route.match
|
63
|
+
|
64
|
+
route.execute
|
65
|
+
end
|
66
|
+
|
67
|
+
class << self
|
68
|
+
# Forwards to a new instance's #call method.
|
69
|
+
def call(env)
|
70
|
+
new.call env
|
71
|
+
end
|
72
|
+
|
73
|
+
# Get this show on the road.
|
74
|
+
# @param host [String] the host to use
|
75
|
+
# @param port [Integer] the port to use
|
76
|
+
def run!(host = '0.0.0.0', port = 4422)
|
77
|
+
Rack::Handler.pick(%w[thin puma]).run new, Host: host, Port: port
|
78
|
+
end
|
79
|
+
|
80
|
+
# Register new routes. The optional method argument can be used to specify
|
81
|
+
# a method.
|
82
|
+
# @param path [String, Regexp] the path to respond to
|
83
|
+
# @param method [String] the HTTP method to use
|
84
|
+
# @raise [ArgumentError] if `method` is not a valid HTTP method
|
85
|
+
def on(path, method = 'GET', &action)
|
86
|
+
unless %w[DELETE GET HEAD OPTIONS PATCH POST PUT].include? method
|
87
|
+
raise ArgumentError, 'Unknown method'
|
88
|
+
end
|
89
|
+
|
90
|
+
@@routes.push Route.new(path, method, &action)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Takes a block that will be executed before every route.
|
94
|
+
def before(&action)
|
95
|
+
@@before = action
|
96
|
+
end
|
97
|
+
|
98
|
+
# Takes a block that will be executed after every route.
|
99
|
+
def after(&action)
|
100
|
+
@@after = action
|
101
|
+
end
|
102
|
+
|
103
|
+
# Redirect to another route.
|
104
|
+
# @param path [String, Regexp] the path to redirect to
|
105
|
+
# @param method [String] the HTTP method to use
|
106
|
+
# @return [String] the redirect's body
|
107
|
+
def redirect_to(path, method = 'GET')
|
108
|
+
result = new.resolve_route path, method
|
109
|
+
|
110
|
+
%i[status headers].each do |r|
|
111
|
+
set r, result[r]
|
112
|
+
end
|
113
|
+
|
114
|
+
result[:body]
|
115
|
+
end
|
116
|
+
|
117
|
+
# Override an item in the response.
|
118
|
+
# @param item [:status, :headers, :body] the item to be overriden
|
119
|
+
# @param content the content to override the item with
|
120
|
+
# @raise [ArgumentError] if item is outside the range of accepted values
|
121
|
+
def set(item, content)
|
122
|
+
unless %i[status headers body].include? item
|
123
|
+
raise ArgumentError, "Unknown item #{item}, cannot override"
|
124
|
+
end
|
125
|
+
|
126
|
+
@@override[item] = content
|
127
|
+
end
|
128
|
+
|
129
|
+
# Set or read cookies.
|
130
|
+
# Depending on the type of `value`, respectively reads, deletes, or sets
|
131
|
+
# a cookie.
|
132
|
+
# @param key [String] the name of the cookie
|
133
|
+
# @param value [nil, :delete, String]
|
134
|
+
def cookie(key, value = nil)
|
135
|
+
if value.nil?
|
136
|
+
read_cookie key
|
137
|
+
elsif value == :delete
|
138
|
+
del_cookie key
|
139
|
+
elsif value.is_a? String
|
140
|
+
set_cookie key, value
|
141
|
+
else
|
142
|
+
raise ArgumentError, 'Value should be nil, :delete, or a string'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# Returns the value of class attribute match.
|
147
|
+
def match
|
148
|
+
@@match
|
149
|
+
end
|
150
|
+
|
151
|
+
# Returns the value of class attribute request.
|
152
|
+
def request
|
153
|
+
@@request
|
154
|
+
end
|
155
|
+
|
156
|
+
private
|
157
|
+
|
158
|
+
def read_cookie(key)
|
159
|
+
@@request.env['HTTP_COOKIE']&.split('; ')&.each do |c|
|
160
|
+
s = c.split('=')
|
161
|
+
return s[1] if s[0] == key
|
162
|
+
end
|
163
|
+
nil # if not found
|
164
|
+
end
|
165
|
+
|
166
|
+
def del_cookie(key)
|
167
|
+
@@override[:headers] ||= {}
|
168
|
+
Rack::Utils.delete_cookie_header! @@override[:headers], key
|
169
|
+
end
|
170
|
+
|
171
|
+
def set_cookie(key, value)
|
172
|
+
@@override[:headers] ||= {}
|
173
|
+
Rack::Utils.set_cookie_header! @@override[:headers], key, value
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
175
177
|
end
|
data/lib/woah/route.rb
CHANGED
@@ -1,40 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Woah
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
# A Woah! routes
|
5
|
+
class Route
|
6
|
+
attr_accessor :match
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
def initialize(path, method, &action)
|
9
|
+
unless [String, Regexp].include? path.class
|
10
|
+
raise 'only strings and regexps are valid paths'
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
@path = path
|
14
|
+
@method = method
|
15
|
+
@action = action
|
16
|
+
@match = nil
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
# Checks if a given route is the same as this one
|
20
|
+
# @param path [String, Regexp] the path to redirect to
|
21
|
+
# @param method [String] the HTTP method to use
|
22
|
+
# @return [Boolean] true if given method and path match this route
|
23
|
+
def matches?(method, path)
|
24
|
+
case @path
|
25
|
+
when String
|
26
|
+
@method == method && @path == path
|
27
|
+
when Regexp
|
28
|
+
@match = @path.match path
|
29
|
+
@method == method && @match
|
30
|
+
end
|
31
|
+
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
# Execute this route's actions.
|
34
|
+
# @return [Hash] the route's response
|
35
|
+
def execute
|
36
|
+
status = 200
|
37
|
+
headers = { 'Content-Type' => 'text/html; charset=utf-8' }
|
38
|
+
body = @action.call
|
39
|
+
{ status: status, headers: headers, body: body }
|
40
|
+
end
|
41
|
+
end
|
40
42
|
end
|
data/lib/woah/version.rb
CHANGED
data/test/basic_verbs_test.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class BasicVerbsTest < MiniTest::Test
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def setup
|
5
|
+
@env = {}
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def test_get_root
|
9
|
+
@env['REQUEST_URI'] = '/'
|
10
|
+
@env['REQUEST_METHOD'] = 'GET'
|
11
|
+
response = TestApp.call @env
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
assert_equal 200, response[0]
|
14
|
+
assert_equal 'hi there!', response[2][0]
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def test_post
|
18
|
+
@env['REQUEST_URI'] = '/'
|
19
|
+
@env['REQUEST_METHOD'] = 'POST'
|
20
|
+
response = TestApp.call @env
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
assert_equal 200, response[0]
|
23
|
+
assert_equal 'got post!', response[2][0]
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def test_get_404
|
27
|
+
@env['REQUEST_URI'] = '/does/not/exist'
|
28
|
+
@env['REQUEST_METHOD'] = 'GET'
|
29
|
+
response = TestApp.call @env
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
assert_equal 404, response[0]
|
32
|
+
end
|
33
33
|
end
|
data/test/before_after_test.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class BeforeAfterTest < MiniTest::Test
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def setup
|
5
|
+
@env = {}
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def test_get_before
|
9
|
+
@env['REQUEST_URI'] = '/before'
|
10
|
+
@env['REQUEST_METHOD'] = 'GET'
|
11
11
|
|
12
|
-
|
12
|
+
response = TestApp.call @env
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
assert_equal 200, response[0]
|
15
|
+
assert_equal 'chunky', response[2][0]
|
16
16
|
|
17
|
-
|
17
|
+
@env['REQUEST_URI'] = '/after'
|
18
18
|
|
19
|
-
|
19
|
+
response = TestApp.call @env
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
assert_equal 200, response[0]
|
22
|
+
assert_equal 'bacon', response[2][0]
|
23
|
+
end
|
24
24
|
end
|
data/test/cookie_test.rb
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class CookieTest < MiniTest::Test
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
4
|
+
def setup
|
5
|
+
@env = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_get_cookie
|
9
|
+
@env['REQUEST_URI'] = '/get_cookie'
|
10
|
+
@env['REQUEST_METHOD'] = 'GET'
|
11
|
+
@env['HTTP_COOKIE'] = 'test=something'
|
12
|
+
response = TestApp.call @env
|
13
|
+
|
14
|
+
assert_equal 200, response[0]
|
15
|
+
assert_equal 'something', response[2][0]
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_get_nonexistent_cookie
|
19
|
+
@env['REQUEST_URI'] = '/get_cookie'
|
20
|
+
@env['REQUEST_METHOD'] = 'GET'
|
21
|
+
response = TestApp.call @env
|
22
|
+
|
23
|
+
assert_equal 200, response[0]
|
24
|
+
assert_equal '', response[2][0]
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_set_cookie
|
28
|
+
@env['REQUEST_URI'] = '/set_cookie'
|
29
|
+
@env['REQUEST_METHOD'] = 'GET'
|
30
|
+
response = TestApp.call @env
|
31
|
+
|
32
|
+
assert_equal 200, response[0]
|
33
|
+
assert_equal 'fruit=apple', response[1]['Set-Cookie']
|
34
|
+
assert_equal '', response[2][0]
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_set_illegal_cookie
|
38
|
+
@env['REQUEST_URI'] = '/set_illegal_cookie'
|
39
|
+
@env['REQUEST_METHOD'] = 'GET'
|
40
|
+
|
41
|
+
assert_raises ArgumentError do
|
42
|
+
TestApp.call @env
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_delete_cookie
|
47
|
+
@env['REQUEST_URI'] = '/delete_cookie'
|
48
|
+
@env['REQUEST_METHOD'] = 'GET'
|
49
|
+
|
50
|
+
response = TestApp.call @env
|
51
|
+
|
52
|
+
assert_equal 200, response[0]
|
53
|
+
assert response[1]['Set-Cookie'].include? 'max-age=0'
|
54
|
+
end
|
55
55
|
end
|
data/test/on_method_test.rb
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class OnMethodTest < MiniTest::Test
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
4
|
+
def setup
|
5
|
+
@env = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_throw_404
|
9
|
+
TestApp.on '/404' do
|
10
|
+
TestApp.set :status, 404
|
11
|
+
"it's a secret to everybody"
|
12
|
+
end
|
13
|
+
|
14
|
+
@env['REQUEST_URI'] = '/404'
|
15
|
+
@env['REQUEST_METHOD'] = 'GET'
|
16
|
+
response = TestApp.call @env
|
17
|
+
|
18
|
+
assert_equal 404, response[0]
|
19
|
+
assert_equal "it's a secret to everybody", response[2][0]
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_regexp_path
|
23
|
+
TestApp.on %r{^/regex/[0-9]+$} do
|
24
|
+
'heya'
|
25
|
+
end
|
26
|
+
|
27
|
+
@env['REQUEST_URI'] = '/regex/22'
|
28
|
+
@env['REQUEST_METHOD'] = 'GET'
|
29
|
+
response = TestApp.call @env
|
30
|
+
|
31
|
+
assert_equal 200, response[0]
|
32
|
+
|
33
|
+
@env['REQUEST_URI'] = '/regex/seventy'
|
34
|
+
response = TestApp.call @env
|
35
|
+
|
36
|
+
assert_equal 404, response[0]
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_regexp_match_data
|
40
|
+
TestApp.on %r{^/myname/(\w+)$} do
|
41
|
+
'hi there, ' + TestApp.match[1]
|
42
|
+
end
|
43
|
+
|
44
|
+
@env['REQUEST_URI'] = '/myname/Charles'
|
45
|
+
@env['REQUEST_METHOD'] = 'GET'
|
46
|
+
response = TestApp.call @env
|
47
|
+
|
48
|
+
assert_equal 200, response[0]
|
49
|
+
assert_equal 'hi there, Charles', response[2][0]
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_illegal_method
|
53
|
+
assert_raises ArgumentError do
|
54
|
+
TestApp.on '/', 'BUBBLES' do
|
55
|
+
'oOooo oO oO'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
@env['REQUEST_URI'] = '/'
|
60
|
+
@env['REQUEST_METHOD'] = 'BUBBLES'
|
61
|
+
response = TestApp.call @env
|
62
|
+
|
63
|
+
assert_equal 404, response[0]
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_illegal_set
|
67
|
+
@env['REQUEST_URI'] = '/nose'
|
68
|
+
@env['REQUEST_METHOD'] = 'GET'
|
69
|
+
|
70
|
+
assert_raises ArgumentError do
|
71
|
+
TestApp.call @env
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_request_object
|
76
|
+
@env['REQUEST_URI'] = '/ip'
|
77
|
+
@env['REQUEST_METHOD'] = 'GET'
|
78
|
+
response = TestApp.call @env
|
79
|
+
|
80
|
+
assert_equal 200, response[0]
|
81
|
+
assert_equal '/ip', response[2][0]
|
82
|
+
end
|
83
83
|
end
|
data/test/redirect_test.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class RedirectTest < MiniTest::Test
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def setup
|
5
|
+
@env = {}
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
# rubocop:disable Style/GlobalVars
|
9
|
+
def test_redirect
|
10
|
+
TestApp.on '/goback' do
|
11
|
+
$something = 'gone back'
|
12
|
+
TestApp.redirect_to '/'
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
@env['REQUEST_URI'] = '/goback'
|
16
|
+
@env['REQUEST_METHOD'] = 'GET'
|
17
|
+
response = TestApp.call @env
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
assert_equal 200, response[0]
|
20
|
+
assert_equal 'hi there!', response[2][0]
|
21
|
+
assert_equal 'gone back', $something
|
22
|
+
end
|
23
|
+
# rubocop:enable Style/GlobalVars
|
24
24
|
end
|
data/test/test_app.rb
CHANGED
@@ -3,51 +3,51 @@
|
|
3
3
|
require_relative '../lib/woah'
|
4
4
|
|
5
5
|
class TestApp < Woah::Base
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
before do
|
7
|
+
@a = 'chunky'
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
on '/' do
|
11
|
+
'hi there!'
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
on '/', 'POST' do
|
15
|
+
'got post!'
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
on '/before' do
|
19
|
+
@a
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
on '/after' do
|
23
|
+
@b
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
on '/get_cookie' do
|
27
|
+
cookie 'test'
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
on '/set_cookie' do
|
31
|
+
cookie 'fruit', 'apple'
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
on '/set_illegal_cookie' do
|
35
|
+
cookie 'one', 1
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
on '/delete_cookie' do
|
39
|
+
cookie 'foo', :delete
|
40
|
+
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
on '/ip' do
|
43
|
+
request.env['REQUEST_URI']
|
44
|
+
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
TestApp.on '/nose' do
|
47
|
+
TestApp.set :nose, true
|
48
|
+
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
after do
|
51
|
+
@b = 'bacon'
|
52
|
+
end
|
53
53
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: woah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- knarka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -24,8 +24,9 @@ dependencies:
|
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.0.6
|
27
|
-
description:
|
28
|
-
|
27
|
+
description: |-
|
28
|
+
Woah! is a minimal web framework built on Rack designed to
|
29
|
+
let you just do your thing.
|
29
30
|
email: knarka@airmail.cc
|
30
31
|
executables: []
|
31
32
|
extensions: []
|
@@ -63,8 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
64
|
- !ruby/object:Gem::Version
|
64
65
|
version: '0'
|
65
66
|
requirements: []
|
66
|
-
|
67
|
-
rubygems_version: 2.7.7
|
67
|
+
rubygems_version: 3.0.3
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: Woah! is a minimal web framework built on Rack.
|