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 error climbing controller hierarchy #875

Merged
merged 1 commit into from
May 29, 2023
Merged
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
2 changes: 1 addition & 1 deletion lib/apipie/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def valid_search_args?(version, resource_id, method_name)
end

def version_prefix(klass)
version = controller_versions(klass.to_s).first
version = controller_versions(klass).first
base_url = get_base_url(version)
return "/" if base_url.blank?
base_url[1..-1] + "/"
Expand Down
4 changes: 3 additions & 1 deletion lib/apipie/resource_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def doc_url
Apipie.full_url crumbs.join('/')
end

def api_url; "#{Apipie.api_base_url(_version)}#{@_path}"; end
def api_url
"#{Apipie.api_base_url(_version)}#{@_path}"
end

def valid_method_name?(method_name)
@_methods.keys.map(&:to_s).include?(method_name.to_s)
Expand Down
23 changes: 23 additions & 0 deletions spec/controllers/api/v2/empty_middle_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe Api::V2::EmptyMiddleController do
let(:resource_description) { Apipie.get_resource_description(described_class, '2.0') }

describe 'resource description' do
subject { resource_description }

context 'when namespaced resources are enabled' do
before { Apipie.configuration.namespaced_resources = true }
after { Apipie.configuration.namespaced_resources = false }

# we don't actually expect the resource description to be nil, but resource IDs
# are computed at file load time, and altering the value of namespaced_resources
# after the fact doesn't change the resource ID, so it can't be found
it { is_expected.to be_nil }
end

context 'when namespaced resources are disabled' do
it { is_expected.to be_nil }
end
end
end
5 changes: 5 additions & 0 deletions spec/dummy/app/controllers/api/v2/empty_middle_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ class EmptyMiddleController < V2::BaseController
# This is an empty controller, used to test cases where controllers
# may inherit from a middle controler that does not define a resource_description,
# but the middle controller's parent does.

def inconsequential_method
# This method is here to ensure that the controller is not empty.
# It triggers method_added, which is used to add the resource description.
end
end
end
end