Skip to content

Commit 98e6516

Browse files
committed
fix Helpers modified given helper module
1 parent 7c98ebb commit 98e6516

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* [#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).
1414
* [#1330](https://github.com/ruby-grape/grape/pull/1330): Add `register` keyword for adding customized parsers and formatters - [@namusyaka](https://github.com/namusyaka).
1515
* [#1336](https://github.com/ruby-grape/grape/pull/1336): Do not modify Hash argument to `error!` - [@tjwp](https://github.com/tjwp).
16+
* [#1338](https://github.com/ruby-grape/grape/pull/1338): Fix helpers method modified given helper module - [@vsorlov](https://github.com/vsorlov).
1617

1718
0.15.0 (3/8/2016)
1819
=================

lib/grape/dsl/helpers.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,21 @@ module ClassMethods
2727
# end
2828
#
2929
def helpers(new_mod = nil, &block)
30+
mod = Module.new
3031
if block_given? || new_mod
31-
mod = new_mod || Module.new
32+
if new_mod
33+
define_boolean_in_mod new_mod
34+
inject_api_helpers_to_mod new_mod
35+
mod.send :include, new_mod
36+
end
37+
3238
define_boolean_in_mod(mod)
33-
inject_api_helpers_to_mod(mod) if new_mod
3439
inject_api_helpers_to_mod(mod) do
3540
mod.class_eval(&block)
3641
end if block_given?
3742

3843
namespace_stackable(:helpers, mod)
3944
else
40-
mod = Module.new
4145
namespace_stackable(:helpers).each do |mod_to_include|
4246
mod.send :include, mod_to_include
4347
end

spec/grape/dsl/helpers_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def test
4646
expect(subject).to receive(:namespace_stackable).with(:helpers).and_call_original
4747
subject.helpers(mod, &proc)
4848

49-
expect(subject.mod).to eq mod
49+
expect(mod.instance_methods).not_to include :test
50+
expect(subject.mod.instance_methods).to include :test
5051
end
5152

5253
context 'with an external file' do

0 commit comments

Comments
 (0)