When running requests with disable_rails_query_string_format
with such query params:
query: {selected_ids: [1,2,3]}
It works fine when running the code in the app, but when running specs, the url become truncated and only last element of the array is taken, so that url become selected_ids=3
instead of selected_ids=1&selected_ids=2&selected_ids=3
.
Don't know if that matter, but additionally we use Webmock to stub requests inside specs.
Maybe someone ran the same issue and know what may cause it?
Update, code abstraction
Let's say, here's a service called Client:
class Client
include HTTParty
SOME_ENDPOINT = 'http://someurl.com/some-endpoint'.freeze
def do_get(options = {})
self.class.disable_rails_query_string_format
self.class.get(SOME_ENDPOINT, options)
end
end
And at some point it gets executed, let's say, by some action performed by controller, which delegates execution to resource and resource executes that service:
# Somewhere in resource
Client.new.do_get(selected_ids: [1, 2, 3])
When the code above gets executed in non-test environment, Client
makes a correct call to http://someurl.com/some-endpoint?selected_ids=1&selected_ids=2&selected_ids=3
But under specs, when doing the same thing without stub_request
, Webmock error got raised indicating the unmocked url, which is incorrect: http://someurl.com/some-endpoint?selected_ids=3
Generally, spec is not doing some extra steps and looks like standard RSpec specs:
describe Client
subject { Client.new.do_get(selected_ids: [1, 2, 3]) }
it
subject
end
end
# -> Webmock error - unregistered request to
# http://someurl.com/some-endpoint?selected_ids=3,
# but it should be to
# http://someurl.com/some-endpoint?selected_ids=1&selected_ids=2&selected_ids=3