helmet 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/test/api_test.rb +90 -0
- data/test/template_test.rb +27 -0
- data/test/test_helper.rb +9 -0
- metadata +5 -2
data/test/api_test.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
class Simple < Helmet::API
|
6
|
+
|
7
|
+
before /\/x\w*$/ do
|
8
|
+
halt 'filtered!'
|
9
|
+
end
|
10
|
+
|
11
|
+
get '/' do
|
12
|
+
'get'
|
13
|
+
end
|
14
|
+
|
15
|
+
post '/' do
|
16
|
+
'post'
|
17
|
+
end
|
18
|
+
|
19
|
+
put '/' do
|
20
|
+
'put'
|
21
|
+
end
|
22
|
+
|
23
|
+
delete '/' do
|
24
|
+
'delete'
|
25
|
+
end
|
26
|
+
|
27
|
+
get '/redirect' do
|
28
|
+
redirect '/redirected'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class APITest < Test::Unit::TestCase
|
33
|
+
include Goliath::TestHelper
|
34
|
+
|
35
|
+
# code from goliath test
|
36
|
+
def setup
|
37
|
+
@err = Proc.new { assert false, "API request failed" }
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_get
|
41
|
+
with_api(Simple) do
|
42
|
+
get_request({}, @err) do |c|
|
43
|
+
assert_equal 'get', c.response
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_post
|
49
|
+
with_api(Simple) do
|
50
|
+
post_request({}, @err) do |c|
|
51
|
+
assert_equal 'post', c.response
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_put
|
57
|
+
with_api(Simple) do
|
58
|
+
put_request({}, @err) do |c|
|
59
|
+
assert_equal 'put', c.response
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_delete
|
65
|
+
with_api(Simple) do
|
66
|
+
delete_request({}, @err) do |c|
|
67
|
+
assert_equal 'delete', c.response
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_filter
|
73
|
+
with_api(Simple) do
|
74
|
+
get_request({:path => '/xx'}, @err) do |c|
|
75
|
+
assert_equal 'filtered!', c.response
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_redirected
|
81
|
+
with_api(Simple) do
|
82
|
+
get_request({:path => '/redirect'}, @err) do |c|
|
83
|
+
assert_equal c.response_header.status, 302
|
84
|
+
uri = URI.parse(c.response_header['LOCATION'])
|
85
|
+
assert_equal '/redirected', uri.path
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class TemplateAPI < Helmet::API
|
4
|
+
|
5
|
+
get '/' do
|
6
|
+
@test = 'test'
|
7
|
+
erb :test
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
class TemplateTest < Test::Unit::TestCase
|
13
|
+
include Goliath::TestHelper
|
14
|
+
|
15
|
+
# code from goliath test
|
16
|
+
def setup
|
17
|
+
@err = Proc.new { assert false, "API request failed" }
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_template_binding
|
21
|
+
with_api(TemplateAPI) do
|
22
|
+
get_request({}, @err) do |c|
|
23
|
+
assert_equal 'test', c.response
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'goliath/test_helper'
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'helmet', 'api')
|
5
|
+
|
6
|
+
# STDOUT.puts "File dirname: #{File.dirname(__FILE__)}"
|
7
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
8
|
+
|
9
|
+
Goliath.env = :test
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: helmet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Thiago Lewin
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-09
|
13
|
+
date: 2012-10-09 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: goliath
|
@@ -48,6 +48,9 @@ files:
|
|
48
48
|
- lib/helmet/response.rb
|
49
49
|
- lib/helmet/templates.rb
|
50
50
|
- lib/helmet.rb
|
51
|
+
- test/api_test.rb
|
52
|
+
- test/template_test.rb
|
53
|
+
- test/test_helper.rb
|
51
54
|
homepage: https://github.com/tlewin/helmet
|
52
55
|
licenses: []
|
53
56
|
|