padrino-core 0.5.0 → 0.6.1
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.
- data/LICENSE +1 -1
- data/README.rdoc +232 -19
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/padrino +3 -2
- data/lib/padrino-core.rb +2 -0
- data/lib/padrino-core/application.rb +278 -24
- data/lib/padrino-core/cli.rb +102 -0
- data/lib/padrino-core/{tasks → cli}/adapter.rb +1 -2
- data/lib/padrino-core/{tasks → cli}/console.rb +1 -1
- data/lib/padrino-core/cli/rake.rb +25 -0
- data/lib/padrino-core/{tasks → cli}/test.rb +2 -3
- data/lib/padrino-core/images/404.png +0 -0
- data/lib/padrino-core/images/500.png +0 -0
- data/lib/padrino-core/loader.rb +1 -7
- data/lib/padrino-core/logger.rb +7 -3
- data/lib/padrino-core/mounter.rb +2 -0
- data/lib/padrino-core/routing.rb +0 -0
- data/lib/padrino-core/support_lite.rb +1 -1
- data/lib/padrino-core/tasks.rb +11 -82
- data/padrino-core.gemspec +14 -7
- data/test/fixtures/apps/complex.rb +2 -2
- data/test/fixtures/apps/simple.rb +1 -1
- data/test/helper.rb +0 -3
- data/test/test_reloader_complex.rb +1 -0
- data/test/test_reloader_simple.rb +21 -4
- data/test/test_routing.rb +217 -0
- metadata +21 -7
- data/lib/padrino-core/tasks/helpers.rb +0 -20
- data/lib/padrino-core/tasks/rake_tasks.rb +0 -19
@@ -9,6 +9,7 @@ class TestComplexReloader < Test::Unit::TestCase
|
|
9
9
|
Padrino.mounted_apps.clear
|
10
10
|
Padrino.mount("complex_1_demo").to("/complex_1_demo")
|
11
11
|
Padrino.mount("complex_2_demo").to("/complex_2_demo")
|
12
|
+
assert_equal ["/complex_1_demo", "/complex_2_demo"], Padrino.mounted_apps.collect(&:uri_root)
|
12
13
|
assert_equal ["complex_1_demo", "complex_2_demo"], Padrino.mounted_apps.collect(&:name)
|
13
14
|
assert Complex1Demo.reload?
|
14
15
|
assert Complex2Demo.reload?
|
@@ -21,10 +21,27 @@ class TestSimpleReloader < Test::Unit::TestCase
|
|
21
21
|
assert_equal 404, status
|
22
22
|
end
|
23
23
|
end
|
24
|
-
end
|
25
24
|
|
25
|
+
should 'keep sinatra routes' do
|
26
|
+
mock_app do
|
27
|
+
get("/"){ "ok" }
|
28
|
+
end
|
29
|
+
get "/"
|
30
|
+
assert_equal 200, status
|
31
|
+
get "/__sinatra__/404.png"
|
32
|
+
assert_equal 200, status
|
33
|
+
assert_equal "image/png", response["Content-Type"]
|
34
|
+
@app.reset_routes!
|
35
|
+
get "/"
|
36
|
+
assert_equal 404, status
|
37
|
+
get "/__sinatra__/404.png"
|
38
|
+
assert_equal 200, status
|
39
|
+
assert_equal "image/png", response["Content-Type"]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
26
43
|
context 'for simple reload functionality' do
|
27
|
-
|
44
|
+
|
28
45
|
should 'correctly instantiate SimpleDemo fixture' do
|
29
46
|
Padrino.mounted_apps.clear
|
30
47
|
Padrino.mount_core("simple_demo")
|
@@ -32,7 +49,7 @@ class TestSimpleReloader < Test::Unit::TestCase
|
|
32
49
|
assert SimpleDemo.reload?
|
33
50
|
assert_match %r{fixtures/apps/simple.rb}, SimpleDemo.app_file
|
34
51
|
end
|
35
|
-
|
52
|
+
|
36
53
|
should 'correctly reload SimpleDemo fixture' do
|
37
54
|
@app = SimpleDemo
|
38
55
|
get "/"
|
@@ -44,7 +61,7 @@ class TestSimpleReloader < Test::Unit::TestCase
|
|
44
61
|
sleep 1.2 # We need at least a cooldown of 1 sec.
|
45
62
|
get "/"
|
46
63
|
assert_equal new_phrase, body
|
47
|
-
|
64
|
+
|
48
65
|
# Now we need to prevent to commit a new changed file so we revert it
|
49
66
|
File.open(SimpleDemo.app_file, "w") { |f| f.write(buffer) }
|
50
67
|
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestRouting < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should 'ignore trailing delimiters' do
|
6
|
+
mock_app do
|
7
|
+
get("/foo"){ "okey" }
|
8
|
+
end
|
9
|
+
get "/foo"
|
10
|
+
assert_equal "okey", body
|
11
|
+
get "/foo/"
|
12
|
+
assert_equal "okey", body
|
13
|
+
end
|
14
|
+
|
15
|
+
should 'match correcly similar paths' do
|
16
|
+
mock_app do
|
17
|
+
get("/my/:foo_id"){ params[:foo_id] }
|
18
|
+
get("/my/:bar_id/bar"){ params[:bar_id] }
|
19
|
+
end
|
20
|
+
get "/my/1"
|
21
|
+
assert_equal "1", body
|
22
|
+
get "/my/2/bar"
|
23
|
+
assert_equal "2", body
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'generate basic urls'do
|
27
|
+
mock_app do
|
28
|
+
get(:foo){ url(:foo) }
|
29
|
+
get(:bar, :with => :id){ url(:bar, :id => 1) }
|
30
|
+
get("/old-bar/:id"){ params[:id] }
|
31
|
+
post(:mix, :map => "/mix-bar/:id"){ params[:id] }
|
32
|
+
get(:mix, :map => "/mix-bar/:id"){ params[:id] }
|
33
|
+
end
|
34
|
+
get "/foo"
|
35
|
+
assert_equal "/foo", body
|
36
|
+
get "/bar/2"
|
37
|
+
assert_equal "/bar/1", body
|
38
|
+
get "/old-bar/3"
|
39
|
+
assert_equal "3", body
|
40
|
+
post "/mix-bar/4"
|
41
|
+
assert_equal "4", body
|
42
|
+
get "/mix-bar/4"
|
43
|
+
assert_equal "4", body
|
44
|
+
end
|
45
|
+
|
46
|
+
should 'generate url with format' do
|
47
|
+
mock_app do
|
48
|
+
get(:a, :respond_to => :any){ url(:a, :format => :json) }
|
49
|
+
get(:b, :respond_to => :js){ url(:b, :format => :js) }
|
50
|
+
get(:c, :respond_to => [:js, :json]){ url(:c, :format => :json) }
|
51
|
+
get(:d, :respond_to => [:html, :js]){ url(:d, :format => :js, :foo => :bar) }
|
52
|
+
end
|
53
|
+
get "/a.js"
|
54
|
+
assert_equal "/a.json", body
|
55
|
+
get "/b.js"
|
56
|
+
assert_equal "/b.js", body
|
57
|
+
get "/b.ru"
|
58
|
+
assert_equal 404, status
|
59
|
+
get "/c.js"
|
60
|
+
assert_equal "/c.json", body
|
61
|
+
get "/c.json"
|
62
|
+
assert_equal "/c.json", body
|
63
|
+
get "/c.ru"
|
64
|
+
assert_equal 404, status
|
65
|
+
get "/d.json"
|
66
|
+
assert 404, status
|
67
|
+
get "/d"
|
68
|
+
assert_equal "/d.js?foo=bar", body
|
69
|
+
get "/d.js"
|
70
|
+
assert_equal "/d.js?foo=bar", body
|
71
|
+
end
|
72
|
+
|
73
|
+
should 'map routes' do
|
74
|
+
mock_app do
|
75
|
+
get(:bar){ "bar" }
|
76
|
+
end
|
77
|
+
get "/bar"
|
78
|
+
assert_equal "bar", body
|
79
|
+
assert_equal "/bar", @app.url(:bar)
|
80
|
+
end
|
81
|
+
|
82
|
+
should 'remove index from path' do
|
83
|
+
mock_app do
|
84
|
+
get(:index){ "index" }
|
85
|
+
get("/accounts/index"){ "accounts" }
|
86
|
+
end
|
87
|
+
get "/"
|
88
|
+
assert_equal "index", body
|
89
|
+
assert_equal "/", @app.url(:index)
|
90
|
+
get "/accounts"
|
91
|
+
assert_equal "accounts", body
|
92
|
+
end
|
93
|
+
|
94
|
+
should 'parse named params' do
|
95
|
+
mock_app do
|
96
|
+
get(:print, :with => :id){ "Im #{params[:id]}" }
|
97
|
+
end
|
98
|
+
get "/print/9"
|
99
|
+
assert_equal "Im 9", body
|
100
|
+
assert_equal "/print/9", @app.url(:print, :id => 9)
|
101
|
+
end
|
102
|
+
|
103
|
+
should 'respond to' do
|
104
|
+
mock_app do
|
105
|
+
get(:a, :respond_to => :js){ "js" }
|
106
|
+
get(:b, :respond_to => :any){ "any" }
|
107
|
+
get(:c, :respond_to => [:js, :json]){ "js,json" }
|
108
|
+
get(:d, :respond_to => [:html, :js]){ "html,js"}
|
109
|
+
end
|
110
|
+
get "/a"
|
111
|
+
assert_equal 404, status
|
112
|
+
get "/a.js"
|
113
|
+
assert_equal "js", body
|
114
|
+
get "/b"
|
115
|
+
assert_equal "any", body
|
116
|
+
get "/b.foo"
|
117
|
+
assert_equal "any", body
|
118
|
+
get "/c"
|
119
|
+
assert_equal 404, status
|
120
|
+
get "/c.fo"
|
121
|
+
assert_equal 404, status
|
122
|
+
get "/c.js"
|
123
|
+
assert_equal "js,json", body
|
124
|
+
get "/c.json"
|
125
|
+
assert_equal "js,json", body
|
126
|
+
get "/d"
|
127
|
+
assert_equal "html,js", body
|
128
|
+
get "/d.fo"
|
129
|
+
assert_equal 404, status
|
130
|
+
get "/d.js"
|
131
|
+
assert_equal "html,js", body
|
132
|
+
end
|
133
|
+
|
134
|
+
should 'respond_to and set content_type' do
|
135
|
+
mock_app do
|
136
|
+
get :a, :respond_to => :any do
|
137
|
+
case content_type
|
138
|
+
when :js then "js"
|
139
|
+
when :json then "json"
|
140
|
+
when :foo then "foo"
|
141
|
+
when :html then "html"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
get "/a.js"
|
146
|
+
assert_equal "js", body
|
147
|
+
assert_equal 'application/javascript', response["Content-Type"]
|
148
|
+
get "/a.json"
|
149
|
+
assert_equal "json", body
|
150
|
+
assert_equal 'application/json', response["Content-Type"]
|
151
|
+
get "/a.foo"
|
152
|
+
assert_equal "foo", body
|
153
|
+
assert_equal 'application/octet-stream', response["Content-Type"]
|
154
|
+
get "/a"
|
155
|
+
assert_equal "html", body
|
156
|
+
assert_equal 'text/html', response["Content-Type"]
|
157
|
+
end
|
158
|
+
|
159
|
+
should 'use controllers' do
|
160
|
+
mock_app do
|
161
|
+
controller "/admin" do
|
162
|
+
get("/"){ "index" }
|
163
|
+
get("/show/:id"){ "show #{params[:id]}" }
|
164
|
+
end
|
165
|
+
end
|
166
|
+
get "/admin"
|
167
|
+
assert_equal "index", body
|
168
|
+
get "/admin/show/1"
|
169
|
+
assert_equal "show 1", body
|
170
|
+
end
|
171
|
+
|
172
|
+
should 'use named controllers' do
|
173
|
+
mock_app do
|
174
|
+
controller :admin do
|
175
|
+
get(:index){ "index" }
|
176
|
+
get(:show, :with => :id){ "show #{params[:id]}" }
|
177
|
+
end
|
178
|
+
controllers :foo, :bar do
|
179
|
+
get(:index){ "foo_bar_index" }
|
180
|
+
end
|
181
|
+
end
|
182
|
+
get "/admin"
|
183
|
+
assert_equal "index", body
|
184
|
+
get "/admin/show/1"
|
185
|
+
assert_equal "show 1", body
|
186
|
+
assert_equal "/admin", @app.url(:admin_index)
|
187
|
+
assert_equal "/admin/show/1", @app.url(:admin_show, :id => 1)
|
188
|
+
get "/foo/bar"
|
189
|
+
assert_equal "foo_bar_index", body
|
190
|
+
end
|
191
|
+
|
192
|
+
should 'reset routes' do
|
193
|
+
mock_app do
|
194
|
+
get("/"){ "foo" }
|
195
|
+
router.reset!
|
196
|
+
end
|
197
|
+
get "/"
|
198
|
+
assert_equal 404, status
|
199
|
+
end
|
200
|
+
|
201
|
+
should 'apply maps' do
|
202
|
+
mock_app do
|
203
|
+
controllers :admin do
|
204
|
+
get(:index, :map => "/"){ "index" }
|
205
|
+
get(:show, :with => :id, :map => "/show"){ "show #{params[:id]}" }
|
206
|
+
get(:edit, :map => "/edit/:id/product"){ "edit #{params[:id]}" }
|
207
|
+
end
|
208
|
+
end
|
209
|
+
get "/"
|
210
|
+
assert_equal "index", body
|
211
|
+
get "/show/1"
|
212
|
+
assert_equal "show 1", body
|
213
|
+
get "/edit/1/product"
|
214
|
+
assert_equal "edit 1", body
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2010-01-
|
15
|
+
date: 2010-01-14 00:00:00 +01:00
|
16
16
|
default_executable: padrino
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -35,6 +35,16 @@ dependencies:
|
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: 0.3.2
|
37
37
|
version:
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: usher
|
40
|
+
type: :runtime
|
41
|
+
version_requirement:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.6.2
|
47
|
+
version:
|
38
48
|
- !ruby/object:Gem::Dependency
|
39
49
|
name: thor
|
40
50
|
type: :runtime
|
@@ -124,22 +134,25 @@ files:
|
|
124
134
|
- lib/padrino-core.rb
|
125
135
|
- lib/padrino-core/application.rb
|
126
136
|
- lib/padrino-core/caller.rb
|
137
|
+
- lib/padrino-core/cli.rb
|
138
|
+
- lib/padrino-core/cli/adapter.rb
|
139
|
+
- lib/padrino-core/cli/console.rb
|
140
|
+
- lib/padrino-core/cli/rake.rb
|
141
|
+
- lib/padrino-core/cli/test.rb
|
142
|
+
- lib/padrino-core/images/404.png
|
143
|
+
- lib/padrino-core/images/500.png
|
127
144
|
- lib/padrino-core/loader.rb
|
128
145
|
- lib/padrino-core/locale/en.yml
|
129
146
|
- lib/padrino-core/logger.rb
|
130
147
|
- lib/padrino-core/mounter.rb
|
131
148
|
- lib/padrino-core/reloader.rb
|
149
|
+
- lib/padrino-core/routing.rb
|
132
150
|
- lib/padrino-core/server.rb
|
133
151
|
- lib/padrino-core/stat.rb
|
134
152
|
- lib/padrino-core/support_lite.rb
|
135
153
|
- lib/padrino-core/support_lite/as_support.rb
|
136
154
|
- lib/padrino-core/support_lite/extlib_support.rb
|
137
155
|
- lib/padrino-core/tasks.rb
|
138
|
-
- lib/padrino-core/tasks/adapter.rb
|
139
|
-
- lib/padrino-core/tasks/console.rb
|
140
|
-
- lib/padrino-core/tasks/helpers.rb
|
141
|
-
- lib/padrino-core/tasks/rake_tasks.rb
|
142
|
-
- lib/padrino-core/tasks/test.rb
|
143
156
|
- lib/padrino-core/version.rb
|
144
157
|
- padrino-core.gemspec
|
145
158
|
- test/fixtures/apps/.components
|
@@ -153,6 +166,7 @@ files:
|
|
153
166
|
- test/test_mounter.rb
|
154
167
|
- test/test_reloader_complex.rb
|
155
168
|
- test/test_reloader_simple.rb
|
169
|
+
- test/test_routing.rb
|
156
170
|
- test/test_server.rb
|
157
171
|
has_rdoc: true
|
158
172
|
homepage: http://github.com/padrino/padrino-framework/tree/master/padrino-core
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Padrino
|
2
|
-
module Tasks
|
3
|
-
module Helpers
|
4
|
-
|
5
|
-
def chdir(dir)
|
6
|
-
return unless dir
|
7
|
-
begin
|
8
|
-
Dir.chdir(dir.to_s)
|
9
|
-
rescue Errno::ENOENT
|
10
|
-
puts "=> Specified Padrino root '#{dir}' " +
|
11
|
-
"does not appear to exist!"
|
12
|
-
rescue Errno::EACCES
|
13
|
-
puts "=> Specified Padrino root '#{dir}' " +
|
14
|
-
"cannot be accessed by the current user!"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
|
5
|
-
Dir["lib/tasks/**/*.rake"].each { |ext| load(ext) }
|
6
|
-
|
7
|
-
# TODO: require here padrino-gen rake db:migrate, padrino-routes rake routes etc...
|
8
|
-
|
9
|
-
class Padrino::Tasks::RakeFile
|
10
|
-
cattr_accessor :boot_file
|
11
|
-
end
|
12
|
-
|
13
|
-
task :environment do
|
14
|
-
require Padrino::Tasks::RakeFile.boot_file
|
15
|
-
Padrino.mounted_apps.each do |app|
|
16
|
-
Padrino.require_dependency(app.app_file)
|
17
|
-
app.app_object.setup_application!
|
18
|
-
end
|
19
|
-
end
|