[Enhancement] Allows HttpMock to ignore query params from url path if given the option #395
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Recently, I encountered an issue where date-time values within query parameters were not accurately detected and parsed, leading to inaccuracies in the mocks I had. I had to either change the business logic to not use date-time values in query parameters, or to change the way the date-time values were parsed. For me, the former was not an option, so I had to change the way the date-time values were parsed.
Currently ActiveResource::HttpMock does not provide a way to omit the query parameters from the URL when matching a request, while I understand that this is probably not a common use case since it will lead to a lot of issues when the mocked URL is not specific enough, I still think it would be useful to have the option to omit the query parameters from the URL when matching a request.
In this PR I have added a
options
parameter, which defaults to{}
. When theoptions[:omit_query_params]
is set totrue
, the query parameters will be omitted from the URL when matching a request. This does not change the default behavior of theActiveResource::HttpMock
class, rather it adds an option to change the behavior. In addition, I have also added a methodremove_query_params_from_path
to remove the query parameters.I hope this is not too much of a niche use case, and that this PR can be merged. If not, I would love to hear your feedback on this.