Fix #4240: only=… param malfunctioning on autocomplete API.
This commit is contained in:
@@ -17,7 +17,7 @@ class ApplicationResponder < ActionController::Responder
|
|||||||
options[:root] ||= resource.table_name.dasherize if resource.respond_to?(:table_name)
|
options[:root] ||= resource.table_name.dasherize if resource.respond_to?(:table_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
options[:only] ||= params["only"].scan(/\w+/).map(&:to_sym) if params["only"]
|
options[:only] ||= params["only"].scan(/\w+/) if params["only"]
|
||||||
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -294,6 +294,8 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
options[:include] ||= []
|
options[:include] ||= []
|
||||||
options[:methods] ||= []
|
options[:methods] ||= []
|
||||||
|
|
||||||
|
options[:only] = options[:only].map(&:to_sym)
|
||||||
|
|
||||||
attributes, methods = api_attributes.partition { |attr| has_attribute?(attr) }
|
attributes, methods = api_attributes.partition { |attr| has_attribute?(attr) }
|
||||||
methods += options[:methods]
|
methods += options[:methods]
|
||||||
includes = options[:include]
|
includes = options[:include]
|
||||||
|
|||||||
@@ -49,6 +49,13 @@ class TagsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
get autocomplete_tags_path, params: { search: { name_matches: "t" }, format: :json }
|
get autocomplete_tags_path, params: { search: { name_matches: "t" }, format: :json }
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "show action" do
|
context "show action" do
|
||||||
|
|||||||
Reference in New Issue
Block a user