3

In a rails controller test, how does one send in a query string to the 'get' method? For example, for the url www.abc.com/categories?type=10.

In my test I would start with: get :index

but then how do I pass in the query string to it?

2 Answers 2

3

This should work in your controller test:

get :index, type: 10 
Sign up to request clarification or add additional context in comments.

2 Comments

Getting UrlGenerationError: No route matches {:action => index, :type => '10'.....} Could it be that it's being passed as /categories/10 instead of /categores?type=10?
The params look alright, can you post the code for the route you wrote for that specific controller/action?
1

In Rails 5 you do like:

path_params = {format: :json, project_id: "OSE"} get get_test_cases_url(**path_params), params: {case_ids: ["NON-9450", "NON-12345", "OCP-9361"]} 

get_test_cases is name of your route. The path_params are all params needed to construct URL for the route. And this is passing one array type query GET param.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.