Fix /uploads?search[uploader_name] not filtering by uploader name.

Caused by `relation = self` in `search_post_id_attribute`.
This commit is contained in:
evazion
2019-09-02 19:53:47 -05:00
parent 5df3b01ca2
commit 1e0aadb6e7
2 changed files with 8 additions and 5 deletions

View File

@@ -75,7 +75,7 @@ class ApplicationRecord < ActiveRecord::Base
end
def search_attributes(params, *attributes)
attributes.reduce(self) do |relation, attribute|
attributes.reduce(all) do |relation, attribute|
relation.search_attribute(attribute, params)
end
end
@@ -136,7 +136,7 @@ class ApplicationRecord < ActiveRecord::Base
end
def search_post_id_attribute(params)
relation = self
relation = all
if params[:post_id].present?
relation = relation.search_attribute(:post_id, params)
@@ -174,7 +174,7 @@ class ApplicationRecord < ActiveRecord::Base
def search(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)
end
end

View File

@@ -137,6 +137,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
setup do
as_user do
@upload = create(:source_upload, tag_string: "foo bar")
@upload2 = create(:source_upload, tag_string: "tagme", rating: "e")
end
end
@@ -151,14 +152,16 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
uploader_name: @upload.uploader.name,
source_matches: @upload.source,
rating: @upload.rating,
has_post: "yes",
post_tags_match: @upload.tag_string,
status: @upload.status,
server: @upload.server,
}
get uploads_path, params: { search: search_params }
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