Merge pull request #13587 from mkllnk/json-response

Clean up request specs testing JSON
This commit is contained in:
David Cook
2025-10-13 14:24:26 +11:00
committed by GitHub
2 changed files with 3 additions and 17 deletions

View File

@@ -19,6 +19,8 @@ RSpec.describe "Customers", swagger_doc: "v1.yaml", feature: :api_v1 do
}
let!(:customer2) { create(:customer, enterprise: enterprise1, created_manually: true,) }
let!(:customer3) { create(:customer, enterprise: enterprise2, created_manually: true,) }
let(:json_response_ids) { json_response[:data]&.pluck(:id) }
let(:json_error_detail) { json_response[:errors][0][:detail] }
before do
login_as enterprise1.owner

View File

@@ -3,23 +3,7 @@
module OpenFoodNetwork
module ApiHelper
def json_response
json_response = JSON.parse(response.body)
case json_response
when Hash
json_response.with_indifferent_access
when Array
json_response.map(&:with_indifferent_access)
else
json_response
end
end
def json_response_ids
json_response[:data]&.pluck(:id)
end
def json_error_detail
json_response[:errors][0][:detail]
response.parsed_body
end
def assert_unauthorized!