From 9d256d4da2d46b64ce0d2e808c4839a571951ae7 Mon Sep 17 00:00:00 2001 From: Jens Balvig Date: Mon, 19 Apr 2021 15:37:18 +0900 Subject: [PATCH] fix params with stringified keys that are part of the URL getting appended to query (#119) --- lib/spyke/relation.rb | 6 +++++- lib/spyke/version.rb | 2 +- test/scopes_test.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/spyke/relation.rb b/lib/spyke/relation.rb index cebdf67..8e3b340 100644 --- a/lib/spyke/relation.rb +++ b/lib/spyke/relation.rb @@ -5,7 +5,7 @@ class Relation include Enumerable attr_reader :klass - attr_accessor :params + attr_reader :params delegate :to_ary, :[], :any?, :empty?, :last, :size, :metadata, to: :find_some def initialize(klass, options = {}) @@ -21,6 +21,10 @@ def where(conditions = {}) relation end + def params=(params) + @params = params.symbolize_keys + end + def with(uri) if uri.is_a? Symbol @options[:uri] = File.join @options[:uri], uri.to_s diff --git a/lib/spyke/version.rb b/lib/spyke/version.rb index 14ce450..4cb12d8 100644 --- a/lib/spyke/version.rb +++ b/lib/spyke/version.rb @@ -1,3 +1,3 @@ module Spyke - VERSION = '5.4.2' + VERSION = '5.4.3' end diff --git a/test/scopes_test.rb b/test/scopes_test.rb index a4211d8..4e1a716 100644 --- a/test/scopes_test.rb +++ b/test/scopes_test.rb @@ -61,6 +61,14 @@ def test_chainable_where assert_requested endpoint end + def test_where_with_stringified_keys + endpoint = stub_request(:get, 'http://sushi.com/recipes/1/image') + + RecipeImage.where("recipe_id" => 1).to_a + + assert_requested endpoint + end + def test_chainable_class_method endpoint = stub_request(:get, 'http://sushi.com/recipes?status=published&per_page=3')