From 1ee2d22b97002298cf5ae430fbad744c38228443 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 25 Aug 2022 21:28:21 -0500 Subject: [PATCH] Fix #5184: undefined method `to_model' for []:Array searching for IQDB queries with JSON. --- app/controllers/iqdb_queries_controller.rb | 2 +- test/functional/iqdb_queries_controller_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/iqdb_queries_controller.rb b/app/controllers/iqdb_queries_controller.rb index 9e77438cf..1b73fcf28 100644 --- a/app/controllers/iqdb_queries_controller.rb +++ b/app/controllers/iqdb_queries_controller.rb @@ -9,7 +9,7 @@ class IqdbQueriesController < ApplicationController iqdb_params = search_params.to_h.symbolize_keys @high_similarity_matches, @low_similarity_matches, @matches = IqdbClient.new.search(**iqdb_params) - respond_with(@matches, template: "iqdb_queries/show") + respond_with(@matches, template: "iqdb_queries/show", location: iqdb_queries_path) end alias create show diff --git a/test/functional/iqdb_queries_controller_test.rb b/test/functional/iqdb_queries_controller_test.rb index f10a70c07..c91d51dc5 100644 --- a/test/functional/iqdb_queries_controller_test.rb +++ b/test/functional/iqdb_queries_controller_test.rb @@ -35,6 +35,19 @@ class IqdbQueriesControllerTest < ActionDispatch::IntegrationTest assert_select("#post_#{@post.id}") end end + + context "with a file parameter" do + should "render a response" do + @matches = [{ post_id: @post.id, score: 95.0 }] + mock_iqdb_matches(@matches) + + file = Rack::Test::UploadedFile.new("test/files/test.jpg") + post_auth iqdb_queries_path(format: :json), @user, params: { search: { file: file }} + + assert_response :success + assert_equal([{ post_id: @post.id, score: 95.0, post: as(@user) { @post.as_json } }.with_indifferent_access], response.parsed_body) + end + end end end end