-
Notifications
You must be signed in to change notification settings - Fork 568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request with query containing array is incorrectly altered #764
Comments
@weppos thank you for reporting the issue. Could you please let me know what is the issue you are experiencing as a side effect of that behaviour of the request registry? Is that lack of precision when matching executed request or that they don't match at all? Request registry stores normalized query params. There are different ways that query params, representing an array can be serialized. There is no RFC standard that defines that. WebMock had to choose one. Saying above, perhaps WebMock should offer some way persisting the original url and allowing matching requests with request pattern, only when url string is exactly the same. |
@bblimke the issue manifests in an expectation failure:
|
@aeden does it help if you set |
I tried setting this directly before the expectation call, but it does not appear to have an impact. The expectation still fails the same way as before. |
@aeden thanks. Does it match if you change the query params to "street"=>["1234 SW 1st Street", "Apt 3"]? |
If I remove the |
Looks like I am also affected by this issue. |
Hello, I got a similar issue with query and array: Failures:
When I create the query I am using: WebMock::Config.instance.query_values_notation = :flat_array Seems to fix it, I guess the issue is somewhere in the deep array encoding/decoding |
I will chime in and bump this issue. I'm query Gmail API, you can fetch message with format |
@surkova could you please provide an example? Is there a problem with matching query or headers in your case? |
@bblimke I have a screenshot illustrating the problem. I took it while in the debugger navigating inside # Note that only the last value of metadataHeaders is enough to make a match.
query_string = "?fields=sizeEstimate,id,payload&format=metadata&metadataHeaders=Reply-To"aUser=#{@account.id}"
url += query_string
stub_request(:get, url).to_return(
status: 200,
body: fixture,
headers: {
'Content-Type' => 'application/json',
}
) The request in my case is generated by https://github.com/googleapis/google-api-ruby-client and it sends |
@surkova thank you for clarifying. have you tried setting |
@bblimke I just tried this, it worked: url = "https://www.googleapis.com/gmail/v1/users/#{google_user_id}/messages/#{message_id}"
WebMock::Config.instance.query_values_notation = :flat_array
query_string = "fields=sizeEstimate,id,payload&format=metadata&metadataHeaders=From&metadataHeaders=Reply-To"aUser=#{@account.id}"
stub_request(:get, url).with(query: query_string).to_return(
status: 200,
body: fixture,
headers: {
'Content-Type' => 'application/json',
}
) I haven't found any examples on how to specify query as an actual array of tuples, only this test case. I'd assume I'd need to loop and join array elements myself. Thank you for pointing out this solution. I'd assume that keeping repeated query params is the default behavior. |
@surkova I agree it's confusing. It should be at least mentioned in README. |
In this test case the config is changed for all tests in the context. Would it be possible to change config directly on |
@surkova it's not possible. I think it will also be a pain to know when to use flat array and when not to, therefore it would be better to either allow WebMock to do that automatically or find a way to avid various notations completely. |
@bblimke we noticed random test failures when I introduced My expectation from the library would be the following: the library should always assume there can be duplicate keys in the query string if query is supplied as an array of tuples or a string and handles that on the fly without adding any particular settings in the config. |
I agree. The reason is the representation of query parameters as a hash, same limitation as e.g Rails has when it comes to parameters handling. It's unlikely this is going to get fixed soon, unless someone will be willing to spend time on rebuilding this part of WebMock. |
I have a test that is failing because the expectation can't be properly verified. The request has a query that contains a value with an indexed array:
Basically the parameter street is passed as it follows:
However, when the request is stored in the registry, it is altered and the values 0 and 1 in
street[X]
are stripped and replaced with simplystreet[]
.This is the portion of code where the issue happens:
specifically, the bug is caused by
query_to_values
andvalues_to_query
:It should be
The text was updated successfully, but these errors were encountered: