Forum: RSpec why is 'get :index, :page => 2' different from 'get :index, :page => "2"'

Posted by apneadiving (Guest)
on 2012-01-06 00:49
(Received via mailing list)
Hi,

After coding my app and enjoying a green wave of tests, I had horrible
feedback about some bugs.

Those bugs happened to some well tested parts of my app.

After some research, I found out that

get :index, :page => 2, :per_page => 5

is different from:

get :index, :page => "2", :per_page => "5"

So I simply missed some 'to_i' in my controller.

I thought, the 'get' parameters would have been stringified, like it
is in a standard request.

Why is it not the case?
Posted by David Chelimsky (Guest)
on 2012-01-06 00:57
(Received via mailing list)
On Thu, Jan 5, 2012 at 5:45 PM, apneadiving 
<apnea.diving.deep@gmail.com> wrote:
>
> is different from:
>
> get :index, :page => "2", :per_page => "5"
>
> So I simply missed some 'to_i' in my controller.
>
> I thought, the 'get' parameters would have been stringified, like it
> is in a standard request.

That's what I thought too!

https://github.com/rails/rails/pull/1203

>
> Why is it not the case?

It is, depending on what version of Rails you're using. Don't remember
which version included my patch(es), but I *think* it was 3.1.

HTH,
David
Posted by apneadiving (Guest)
on 2012-01-06 01:16
(Received via mailing list)
On Jan 6, 12:55am, David Chelimsky <dchelim...@gmail.com> wrote:
> > get :index, :page => 2, :per_page => 5
> That's what I thought too!
> HTH,
> David
> _______________________________________________
> rspec-users mailing list
> rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users

You definitely rock.

Thanks a bunch for this neat & quick answer :)
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.