From d5ee1aa46c22e0b0af9310778c9b5aeee04a5fa0 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Thu, 27 Jan 2022 20:30:38 +0100 Subject: [PATCH] Add Pagy support Pagy calls `count` on collections with `:all` as parameter. This changes ensures that non hash parameters will be discarded --- lib/hawk/model/finder.rb | 1 + spec/collections_spec.rb | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/hawk/model/finder.rb b/lib/hawk/model/finder.rb index 6a042f8..44c3d43 100644 --- a/lib/hawk/model/finder.rb +++ b/lib/hawk/model/finder.rb @@ -40,6 +40,7 @@ def all(params = {}) end def count(params = {}) + params = {} unless params.is_a?(Hash) path = path_for(count_path, params) method = connection.url_length(path,:get,params) > 2000 ? :post : :get repr = connection.send(method, path, params) diff --git a/spec/collections_spec.rb b/spec/collections_spec.rb index d1a0fbd..01d43fd 100644 --- a/spec/collections_spec.rb +++ b/spec/collections_spec.rb @@ -52,12 +52,20 @@ class Mosquito < Hawk::Model::Base end describe '.count' do - specify do + before do stub_request(:GET, "http://zombo.com/mosquitos/count"). with(:headers => {'User-Agent'=>'Foobar'}). to_return(:status => 200, :body => {count: 123}.to_json, :headers => {}) + end + specify do expect(Mosquito.count).to eq(123) end + + context 'when parameter is not a hash' do + specify do + expect { Mosquito.count(:all) }.not_to raise_error + end + end end end