Skip to content

Commit 6aa3282

Browse files
dandehavillanddblock
authored andcommitted
Fix const errors being hidden by bug in const_missing (ruby-grape#1876)
1 parent 51217ea commit 6aa3282

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#### Fixes
1010

1111
* [#1868](https://github.com/ruby-grape/grape/pull/1868): Fix NoMethodError with none hash params - [@ksss](https://github.com/ksss).
12+
* [#1876](https://github.com/ruby-grape/grape/pull/1876): Fix const errors being hidden by bug in `const_missing` - [@dandehavilland](https://github.com/dandehavilland).
1213

1314
### 1.2.3 (2019/01/16)
1415

lib/grape/api.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ def api.inherited(child_api)
6464
def const_missing(*args)
6565
if base_instance.const_defined?(*args)
6666
base_instance.const_get(*args)
67-
elsif parent && parent.const_defined?(*args)
68-
parent.const_get(*args)
6967
else
7068
super
7169
end

spec/grape/api_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,4 +3869,21 @@ def before
38693869
expect(grape_api.eql?(MyAPI))
38703870
end
38713871
end
3872+
3873+
describe 'const_missing' do
3874+
subject(:grape_api) { Class.new(Grape::API) }
3875+
let(:mounted) do
3876+
Class.new(Grape::API) do
3877+
get '/missing' do
3878+
SomeRandomConstant
3879+
end
3880+
end
3881+
end
3882+
3883+
before { subject.mount mounted => '/const' }
3884+
3885+
it 'raises an error' do
3886+
expect { get '/const/missing' }.to raise_error(NameError).with_message(/SomeRandomConstant/)
3887+
end
3888+
end
38723889
end

0 commit comments

Comments
 (0)