Skip to content

Commit

Permalink
fixes #186: helpers should allow multiple calls with modules and blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Padron committed Jun 29, 2012
1 parent db4f5ad commit 9018102
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/grape/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,14 @@ def represent(model_class, options)
# end
# end
# end
def helpers(mod = nil, &block)
if block_given? || mod
mod ||= settings.peek[:helpers] || Module.new
def helpers(new_mod = nil, &block)
if block_given? || new_mod
mod = settings.peek[:helpers] || Module.new
if new_mod
mod.class_eval do
include new_mod
end
end
mod.class_eval &block if block_given?
set(:helpers, mod)
else
Expand Down
22 changes: 22 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,28 @@ def hello
get '/howdy'
last_response.body.should eql 'Hello, world.'
end

it 'should allow multiple calls with modules and blocks' do
subject.helpers Module.new do
def one
1
end
end
subject.helpers Module.new do
def two
2
end
end
subject.helpers do
def three
3
end
end
subject.get 'howdy' do
[one, two, three]
end
lambda{get '/howdy'}.should_not raise_error
end
end

describe '.scope' do
Expand Down

0 comments on commit 9018102

Please sign in to comment.