From 75fc35574ecfca1516814f335314ce0e5fb115b2 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 15 Feb 2022 13:03:55 +1100 Subject: [PATCH] Make json_response test helper deal with error response It raised an error: NoMethodError: undefined method `map' for nil:NilClass --- spec/requests/api/v1/customers_spec.rb | 9 +++++++++ spec/support/api_helper.rb | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/requests/api/v1/customers_spec.rb b/spec/requests/api/v1/customers_spec.rb index 59c4de7ec2..de80b87901 100644 --- a/spec/requests/api/v1/customers_spec.rb +++ b/spec/requests/api/v1/customers_spec.rb @@ -71,6 +71,15 @@ describe "Customers", type: :request do end end + describe "pagination" do + it "renders the first page" do + pending "pagination logic compares string with integer" + + get "/api/v1/customers", params: { page: "1" } + expect(json_response_ids).to eq [customer1.id.to_s, customer2.id.to_s] + end + end + post "Create customer" do tags "Customers" consumes "application/json" diff --git a/spec/support/api_helper.rb b/spec/support/api_helper.rb index d4591ece3d..37d1d6a4d1 100644 --- a/spec/support/api_helper.rb +++ b/spec/support/api_helper.rb @@ -15,7 +15,7 @@ module OpenFoodNetwork end def json_response_ids - json_response[:data].map{ |item| item["id"] } + json_response[:data]&.map{ |item| item["id"] } end def json_error_detail