sinatra_more 0.3.15 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.16
|
@@ -9,7 +9,8 @@ module SinatraMore
|
|
9
9
|
# Named paths stores the named route aliases mapping to the url
|
10
10
|
# i.e { [:account] => '/account/path', [:admin, :show] => '/admin/show/:id' }
|
11
11
|
app.set :named_paths, {}
|
12
|
-
app.set :app_name, app.name.underscore.to_sym
|
12
|
+
app.set :app_name, app.name.underscore.to_sym unless app.respond_to?(:app_name)
|
13
|
+
app.set :uri_root, '/' unless app.respond_to?(:uri_root)
|
13
14
|
app.helpers SinatraMore::RoutingHelpers
|
14
15
|
|
15
16
|
# map constructs a mapping between a named route and a specified alias
|
@@ -11,7 +11,7 @@ module SinatraMore
|
|
11
11
|
# Used to define the url mapping to the supplied alias
|
12
12
|
# NamedRoute.new(@app, :account).to('/account/path')
|
13
13
|
def to(path)
|
14
|
-
@app.named_paths[@names.unshift(@app.app_name)] = path
|
14
|
+
@app.named_paths[@names.unshift(@app.app_name)] = File.join(@app.uri_root, path)
|
15
15
|
end
|
16
16
|
|
17
17
|
# Used to define the url mappings for child aliases within a namespace
|
data/sinatra_more.gemspec
CHANGED
@@ -4,11 +4,11 @@ require 'haml'
|
|
4
4
|
|
5
5
|
class RoutingDemo < Sinatra::Base
|
6
6
|
register SinatraMore::RoutingPlugin
|
7
|
-
|
7
|
+
|
8
8
|
configure do
|
9
9
|
set :root, File.dirname(__FILE__)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
map(:admin, :show).to("/admin/:id/show")
|
13
13
|
map :admin do |namespace|
|
14
14
|
namespace.map(:update).to("/admin/:id/update/:name")
|
data/test/test_routing_plugin.rb
CHANGED
@@ -3,7 +3,7 @@ require 'fixtures/routing_app/app'
|
|
3
3
|
|
4
4
|
class TestRoutingPlugin < Test::Unit::TestCase
|
5
5
|
def app
|
6
|
-
RoutingDemo.tap { |app| app.set :environment, :test }
|
6
|
+
RoutingDemo.tap { |app| app.set :environment, :test }.tap { |app| app.set :uri_root, '/blog' }
|
7
7
|
end
|
8
8
|
|
9
9
|
context 'for links list displaying routes' do
|
@@ -22,15 +22,30 @@ class TestRoutingPlugin < Test::Unit::TestCase
|
|
22
22
|
assert_have_selector :p, :class => 'app_admin_url', :content => '/admin/25/show'
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
|
+
context 'for mounted application' do
|
27
|
+
should "support changing uri root no mount" do
|
28
|
+
demo = app.new
|
29
|
+
demo.class.stubs(:uri_root).returns("/")
|
30
|
+
demo.class.map(:demo).to('/demo')
|
31
|
+
assert_equal "/demo", demo.url_for(:demo)
|
32
|
+
end
|
33
|
+
should "support changing uri root with mount" do
|
34
|
+
demo = app.new
|
35
|
+
demo.class.stubs(:uri_root).returns("/blog")
|
36
|
+
demo.class.map(:demo).to('/demo')
|
37
|
+
assert_equal "/blog/demo", demo.url_for(:demo)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
26
41
|
context 'for failed or missing routes' do
|
27
42
|
should "properly not raise when found" do
|
28
|
-
assert_nothing_raised { app.new.url_for(:accounts) }
|
29
|
-
assert_nothing_raised { app.new.url_for(:routing_demo, :admin, :show, :id => 5) }
|
43
|
+
assert_nothing_raised { app.new.url_for(:accounts) }
|
44
|
+
assert_nothing_raised { app.new.url_for(:routing_demo, :admin, :show, :id => 5) }
|
30
45
|
end
|
31
46
|
should "properly raise not found exception" do
|
32
|
-
assert_raises(SinatraMore::RouteNotFound) { visit '/failed_route' }
|
33
|
-
assert_raises(SinatraMore::RouteNotFound) { app.new.url_for(:admin, :fake) }
|
47
|
+
assert_raises(SinatraMore::RouteNotFound) { visit '/failed_route' }
|
48
|
+
assert_raises(SinatraMore::RouteNotFound) { app.new.url_for(:admin, :fake) }
|
34
49
|
end
|
35
50
|
should "properly raise about an invalid alias for route definition" do
|
36
51
|
assert_raises(SinatraMore::RouteNotFound) { app.get(:fake) }
|
@@ -60,14 +75,14 @@ class TestRoutingPlugin < Test::Unit::TestCase
|
|
60
75
|
assert_have_selector :p, :content => "admin show for id 50"
|
61
76
|
end
|
62
77
|
end
|
63
|
-
|
78
|
+
|
64
79
|
context 'for admin update url' do
|
65
80
|
setup { visit '/admin/15/update/demo' }
|
66
81
|
should "return proper update text" do
|
67
82
|
assert_have_selector :p, :content => "updated admin with id 15 and name demo"
|
68
83
|
end
|
69
84
|
end
|
70
|
-
|
85
|
+
|
71
86
|
context 'for admin destroy url' do
|
72
87
|
setup { visit '/admin/60/destroy' }
|
73
88
|
should "return proper destroy text" do
|