testing multi value querystring parameters

139 views
Skip to first unread message

Jilles van Gurp

unread,
Apr 2, 2013, 5:58:30 AM4/2/13
to sina...@googlegroups.com
I'm working around sinatra's lack of multi value parameters in the query string by parsing it directly. This works fine. However, I'm a bit stuck with how to test this using rack-test since rack/sinatra seem to be conspiring to defeat all my attempts to pass multiple values for the same parameter.

In my test I have something like

get "/?tag=foo&tag=bar"

the actual query string on the sinatra side is

tag=bar

So, it loses the first value. I've tried using a list in the params object as well

get "/?tag=foo&tag=bar", {"tag"=>["foo","bar"]}

this has the same result.

Is there a way to set the query string directly?

I'm using pretty much the latest of everything (as of yesterday): rack (1.5.2),  rack-test (0.6.2), sinatra (1.3.6).

Jilles

Konstantin Haase

unread,
Apr 2, 2013, 6:13:47 AM4/2/13
to sina...@googlegroups.com
You should be able to use request.query_string.

See also:


Konstantin

--
You received this message because you are subscribed to the Google Groups "sinatrarb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sinatrarb+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jilles van Gurp

unread,
Apr 2, 2013, 8:11:29 AM4/2/13
to sina...@googlegroups.com
Thanks, 

That didn't quite work but it made me figure out that there is a request function that you can call directly from a test:

request("/?tag=foo&tag=bar")

This actually works as expected and the query string is passed as is to sinatra, as you would expect.

Jilles 
Reply all
Reply to author
Forward
0 new messages