Forum: RSpec Passing get request parameters in an rspec test

0e8da4e8b7cc443b1ac780e10cd62eeb?d=identicon&s=25 Matt Kolenda (Guest)
on 2010-04-02 19:18
(Received via mailing list)
Hello

Please forgive my noobness to rspec.  I have a controller method that
inspects the params[:id] object and renders a view that depends on the
existence of that :id.

I want to ensure that the view is rendered in the controller rspec test.
The rspec code is:

  describe "GET 'enrollments'" do
    it "should be successful" do
      get 'enrollments'
      response.should be_success
    end
  end

The 'enrollments' controller method inspects the params object, pulls
out
the :id and uses it in a few queries to populate a couple of instance
variables.

My question is "How do I pass in the params[:id] parameter to the get
'enrollments' line?"

Thanks in advance

Matt
E3ba60e3dcb813f8abcd7732350e74cf?d=identicon&s=25 Phillip Koebbe (pkoebbe)
on 2010-04-02 20:00
(Received via mailing list)
On 2010-04-02 12:16 PM, Matt Kolenda wrote:
> Hello
>
> Please forgive my noobness to rspec.

We're all noobs at some point in regard to something. No forgiveness
necessary. :)

>     end
>   end
>
> The 'enrollments' controller method inspects the params object, pulls
> out the :id and uses it in a few queries to populate a couple of
> instance variables.
>
> My question is "How do I pass in the params[:id] parameter to the get
> 'enrollments' line?"
>

get 'enrollments', {:id => '1')

One thing I've learned is to pay attention to the data type you use in
the params hash when you use get|post|put|delete. The params hash in a
real application is filled with strings, so yours should be too.
> Thanks in advance
>
> Matt

Peace,
Phillip
E3ba60e3dcb813f8abcd7732350e74cf?d=identicon&s=25 Phillip Koebbe (pkoebbe)
on 2010-04-02 20:06
(Received via mailing list)
> get 'enrollments', {:id => '1')

And, of course, that should be a curly at the end!

get 'enrollments', {:id => '1'}

Phillip
0e8da4e8b7cc443b1ac780e10cd62eeb?d=identicon&s=25 Matt Kolenda (Guest)
on 2010-04-07 06:00
(Received via mailing list)
Phillip - Yes, that worked,  thanks a million!

Matt
This topic is locked and can not be replied to.