hobbit-contrib 0.5.3 → 0.6.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/hobbit-contrib.gemspec +1 -0
- data/lib/hobbit/contrib/version.rb +1 -1
- data/lib/hobbit/filter.rb +5 -4
- data/test/environment_test.rb +14 -14
- data/test/error_handling_and_filter_test.rb +8 -8
- data/test/error_handling_test.rb +10 -10
- data/test/filter_test.rb +14 -10
- data/test/helper.rb +1 -0
- data/test/mote_test.rb +5 -5
- data/test/render_test.rb +6 -6
- data/test/session_test.rb +2 -2
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 802654dd916d3a7a81d580faf85e0d5c1bf9eeb1
|
4
|
+
data.tar.gz: 769fec8b8f0a05d54ddb9e94481485642daa3186
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da0ff48b1b5d7f9682e149c6e056426f01c43ee03a2dbbb39417a7278778628e5a82c7b6b98a46050234a25c051fb2fefa2e2031526dbb3865cbfec8985cfdd9
|
7
|
+
data.tar.gz: f75f472b13d2b8bd52bcb1ccaf1650311a6fea541b97aff553ce001e8668c71e611e42016ecb926abf04ec0c169536a3ead2a4db2c4bd6b58e1d7dccf43e7b4b
|
data/CHANGELOG.md
CHANGED
data/hobbit-contrib.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'erubis'
|
24
24
|
spec.add_development_dependency 'mote'
|
25
25
|
spec.add_development_dependency 'oktobertest'
|
26
|
+
spec.add_development_dependency 'oktobertest-contrib'
|
26
27
|
spec.add_development_dependency 'rack-test'
|
27
28
|
spec.add_development_dependency 'rake'
|
28
29
|
spec.add_development_dependency 'tilt'
|
data/lib/hobbit/filter.rb
CHANGED
@@ -34,15 +34,15 @@ module Hobbit
|
|
34
34
|
unless @response.status == 302
|
35
35
|
# we have to do this because `super` will override @response and @request
|
36
36
|
prev_response = @response
|
37
|
-
super
|
38
|
-
@response.
|
37
|
+
current_response = super
|
38
|
+
@response = Hobbit::Response.new current_response[2], current_response[0], current_response[1].merge!(prev_response.headers)
|
39
39
|
filter :after unless @halted
|
40
40
|
end
|
41
|
+
@response.finish
|
41
42
|
end
|
42
|
-
@response.finish
|
43
43
|
end
|
44
44
|
|
45
|
-
def halt(
|
45
|
+
def halt(response)
|
46
46
|
@halted = true
|
47
47
|
super
|
48
48
|
end
|
@@ -57,6 +57,7 @@ module Hobbit
|
|
57
57
|
filter = find_filter(kind)
|
58
58
|
if filter
|
59
59
|
instance_eval(&filter[:block])
|
60
|
+
response.finish if kind == :after
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
data/test/environment_test.rb
CHANGED
@@ -16,7 +16,7 @@ scope Hobbit::Environment do
|
|
16
16
|
scope '::environment' do
|
17
17
|
test 'returns the current environment' do
|
18
18
|
with_env('development') do
|
19
|
-
|
19
|
+
assert_equal :development, app.to_app.class.environment
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -24,7 +24,7 @@ scope Hobbit::Environment do
|
|
24
24
|
scope '#environment' do
|
25
25
|
test 'returns the current environment' do
|
26
26
|
with_env('development') do
|
27
|
-
|
27
|
+
assert_equal :development, app.to_app.environment
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -32,71 +32,71 @@ scope Hobbit::Environment do
|
|
32
32
|
scope '::development?' do
|
33
33
|
test "returns true if ENV['RACK_ENV'] = :development" do
|
34
34
|
with_env('development') do
|
35
|
-
assert app.to_app.class.development?
|
35
|
+
assert app.to_app.class.development?
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
test "returns false if ENV['RACK_ENV'] != :development" do
|
40
|
-
assert app.to_app.class.development?
|
40
|
+
assert !app.to_app.class.development?
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
scope '#development?' do
|
45
45
|
test "returns true if ENV['RACK_ENV'] = :development" do
|
46
46
|
with_env('development') do
|
47
|
-
assert app.to_app.development?
|
47
|
+
assert app.to_app.development?
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
test "returns false if ENV['RACK_ENV'] != :development" do
|
52
|
-
assert app.to_app.development?
|
52
|
+
assert !app.to_app.development?
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
scope '::production?' do
|
57
57
|
test "returns true if ENV['RACK_ENV'] = :production" do
|
58
58
|
with_env('production') do
|
59
|
-
assert app.to_app.class.production?
|
59
|
+
assert app.to_app.class.production?
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
test "returns false if ENV['RACK_ENV'] != :production" do
|
64
|
-
assert app.to_app.class.production?
|
64
|
+
assert !app.to_app.class.production?
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
scope '#production?' do
|
69
69
|
test "returns true if ENV['RACK_ENV'] = :production" do
|
70
70
|
with_env('production') do
|
71
|
-
assert app.to_app.production?
|
71
|
+
assert app.to_app.production?
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
test "returns false if ENV['RACK_ENV'] != :production" do
|
76
|
-
assert app.to_app.production?
|
76
|
+
assert !app.to_app.production?
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
scope '::test?' do
|
81
81
|
test "returns true if ENV['RACK_ENV'] = :test" do
|
82
|
-
assert app.to_app.class.test?
|
82
|
+
assert app.to_app.class.test?
|
83
83
|
end
|
84
84
|
|
85
85
|
test "returns false if ENV['RACK_ENV'] != :test" do
|
86
86
|
with_env('development') do
|
87
|
-
assert app.to_app.class.test?
|
87
|
+
assert !app.to_app.class.test?
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
scope '#test?' do
|
93
93
|
test "returns true if ENV['RACK_ENV'] = :test" do
|
94
|
-
assert app.to_app.test?
|
94
|
+
assert app.to_app.test?
|
95
95
|
end
|
96
96
|
|
97
97
|
test "returns false if ENV['RACK_ENV'] != :test" do
|
98
98
|
with_env('development') do
|
99
|
-
assert app.to_app.test?
|
99
|
+
assert !app.to_app.test?
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -29,8 +29,8 @@ scope 'combine Hobbit::ErrorHandling and Hobbit::Filter' do
|
|
29
29
|
test 'calls the before filter' do
|
30
30
|
get '/'
|
31
31
|
assert last_response.ok?
|
32
|
-
|
33
|
-
|
32
|
+
assert_equal 'Sorry', last_response.body
|
33
|
+
assert_includes last_request.env, 'hobbit.before'
|
34
34
|
assert !last_request.env.include?('hobbit.after')
|
35
35
|
end
|
36
36
|
end
|
@@ -63,7 +63,7 @@ scope 'combine Hobbit::ErrorHandling and Hobbit::Filter' do
|
|
63
63
|
test 'calls the before filter' do
|
64
64
|
get '/'
|
65
65
|
assert last_response.ok?
|
66
|
-
|
66
|
+
assert_equal 'Sorry', last_response.body
|
67
67
|
assert !last_request.env.include?('hobbit.after')
|
68
68
|
end
|
69
69
|
end
|
@@ -96,8 +96,8 @@ scope 'combine Hobbit::ErrorHandling and Hobbit::Filter' do
|
|
96
96
|
test 'calls the before filter' do
|
97
97
|
get '/'
|
98
98
|
assert last_response.ok?
|
99
|
-
|
100
|
-
|
99
|
+
assert_equal 'this is written in the body. Sorry', last_response.body
|
100
|
+
assert_includes last_request.env, 'hobbit.before'
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -130,11 +130,11 @@ scope 'combine Hobbit::ErrorHandling and Hobbit::Filter' do
|
|
130
130
|
test 'does not work as expected' do
|
131
131
|
get '/'
|
132
132
|
assert last_response.ok?
|
133
|
-
|
134
|
-
|
133
|
+
assert_equal 'Sorry', last_response.body
|
134
|
+
assert_includes last_request.env, 'hobbit.before'
|
135
135
|
# this is contrary to a previous test, which is not the desired workflow
|
136
136
|
# or is it?
|
137
|
-
|
137
|
+
assert_includes last_request.env, 'hobbit.after'
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
data/test/error_handling_test.rb
CHANGED
@@ -57,14 +57,14 @@ scope Hobbit::ErrorHandling do
|
|
57
57
|
error StandardError, &p
|
58
58
|
end
|
59
59
|
|
60
|
-
|
61
|
-
|
60
|
+
assert_includes app.to_app.class.errors, StandardError
|
61
|
+
assert_equal p.call, app.to_app.class.errors[StandardError].call
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
scope '::errors' do
|
66
66
|
test 'returns a Hash' do
|
67
|
-
|
67
|
+
assert_kind_of Hash, app.to_app.class.errors
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -72,7 +72,7 @@ scope Hobbit::ErrorHandling do
|
|
72
72
|
test 'works as expected' do
|
73
73
|
get '/'
|
74
74
|
assert last_response.ok?
|
75
|
-
|
75
|
+
assert_equal 'hello', last_response.body
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -94,25 +94,25 @@ scope Hobbit::ErrorHandling do
|
|
94
94
|
test 'calls the block set in error' do
|
95
95
|
get '/raises'
|
96
96
|
assert last_response.ok?
|
97
|
-
|
97
|
+
assert_equal 'StandardError', last_response.body
|
98
98
|
end
|
99
99
|
|
100
100
|
test 'allows to define more than one exception' do
|
101
101
|
get '/other_raises'
|
102
102
|
assert last_response.ok?
|
103
|
-
|
103
|
+
assert_equal 'Not Found', last_response.body
|
104
104
|
end
|
105
105
|
|
106
106
|
test 'allows to define a general exception class to catch' do
|
107
107
|
get '/same_other_raises'
|
108
108
|
assert last_response.ok?
|
109
|
-
|
109
|
+
assert_equal 'Not Found', last_response.body
|
110
110
|
end
|
111
111
|
|
112
112
|
test 'sets the returned value of the error block as the body' do
|
113
113
|
get '/other_raises'
|
114
114
|
assert last_response.ok?
|
115
|
-
|
115
|
+
assert_equal 'Not Found', last_response.body
|
116
116
|
assert last_response.body != 'not this'
|
117
117
|
end
|
118
118
|
|
@@ -123,14 +123,14 @@ scope Hobbit::ErrorHandling do
|
|
123
123
|
|
124
124
|
get '/raises'
|
125
125
|
assert last_response.ok?
|
126
|
-
|
126
|
+
assert_equal 'other handler!', last_response.body
|
127
127
|
end
|
128
128
|
|
129
129
|
test 'uses the response object' do
|
130
130
|
get '/must_use_response'
|
131
131
|
assert last_response.redirection?
|
132
132
|
follow_redirect!
|
133
|
-
|
133
|
+
assert_equal 'hello', last_response.body
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
data/test/filter_test.rb
CHANGED
@@ -205,7 +205,8 @@ EOS
|
|
205
205
|
include Hobbit::Filter
|
206
206
|
|
207
207
|
before do
|
208
|
-
|
208
|
+
response.status = 401
|
209
|
+
halt response.finish
|
209
210
|
end
|
210
211
|
|
211
212
|
get '/' do
|
@@ -216,7 +217,7 @@ EOS
|
|
216
217
|
|
217
218
|
test 'does not execute the route' do
|
218
219
|
get '/'
|
219
|
-
|
220
|
+
assert_status 401
|
220
221
|
assert last_response.body.empty?
|
221
222
|
end
|
222
223
|
end
|
@@ -235,17 +236,19 @@ EOS
|
|
235
236
|
end
|
236
237
|
|
237
238
|
get '/' do
|
238
|
-
|
239
|
+
response.status = 401
|
240
|
+
response.write 'Unauthenticated'
|
241
|
+
halt response.finish
|
239
242
|
end
|
240
243
|
end
|
241
244
|
end
|
242
245
|
|
243
246
|
test 'does not execute the after filter' do
|
244
247
|
get '/'
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
248
|
+
assert_status 401
|
249
|
+
assert_includes last_response.headers, 'Content-Type'
|
250
|
+
assert_header 'Content-Type', 'text/plain'
|
251
|
+
assert_equal 'Unauthenticated', last_response.body
|
249
252
|
end
|
250
253
|
end
|
251
254
|
|
@@ -255,7 +258,8 @@ EOS
|
|
255
258
|
include Hobbit::Filter
|
256
259
|
|
257
260
|
after do
|
258
|
-
|
261
|
+
response.status = 401
|
262
|
+
halt response.finish
|
259
263
|
end
|
260
264
|
|
261
265
|
get '/' do
|
@@ -266,8 +270,8 @@ EOS
|
|
266
270
|
|
267
271
|
test 'does not execute the route' do
|
268
272
|
get '/'
|
269
|
-
|
270
|
-
|
273
|
+
assert_status 401
|
274
|
+
assert_equal 'hello world', last_response.body
|
271
275
|
end
|
272
276
|
end
|
273
277
|
end
|
data/test/helper.rb
CHANGED
data/test/mote_test.rb
CHANGED
@@ -22,19 +22,19 @@ scope Hobbit::Mote do
|
|
22
22
|
|
23
23
|
scope '#default_layout' do
|
24
24
|
test 'defaults to application.mote' do
|
25
|
-
|
25
|
+
assert_equal "#{app.to_app.layouts_path}/application.mote", app.to_app.default_layout
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
scope '#find_template' do
|
30
30
|
test 'returns a template path' do
|
31
|
-
|
31
|
+
assert_equal "#{app.to_app.views_path}/index.mote", app.to_app.find_template('index')
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
scope '#layouts_path' do
|
36
36
|
test 'returns the path to the layouts directory' do
|
37
|
-
|
37
|
+
assert_equal "#{app.to_app.views_path}/layouts", app.to_app.layouts_path
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -72,7 +72,7 @@ scope Hobbit::Mote do
|
|
72
72
|
|
73
73
|
scope '#views_path' do
|
74
74
|
test 'returns the path to the views directory' do
|
75
|
-
|
75
|
+
assert_equal File.expand_path('../fixtures/mote/views', __FILE__), app.to_app.views_path
|
76
76
|
end
|
77
77
|
|
78
78
|
test 'defaults to "views"' do
|
@@ -80,7 +80,7 @@ scope Hobbit::Mote do
|
|
80
80
|
include Hobbit::Mote
|
81
81
|
end
|
82
82
|
|
83
|
-
|
83
|
+
assert_equal 'views', app.to_app.views_path
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
data/test/render_test.rb
CHANGED
@@ -24,19 +24,19 @@ scope Hobbit::Render do
|
|
24
24
|
|
25
25
|
scope '#default_layout' do
|
26
26
|
test 'defaults to application.erb' do
|
27
|
-
|
27
|
+
assert_equal "#{app.to_app.layouts_path}/application.erb", app.to_app.default_layout
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
scope '#find_template' do
|
32
32
|
test 'returns a template path' do
|
33
|
-
|
33
|
+
assert_equal "#{app.to_app.views_path}/index.#{app.to_app.template_engine}", app.to_app.find_template('index')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
scope '#layouts_path' do
|
38
38
|
test 'returns the path to the layouts directory' do
|
39
|
-
|
39
|
+
assert_equal "#{app.to_app.views_path}/layouts", app.to_app.layouts_path
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -74,13 +74,13 @@ scope Hobbit::Render do
|
|
74
74
|
|
75
75
|
scope '#template_engine' do
|
76
76
|
test 'defaults to erb' do
|
77
|
-
|
77
|
+
assert_equal 'erb', app.to_app.template_engine
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
scope '#views_path' do
|
82
82
|
test 'returns the path to the views directory' do
|
83
|
-
|
83
|
+
assert_equal File.expand_path('../fixtures/render/views', __FILE__), app.to_app.views_path
|
84
84
|
end
|
85
85
|
|
86
86
|
test 'defaults to "views"' do
|
@@ -88,7 +88,7 @@ scope Hobbit::Render do
|
|
88
88
|
include Hobbit::Render
|
89
89
|
end
|
90
90
|
|
91
|
-
|
91
|
+
assert_equal 'views', app.to_app.views_path
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
data/test/session_test.rb
CHANGED
@@ -20,11 +20,11 @@ scope Hobbit::Session do
|
|
20
20
|
test 'returns a session object' do
|
21
21
|
get '/'
|
22
22
|
assert last_response.ok?
|
23
|
-
|
23
|
+
assert_equal 'hobbit', last_response.body
|
24
24
|
|
25
25
|
get '/name'
|
26
26
|
assert last_response.ok?
|
27
|
-
|
27
|
+
assert_equal 'hobbit', last_response.body
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobbit-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patricio Mac Adden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: oktobertest-contrib
|
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'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rack-test
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|