gin 0.0.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +3 -3
- data/.gitignore +7 -0
- data/History.rdoc +3 -6
- data/Manifest.txt +36 -2
- data/README.rdoc +24 -14
- data/Rakefile +2 -9
- data/lib/gin.rb +122 -1
- data/lib/gin/app.rb +595 -0
- data/lib/gin/config.rb +50 -0
- data/lib/gin/controller.rb +602 -0
- data/lib/gin/core_ext/cgi.rb +15 -0
- data/lib/gin/core_ext/gin_class.rb +10 -0
- data/lib/gin/errorable.rb +113 -0
- data/lib/gin/filterable.rb +200 -0
- data/lib/gin/reloadable.rb +90 -0
- data/lib/gin/request.rb +76 -0
- data/lib/gin/response.rb +51 -0
- data/lib/gin/router.rb +222 -0
- data/lib/gin/stream.rb +56 -0
- data/public/400.html +14 -0
- data/public/404.html +13 -0
- data/public/500.html +14 -0
- data/public/error.html +38 -0
- data/public/favicon.ico +0 -0
- data/public/gin.css +61 -0
- data/public/gin_sm.png +0 -0
- data/test/app/app_foo.rb +15 -0
- data/test/app/controllers/app_controller.rb +16 -0
- data/test/app/controllers/foo_controller.rb +3 -0
- data/test/mock_config/backend.yml +7 -0
- data/test/mock_config/memcache.yml +10 -0
- data/test/mock_config/not_a_config.txt +0 -0
- data/test/test_app.rb +592 -0
- data/test/test_config.rb +33 -0
- data/test/test_controller.rb +808 -0
- data/test/test_errorable.rb +221 -0
- data/test/test_filterable.rb +126 -0
- data/test/test_gin.rb +59 -0
- data/test/test_helper.rb +5 -0
- data/test/test_request.rb +81 -0
- data/test/test_response.rb +68 -0
- data/test/test_router.rb +193 -0
- metadata +80 -15
- data/bin/gin +0 -3
- data/test/gin_test.rb +0 -8
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class ResponseTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@res = Gin::Response.new
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def test_assign_body
|
11
|
+
@res.body = "foo"
|
12
|
+
assert_equal ["foo"], @res.body
|
13
|
+
|
14
|
+
@res.body = ["bar"]
|
15
|
+
assert_equal ["bar"], @res.body
|
16
|
+
|
17
|
+
rack_resp = Rack::Response.new
|
18
|
+
rack_resp.body = "rack_body"
|
19
|
+
@res.body = rack_resp
|
20
|
+
assert_equal ["rack_body"], @res.body
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def test_finish
|
25
|
+
@res.body = "foo"
|
26
|
+
expected = [200,
|
27
|
+
{"Content-Type"=>"text/html;charset=UTF-8", "Content-Length"=>"3"},
|
28
|
+
["foo"]]
|
29
|
+
|
30
|
+
assert_equal expected, @res.finish
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def test_finish_file
|
35
|
+
path = File.join(Gin::PUBLIC_DIR, "404.html")
|
36
|
+
file = File.open(path, "rb")
|
37
|
+
@res.body = file
|
38
|
+
resp = @res.finish
|
39
|
+
|
40
|
+
assert_equal file.size.to_s, resp[1]['Content-Length']
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def test_finish_bodyless
|
45
|
+
[204, 205, 304].each do |code|
|
46
|
+
@res['Content-Type'] = "application/json"
|
47
|
+
@res['Content-Length'] = "123"
|
48
|
+
@res.status = code
|
49
|
+
@res.body = "foo"
|
50
|
+
expected = [code, {}, []]
|
51
|
+
|
52
|
+
assert_equal expected, @res.finish
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def test_finish_no_ctype_clen
|
58
|
+
[100, 101].each do |code|
|
59
|
+
@res['Content-Type'] = "application/json"
|
60
|
+
@res['Content-Length'] = "123"
|
61
|
+
@res.status = code
|
62
|
+
@res.body = "foo"
|
63
|
+
expected = [code, {}, ["foo"]]
|
64
|
+
|
65
|
+
assert_equal expected, @res.finish
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/test/test_router.rb
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
require "test/test_helper"
|
2
|
+
|
3
|
+
class MyCtrl < Gin::Controller;
|
4
|
+
def index; end
|
5
|
+
def show; end
|
6
|
+
def unmounted_action; end
|
7
|
+
end
|
8
|
+
|
9
|
+
class FooController < Gin::Controller; end
|
10
|
+
|
11
|
+
|
12
|
+
class RouterTest < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@router = Gin::Router.new
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def test_add_and_retrieve
|
20
|
+
@router.add MyCtrl, '/my_ctrl' do
|
21
|
+
get :bar, "/bar"
|
22
|
+
post :foo
|
23
|
+
any :thing
|
24
|
+
end
|
25
|
+
|
26
|
+
assert_equal [MyCtrl, :bar, {}],
|
27
|
+
@router.resources_for("GET", "/my_ctrl/bar")
|
28
|
+
|
29
|
+
assert_equal [MyCtrl, :foo, {}],
|
30
|
+
@router.resources_for("post", "/my_ctrl/foo")
|
31
|
+
|
32
|
+
assert_nil @router.resources_for("post", "/my_ctrl")
|
33
|
+
|
34
|
+
%w{get post put delete head options trace}.each do |verb|
|
35
|
+
assert_equal [MyCtrl, :thing, {}],
|
36
|
+
@router.resources_for(verb, "/my_ctrl/thing")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def test_add_and_retrieve_named_route
|
42
|
+
@router.add FooController, "/foo" do
|
43
|
+
get :index, "/", :all_foo
|
44
|
+
get :bar, :my_bar
|
45
|
+
post :create
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_equal [FooController, :bar, {}],
|
49
|
+
@router.resources_for("GET", "/foo/bar")
|
50
|
+
|
51
|
+
assert_equal "/foo/bar", @router.path_to(:my_bar)
|
52
|
+
assert_equal "/foo/create", @router.path_to(:create_foo)
|
53
|
+
assert_equal "/foo", @router.path_to(:all_foo)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def test_add_and_retrieve_w_path_params
|
58
|
+
@router.add MyCtrl, '/my_ctrl/:str' do
|
59
|
+
get :bar, "/bar"
|
60
|
+
post :foo, "/"
|
61
|
+
end
|
62
|
+
|
63
|
+
assert_nil @router.resources_for("post", "/my_ctrl")
|
64
|
+
|
65
|
+
assert_equal [MyCtrl, :bar, {'str' => 'item'}],
|
66
|
+
@router.resources_for("GET", "/my_ctrl/item/bar")
|
67
|
+
|
68
|
+
assert_equal [MyCtrl, :foo, {'str' => 'item'}],
|
69
|
+
@router.resources_for("post", "/my_ctrl/item")
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def test_add_omit_base_path
|
74
|
+
@router.add MyCtrl do
|
75
|
+
get :bar
|
76
|
+
end
|
77
|
+
|
78
|
+
assert_equal [MyCtrl, :bar, {}],
|
79
|
+
@router.resources_for("GET", "/my_ctrl/bar")
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def test_add_omit_base_path_controller
|
84
|
+
@router.add FooController do
|
85
|
+
get :index, '/'
|
86
|
+
end
|
87
|
+
|
88
|
+
assert_equal [FooController, :index, {}],
|
89
|
+
@router.resources_for("GET", "/foo")
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def test_add_root_base_path
|
94
|
+
@router.add MyCtrl, "/" do
|
95
|
+
get :bar, "/"
|
96
|
+
end
|
97
|
+
|
98
|
+
assert_equal [MyCtrl, :bar, {}],
|
99
|
+
@router.resources_for("GET", "/")
|
100
|
+
|
101
|
+
assert !@router.has_route?(MyCtrl, :show)
|
102
|
+
assert !@router.has_route?(MyCtrl, :index)
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def test_add_default_restful_routes
|
107
|
+
@router.add MyCtrl, "/" do
|
108
|
+
get :show, "/:id"
|
109
|
+
end
|
110
|
+
|
111
|
+
assert !@router.has_route?(MyCtrl, :index)
|
112
|
+
assert !@router.has_route?(MyCtrl, :unmounted_action)
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
def test_add_all_restful_routes
|
117
|
+
@router.add MyCtrl, "/" do
|
118
|
+
get :show, "/:id"
|
119
|
+
defaults
|
120
|
+
end
|
121
|
+
|
122
|
+
assert @router.has_route?(MyCtrl, :index)
|
123
|
+
assert @router.has_route?(MyCtrl, :unmounted_action)
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
def test_add_all
|
128
|
+
@router.add MyCtrl, "/"
|
129
|
+
|
130
|
+
assert_equal [MyCtrl, :index, {}],
|
131
|
+
@router.resources_for("GET", "/")
|
132
|
+
|
133
|
+
assert_equal [MyCtrl, :show, {'id' => '123'}],
|
134
|
+
@router.resources_for("GET", "/123")
|
135
|
+
|
136
|
+
assert_equal [MyCtrl, :unmounted_action, {}],
|
137
|
+
@router.resources_for("GET", "/unmounted_action")
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
def test_has_route
|
142
|
+
@router.add MyCtrl, '/my_ctrl/:str' do
|
143
|
+
get :bar, "/bar"
|
144
|
+
post :foo, "/"
|
145
|
+
end
|
146
|
+
|
147
|
+
assert @router.has_route?(MyCtrl, :bar)
|
148
|
+
assert @router.has_route?(MyCtrl, :foo)
|
149
|
+
assert !@router.has_route?(MyCtrl, :thing)
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
def test_path_to
|
154
|
+
@router.add MyCtrl, '/my_ctrl/' do
|
155
|
+
get :bar, "/bar"
|
156
|
+
end
|
157
|
+
|
158
|
+
assert_equal "/my_ctrl/bar", @router.path_to(MyCtrl, :bar)
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
def test_path_to_missing
|
163
|
+
@router.add MyCtrl, '/my_ctrl/' do
|
164
|
+
get :bar, "/bar"
|
165
|
+
end
|
166
|
+
|
167
|
+
assert_raises Gin::Router::PathArgumentError do
|
168
|
+
@router.path_to(MyCtrl, :foo)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
def test_path_to_param
|
174
|
+
@router.add MyCtrl, '/my_ctrl/' do
|
175
|
+
get :show, "/:id"
|
176
|
+
end
|
177
|
+
|
178
|
+
assert_equal "/my_ctrl/val", @router.path_to(MyCtrl, :show, "id" => "val")
|
179
|
+
|
180
|
+
assert_equal "/my_ctrl/val", @router.path_to(MyCtrl, :show, :id => "val")
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
def test_path_to_param_missing
|
185
|
+
@router.add MyCtrl, '/my_ctrl/' do
|
186
|
+
get :show, "/:id"
|
187
|
+
end
|
188
|
+
|
189
|
+
assert_raises Gin::Router::PathArgumentError do
|
190
|
+
@router.path_to(MyCtrl, :show)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,40 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
21
|
+
version: '1.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rack-protection
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
28
44
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.
|
45
|
+
version: '1.0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rdoc
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,11 +75,16 @@ dependencies:
|
|
59
75
|
- - ~>
|
60
76
|
- !ruby/object:Gem::Version
|
61
77
|
version: '3.5'
|
62
|
-
description:
|
78
|
+
description: ! 'Gin is a small web framework built from the redistillation of
|
79
|
+
|
80
|
+
Sinatra and Rails idioms. Specifically, it uses much of Sinatra''s
|
81
|
+
|
82
|
+
request flow and HTTP helper methods with dedicated controller classes
|
83
|
+
|
84
|
+
that support Rails-like filters.'
|
63
85
|
email:
|
64
86
|
- yaksnrainbows@gmail.com
|
65
|
-
executables:
|
66
|
-
- gin
|
87
|
+
executables: []
|
67
88
|
extensions: []
|
68
89
|
extra_rdoc_files:
|
69
90
|
- History.rdoc
|
@@ -71,15 +92,49 @@ extra_rdoc_files:
|
|
71
92
|
- README.rdoc
|
72
93
|
files:
|
73
94
|
- .autotest
|
95
|
+
- .gitignore
|
74
96
|
- History.rdoc
|
75
97
|
- Manifest.txt
|
76
98
|
- README.rdoc
|
77
99
|
- Rakefile
|
78
|
-
- bin/gin
|
79
100
|
- lib/gin.rb
|
80
|
-
-
|
101
|
+
- lib/gin/app.rb
|
102
|
+
- lib/gin/config.rb
|
103
|
+
- lib/gin/controller.rb
|
104
|
+
- lib/gin/core_ext/cgi.rb
|
105
|
+
- lib/gin/core_ext/gin_class.rb
|
106
|
+
- lib/gin/errorable.rb
|
107
|
+
- lib/gin/filterable.rb
|
108
|
+
- lib/gin/reloadable.rb
|
109
|
+
- lib/gin/request.rb
|
110
|
+
- lib/gin/response.rb
|
111
|
+
- lib/gin/router.rb
|
112
|
+
- lib/gin/stream.rb
|
113
|
+
- public/400.html
|
114
|
+
- public/404.html
|
115
|
+
- public/500.html
|
116
|
+
- public/error.html
|
117
|
+
- public/favicon.ico
|
118
|
+
- public/gin.css
|
119
|
+
- public/gin_sm.png
|
120
|
+
- test/app/app_foo.rb
|
121
|
+
- test/app/controllers/app_controller.rb
|
122
|
+
- test/app/controllers/foo_controller.rb
|
123
|
+
- test/mock_config/backend.yml
|
124
|
+
- test/mock_config/memcache.yml
|
125
|
+
- test/mock_config/not_a_config.txt
|
126
|
+
- test/test_app.rb
|
127
|
+
- test/test_config.rb
|
128
|
+
- test/test_controller.rb
|
129
|
+
- test/test_errorable.rb
|
130
|
+
- test/test_filterable.rb
|
131
|
+
- test/test_gin.rb
|
132
|
+
- test/test_helper.rb
|
133
|
+
- test/test_request.rb
|
134
|
+
- test/test_response.rb
|
135
|
+
- test/test_router.rb
|
81
136
|
- .gemtest
|
82
|
-
homepage:
|
137
|
+
homepage: http://yaks.me/gin
|
83
138
|
licenses: []
|
84
139
|
post_install_message:
|
85
140
|
rdoc_options:
|
@@ -95,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
150
|
version: '0'
|
96
151
|
segments:
|
97
152
|
- 0
|
98
|
-
hash: -
|
153
|
+
hash: -1476992371774914405
|
99
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
155
|
none: false
|
101
156
|
requirements:
|
@@ -107,6 +162,16 @@ rubyforge_project: gin
|
|
107
162
|
rubygems_version: 1.8.24
|
108
163
|
signing_key:
|
109
164
|
specification_version: 3
|
110
|
-
summary:
|
165
|
+
summary: Gin is a small web framework built from the redistillation of Sinatra and
|
166
|
+
Rails idioms
|
111
167
|
test_files:
|
112
|
-
- test/
|
168
|
+
- test/test_app.rb
|
169
|
+
- test/test_config.rb
|
170
|
+
- test/test_controller.rb
|
171
|
+
- test/test_errorable.rb
|
172
|
+
- test/test_filterable.rb
|
173
|
+
- test/test_gin.rb
|
174
|
+
- test/test_helper.rb
|
175
|
+
- test/test_request.rb
|
176
|
+
- test/test_response.rb
|
177
|
+
- test/test_router.rb
|
data/bin/gin
DELETED