Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Grape helpers modified given helper module #1338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [#1326](https://github.com/ruby-grape/grape/pull/1326): Fix wrong behavior for OPTIONS and HEAD requests with catch-all - [@ekampp](https://github.com/ekampp), [@namusyaka](https://github.com/namusyaka).
* [#1330](https://github.com/ruby-grape/grape/pull/1330): Add `register` keyword for adding customized parsers and formatters - [@namusyaka](https://github.com/namusyaka).
* [#1336](https://github.com/ruby-grape/grape/pull/1336): Do not modify Hash argument to `error!` - [@tjwp](https://github.com/tjwp).
* [#1338](https://github.com/ruby-grape/grape/pull/1338): Fix helpers method modified given helper module - [@vsorlov](https://github.com/vsorlov).

0.15.0 (3/8/2016)
=================
Expand Down
10 changes: 7 additions & 3 deletions lib/grape/dsl/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@ module ClassMethods
# end
#
def helpers(new_mod = nil, &block)
mod = Module.new
if block_given? || new_mod
mod = new_mod || Module.new
if new_mod
define_boolean_in_mod new_mod
inject_api_helpers_to_mod new_mod
mod.send :include, new_mod
end

define_boolean_in_mod(mod)
inject_api_helpers_to_mod(mod) if new_mod
inject_api_helpers_to_mod(mod) do
mod.class_eval(&block)
end if block_given?

namespace_stackable(:helpers, mod)
else
mod = Module.new
namespace_stackable(:helpers).each do |mod_to_include|
mod.send :include, mod_to_include
end
Expand Down
3 changes: 2 additions & 1 deletion spec/grape/dsl/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def test
expect(subject).to receive(:namespace_stackable).with(:helpers).and_call_original
subject.helpers(mod, &proc)

expect(subject.mod).to eq mod
expect(mod.instance_methods).not_to include :test
expect(subject.mod.instance_methods).to include :test
end

context 'with an external file' do
Expand Down