diff --git a/app/models/application_record.rb b/app/models/application_record.rb index f4862fc75..28158b141 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -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 diff --git a/test/functional/uploads_controller_test.rb b/test/functional/uploads_controller_test.rb index 9c33de184..6840684f1 100644 --- a/test/functional/uploads_controller_test.rb +++ b/test/functional/uploads_controller_test.rb @@ -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