Fix #4240: only=… param malfunctioning on autocomplete API.

This commit is contained in:
evazion
2020-01-07 00:01:14 -06:00
parent 45f2530537
commit 3312030ce3
3 changed files with 10 additions and 1 deletions

View File

@@ -17,7 +17,7 @@ class ApplicationResponder < ActionController::Responder
options[:root] ||= resource.table_name.dasherize if resource.respond_to?(:table_name)
end
options[:only] ||= params["only"].scan(/\w+/).map(&:to_sym) if params["only"]
options[:only] ||= params["only"].scan(/\w+/) if params["only"]
super
end

View File

@@ -294,6 +294,8 @@ class ApplicationRecord < ActiveRecord::Base
options[:include] ||= []
options[:methods] ||= []
options[:only] = options[:only].map(&:to_sym)
attributes, methods = api_attributes.partition { |attr| has_attribute?(attr) }
methods += options[:methods]
includes = options[:include]

View File

@@ -49,6 +49,13 @@ class TagsControllerTest < ActionDispatch::IntegrationTest
get autocomplete_tags_path, params: { search: { name_matches: "t" }, format: :json }
assert_response :success
end
should "respect the only param" do
get autocomplete_tags_path, params: { search: { name_matches: "t", only: "name" }, format: :json }
assert_response :success
assert_equal "touhou", response.parsed_body.first["name"]
end
end
context "show action" do