Skip to content

Commit 70eb5e2

Browse files
author
Michael Bleigh
committed
Alias 'segment' to namespace as well, allows for description of nested resources.
1 parent 0893a3a commit 70eb5e2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/grape/api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def namespace(space = nil, &block)
256256
alias_method :group, :namespace
257257
alias_method :resource, :namespace
258258
alias_method :resources, :namespace
259+
alias_method :segment, :namespace
259260

260261
# Create a scope without affecting the URL.
261262
#

spec/grape/api_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ def app; subject end
134134
end
135135
subject.namespace.should == '/'
136136
end
137+
138+
it 'should accept path segments correctly' do
139+
subject.namespace :members do
140+
namespace "/:member_id" do
141+
namespace.should == '/members/:member_id'
142+
get '/' do
143+
params[:member_id]
144+
end
145+
end
146+
end
147+
get '/members/23'
148+
last_response.body.should == "23"
149+
end
137150

138151
it 'should be callable with nil just to push onto the stack' do
139152
subject.namespace do
@@ -143,7 +156,7 @@ def app; subject end
143156
subject.send(:compile_path, 'hello').should == '/hello(.:format)'
144157
end
145158

146-
%w(group resource resources).each do |als|
159+
%w(group resource resources segment).each do |als|
147160
it "`.#{als}` should be an alias" do
148161
subject.send(als, :awesome) do
149162
namespace.should == "/awesome"

0 commit comments

Comments
 (0)