-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Still having issues with helper inheritance #1820
Comments
Try to turn this into a spec? |
Just want to confirm I am seeing this as well. If I have a bit to spare I'll try to write a spec. But basically any |
I went to upgrade today and before (in 1.0~) I had
And the helper would be picked up by all of the mounts, but now that doesn't seem to be the case. The sub-mounts can't seem to find the helpers. If this is just something I'm missing from the upgrade on my end that could help you. But maybe it just broke because of the change in how Grape mounts works with the new |
Have you upgraded to |
On my test - this seems to fail to load
|
Any news on that? I'm also running into that issue. :( |
I had this issue today. I thought that something like this would work, but it didn't: class Base < Grape::API
helpers do
def helper_from_base = 'helper from base'
end
end
class A < Base
helpers do
def helper_from_a = 'helper from A'
end
end
class B < A
helpers do
def helper_from_b = 'helper from B'
end
get '/test' do
{
helper_from_base: respond_to?(:helper_from_base),
helper_from_a: respond_to?(:helper_from_a),
helper_from_b: respond_to?(:helper_from_b),
}
end
end
class Root < Grape::API
format :json
mount A
mount B
end
# response from /test:
# {
# "helper_from_base": false,
# "helper_from_a": false,
# "helper_from_b": true
# } It is possible to workaround this problem by using the class Base < Grape::API
def self.inherited(subclass)
super
subclass.helpers do
def helper_from_base = 'helper from base'
end
end
end
class A < Base
def self.inherited(subclass)
super
subclass.helpers do
def helper_from_a = 'helper from A'
end
end
end
class B < A
helpers do
def helper_from_b = 'helper from B'
end
get '/test' do
{
helper_from_base: respond_to?(:helper_from_base),
helper_from_a: respond_to?(:helper_from_a),
helper_from_b: respond_to?(:helper_from_b),
}
end
end
class Root < Grape::API
format :json
mount A
mount B
end
# response from /test:
# {
# "helper_from_base": true,
# "helper_from_a": true,
# "helper_from_b": true
# } |
Still looking for someone to pickup this issue and write some (failing) specs to start! |
I started writing a failing spec here: lenon@ceb2767 The spec that I added fails as expected but it also causes another test to fail (
|
Thanks for the repro! I bet |
I spent some time debugging this, here's my notes of what I found so far:
grape/lib/grape/util/inheritable_setting.rb Lines 48 to 59 in 3f01d03
In this line
This causes a side effect in the
I'll get back to this when I have some free time. |
I thought this was supposed to be fixed with #1665, but I am still having issues with it. I have a few classes inheriting from Grape::API and I want to avoid having to include the helpers in every endpoint class:
However, when I go to make my end point class inherit, I can't use the AuthenticationHelper methods like
current_user
, for example.Is this intended? What am I missing?
The text was updated successfully, but these errors were encountered: