sinatra-mapping 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +3 -0
- data/README.rdoc +4 -5
- data/VERSION +1 -1
- data/lib/sinatra/mapping.rb +1 -1
- data/test/test_mapping.rb +27 -12
- metadata +1 -1
data/CHANGES
CHANGED
data/README.rdoc
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
= Sinatra::Mapping
|
1
|
+
= Sinatra::Mapping
|
2
2
|
|
3
|
+
Map easily URLs paths.
|
3
4
|
|
4
5
|
* {Repository}[http://github.com/hallison/sinatra-mapping]
|
5
6
|
* {Project}[http://rubyforge.org/projects/sinatra-mapping]
|
@@ -33,10 +34,8 @@ Example:
|
|
33
34
|
map :root, "blog" # => /blog/
|
34
35
|
map :posts, "articles" # => /blog/articles
|
35
36
|
|
36
|
-
mapping
|
37
|
-
|
38
|
-
:archive => "archived-articles" # => /blog/archived-articles
|
39
|
-
end
|
37
|
+
mapping :tags => "labels" # => /blog/labels
|
38
|
+
:archive => "archived-articles" # => /blog/archived-articles
|
40
39
|
|
41
40
|
get root_path do
|
42
41
|
# /blog/
|
data/VERSION
CHANGED
data/lib/sinatra/mapping.rb
CHANGED
@@ -81,7 +81,7 @@ module Sinatra
|
|
81
81
|
|
82
82
|
# Returns all paths mapped by root path in prefix.
|
83
83
|
def path_mapped(*args)
|
84
|
-
!args.empty? ? cleanup_paths("/#{@
|
84
|
+
!args.empty? ? cleanup_paths("/#{@locations[:root]}/#{args.join('/')}") : @locations[:root]
|
85
85
|
end
|
86
86
|
|
87
87
|
# Get paths from location maps.
|
data/test/test_mapping.rb
CHANGED
@@ -15,8 +15,9 @@ class AppForTest < Sinatra::Base
|
|
15
15
|
map :root # root_path => /
|
16
16
|
map :about # about_path => /about
|
17
17
|
|
18
|
-
mapping :posts => "articles",
|
19
|
-
:archive => "archive/articles" # archive_path => /archive/articles
|
18
|
+
mapping :posts => "articles", # posts_path => /articles
|
19
|
+
:archive => "archive/articles", # archive_path => /archive/articles
|
20
|
+
:search => "find-articles" # search_path => /find-articles
|
20
21
|
|
21
22
|
before do
|
22
23
|
@date = Date.today
|
@@ -66,6 +67,10 @@ class AppForTest < Sinatra::Base
|
|
66
67
|
redirect path_to(:about), 301
|
67
68
|
end
|
68
69
|
|
70
|
+
get search_path do
|
71
|
+
"#{title_path :search}:#{path_to :search, :keywords => 'ruby'}"
|
72
|
+
end
|
73
|
+
|
69
74
|
end
|
70
75
|
|
71
76
|
class TestMapping < Test::Unit::TestCase
|
@@ -78,7 +83,8 @@ class TestMapping < Test::Unit::TestCase
|
|
78
83
|
:root_path => "/",
|
79
84
|
:posts_path => "/articles",
|
80
85
|
:archive_path => "/archive/articles",
|
81
|
-
:about_path => "/about"
|
86
|
+
:about_path => "/about",
|
87
|
+
:search_path => "/find-articles"
|
82
88
|
}
|
83
89
|
end
|
84
90
|
|
@@ -95,7 +101,7 @@ class TestMapping < Test::Unit::TestCase
|
|
95
101
|
end
|
96
102
|
|
97
103
|
def test_should_return_ok_in_root_path
|
98
|
-
get
|
104
|
+
get app.root_path do |response|
|
99
105
|
assert response.ok?
|
100
106
|
assert_equal "http://example.org#{@locations[:root_path]}", last_request.url
|
101
107
|
assert_equal "Path:#{@locations[:root_path]}", response.body
|
@@ -103,19 +109,19 @@ class TestMapping < Test::Unit::TestCase
|
|
103
109
|
end
|
104
110
|
|
105
111
|
def test_should_return_ok_in_posts_path
|
106
|
-
get
|
112
|
+
get app.posts_path do |response|
|
107
113
|
assert response.ok?
|
108
114
|
assert_equal "http://example.org#{@locations[:posts_path]}", last_request.url
|
109
115
|
assert_equal "Articles published:#{@locations[:posts_path]}", response.body
|
110
116
|
end
|
111
117
|
|
112
|
-
get "
|
118
|
+
get app.posts_path "/" do
|
113
119
|
follow_redirect!
|
114
120
|
assert last_response.ok?
|
115
121
|
assert_equal "http://example.org#{@locations[:posts_path]}", last_request.url
|
116
122
|
end
|
117
123
|
|
118
|
-
path = "
|
124
|
+
path = app.posts_path "/#{@date.to_s.gsub('-','/')}/post-permalink"
|
119
125
|
get path do |response|
|
120
126
|
assert response.ok?
|
121
127
|
assert_equal "http://example.org#{path}", last_request.url
|
@@ -131,19 +137,19 @@ class TestMapping < Test::Unit::TestCase
|
|
131
137
|
end
|
132
138
|
|
133
139
|
def test_should_return_ok_in_archive_path
|
134
|
-
get
|
140
|
+
get app.archive_path do |response|
|
135
141
|
assert response.ok?
|
136
142
|
assert_equal "http://example.org#{@locations[:archive_path]}", last_request.url
|
137
143
|
assert_equal "Archive articles:#{@locations[:archive_path]}", response.body
|
138
144
|
end
|
139
145
|
|
140
|
-
get "
|
146
|
+
get app.archive_path "/" do
|
141
147
|
follow_redirect!
|
142
148
|
assert last_response.ok?
|
143
149
|
assert_equal "http://example.org#{@locations[:archive_path]}", last_request.url
|
144
150
|
end
|
145
151
|
|
146
|
-
path = "
|
152
|
+
path = app.archive_path "/#{@date.to_s.gsub('-','/')}/post-permalink"
|
147
153
|
get path do |response|
|
148
154
|
assert response.ok?
|
149
155
|
assert_equal "http://example.org#{path}", last_request.url
|
@@ -159,17 +165,26 @@ class TestMapping < Test::Unit::TestCase
|
|
159
165
|
end
|
160
166
|
|
161
167
|
def test_should_return_ok_in_about_path
|
162
|
-
get
|
168
|
+
get app.about_path do |response|
|
163
169
|
assert response.ok?
|
164
170
|
assert_equal "http://example.org#{@locations[:about_path]}", last_request.url
|
165
171
|
assert_equal "About:#{@locations[:about_path]}", response.body
|
166
172
|
end
|
167
173
|
|
168
|
-
get "
|
174
|
+
get app.about_path "/" do
|
169
175
|
follow_redirect!
|
170
176
|
assert last_response.ok?
|
171
177
|
assert_equal "http://example.org#{@locations[:about_path]}", last_request.url
|
172
178
|
end
|
173
179
|
end
|
180
|
+
|
181
|
+
def test_should_return_ok_in_search_path
|
182
|
+
get "#{app.search_path}?keywords=ruby" do |response|
|
183
|
+
assert response.ok?
|
184
|
+
assert_equal "http://example.org#{@locations[:search_path]}?keywords=ruby", last_request.url
|
185
|
+
assert_equal "Find articles:#{@locations[:search_path]}?keywords=ruby", response.body
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
174
189
|
end
|
175
190
|
|