Fix /uploads?search[uploader_name] not filtering by uploader name.
Caused by `relation = self` in `search_post_id_attribute`.
This commit is contained in:
@@ -75,7 +75,7 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search_attributes(params, *attributes)
|
def search_attributes(params, *attributes)
|
||||||
attributes.reduce(self) do |relation, attribute|
|
attributes.reduce(all) do |relation, attribute|
|
||||||
relation.search_attribute(attribute, params)
|
relation.search_attribute(attribute, params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -136,7 +136,7 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search_post_id_attribute(params)
|
def search_post_id_attribute(params)
|
||||||
relation = self
|
relation = all
|
||||||
|
|
||||||
if params[:post_id].present?
|
if params[:post_id].present?
|
||||||
relation = relation.search_attribute(:post_id, params)
|
relation = relation.search_attribute(:post_id, params)
|
||||||
@@ -174,7 +174,7 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
def search(params = {})
|
def search(params = {})
|
||||||
params ||= {}
|
params ||= {}
|
||||||
|
|
||||||
default_attributes = (attribute_names & %w[id created_at updated_at])
|
default_attributes = (attribute_names.map(&:to_sym) & %i[id created_at updated_at])
|
||||||
search_attributes(params, *default_attributes)
|
search_attributes(params, *default_attributes)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
setup do
|
setup do
|
||||||
as_user do
|
as_user do
|
||||||
@upload = create(:source_upload, tag_string: "foo bar")
|
@upload = create(:source_upload, tag_string: "foo bar")
|
||||||
|
@upload2 = create(:source_upload, tag_string: "tagme", rating: "e")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -151,14 +152,16 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
uploader_name: @upload.uploader.name,
|
uploader_name: @upload.uploader.name,
|
||||||
source_matches: @upload.source,
|
source_matches: @upload.source,
|
||||||
rating: @upload.rating,
|
rating: @upload.rating,
|
||||||
has_post: "yes",
|
|
||||||
post_tags_match: @upload.tag_string,
|
|
||||||
status: @upload.status,
|
status: @upload.status,
|
||||||
server: @upload.server,
|
server: @upload.server,
|
||||||
}
|
}
|
||||||
|
|
||||||
get uploads_path, params: { search: search_params }
|
get uploads_path, params: { search: search_params }
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|
||||||
|
get uploads_path(format: :json), params: { search: search_params }
|
||||||
|
assert_response :success
|
||||||
|
assert_equal(@upload.id, response.parsed_body.first["id"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user