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 reloading when extending the apidoc from concern #557

Merged
merged 1 commit into from
Sep 7, 2017
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
16 changes: 8 additions & 8 deletions lib/apipie/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def define_resource_description(controller, version, dsl_data = nil)
# resource_description? It's used to derivate the default value of
# versions for methods.
def controller_versions(controller)
ret = @controller_versions[controller]
ret = @controller_versions[controller.to_s]
return ret unless ret.empty?
if controller == ActionController::Base || controller.nil?
return [Apipie.configuration.default_version]
Expand All @@ -131,7 +131,7 @@ def controller_versions(controller)
end

def set_controller_versions(controller, versions)
@controller_versions[controller] = versions
@controller_versions[controller.to_s] = versions
end

def add_param_group(controller, name, &block)
Expand Down Expand Up @@ -205,7 +205,7 @@ def get_resource_description(resource, version = nil)
return nil
end
resource_description = get_resource_description(resource_name)
if resource_description && resource_description.controller == resource
if resource_description && resource_description.controller.to_s == resource.to_s
return resource_description
end
end
Expand Down Expand Up @@ -236,12 +236,12 @@ def remove_method_description(resource, versions, method_name)

# initialize variables for gathering dsl data
def init_env
@resource_descriptions = HashWithIndifferentAccess.new { |h, version| h[version] = {} }
@controller_to_resource_id = {}
@param_groups = {}
@resource_descriptions ||= HashWithIndifferentAccess.new { |h, version| h[version] = {} }
@controller_to_resource_id ||= {}
@param_groups ||= {}

# what versions does the controller belong in (specified by resource_description)?
@controller_versions = Hash.new { |h, controller| h[controller] = [] }
@controller_versions ||= Hash.new { |h, controller| h[controller.to_s] = [] }
end

def recorded_examples
Expand Down Expand Up @@ -385,7 +385,7 @@ def valid_search_args?(version, resource_name, method_name)
end

def version_prefix(klass)
version = controller_versions(klass).first
version = controller_versions(klass.to_s).first
base_url = get_base_url(version)
return "/" if base_url.blank?
base_url[1..-1] + "/"
Expand Down
2 changes: 0 additions & 2 deletions spec/dummy/app/controllers/extended_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ class ExtendedController < ApplicationController
end
def create
end

include Concerns::ExtendingConcern
end
4 changes: 4 additions & 0 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ class Application < Rails::Application

# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]

config.to_prepare do
ExtendedController.send(:include, Concerns::ExtendingConcern)
end
end
end
2 changes: 2 additions & 0 deletions spec/dummy/config/initializers/apipie.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Apipie.configure do |config|
config.app_name = "Test app"
config.copyright = "&copy; 2012 Pavel Pokorny"
config.languages = ['en']
config.default_locale = 'en'

# set default API version
# can be overriden in resource_description
Expand Down