diff --git a/CHANGELOG.md b/CHANGELOG.md index ad0ceba6a..9262b118b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) ================= diff --git a/lib/grape/dsl/helpers.rb b/lib/grape/dsl/helpers.rb index 2c8f4ea5b..c7e7c8bbf 100644 --- a/lib/grape/dsl/helpers.rb +++ b/lib/grape/dsl/helpers.rb @@ -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 diff --git a/spec/grape/dsl/helpers_spec.rb b/spec/grape/dsl/helpers_spec.rb index 861114088..bc214b38f 100644 --- a/spec/grape/dsl/helpers_spec.rb +++ b/spec/grape/dsl/helpers_spec.rb @@ -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