Re: params not available for controller specs?

I think Jarkko is saying that no spec should have been written for the
code I was trying to fix/change. I’m not sure I would agree that
BDD/RSpec is an inappropriate tool for documenting what I was trying to
change, but I think he would argue that…

Al

----- Original Message ----
From: David C. [email protected]
To: rspec-users [email protected]
Sent: Tuesday, December 4, 2007 12:18:58 PM
Subject: Re: [rspec-users] params not available for controller specs?

On Dec 4, 2007 2:09 PM, Al Chou [email protected] wrote:

I get what you’re saying, but I was trying to fix a bug in existing
code in
Substruct (that I did not write) that was caused by Rails passing the
array
as a /-delimited string and then not automatically decoding that
string. As
Substruct does not say that Edge Rails is a requirement, I felt it
was worth
documenting what I had to change to run it on Rails 1.2.x. Every
code
change should be driven by a test or example; perhaps in this
situation I
should’ve gone over to Test::Unit instead of staying in RSpec? An
interesting philosophical thought…

Seems to me this thread has been about how to deal with rails. I don’t
see what that has to do w/ a T::U vs rspec decision.

The problem is that params[:ids], although built as an Array object

http://localhost:3000/en/clients?foo[]=1&foo[]=2&foo[]=3&foo[]=4&foo[]=5

That will get correctly parsed back to an array in the receiving
action:

def download
If params[:ids] is “1/2/3”, you can be pretty certain that split("/")


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

  ____________________________________________________________________________________

Be a better pen pal.
Text or chat with friends inside Yahoo! Mail. See how.
http://overview.mail.yahoo.com/

On 4.12.2007, at 23.11, Al Chou wrote:

I think Jarkko is saying that no spec should have been written for
the code I was trying to fix/change. I’m not sure I would agree
that BDD/RSpec is an inappropriate tool for documenting what I was
trying to change, but I think he would argue that…

What I was saying was that I think it’s important that Order.find gets
called with an array of ids. That’s what you want to happen and to
have in your spec, right? So in your spec, you’d have

it “should find orders with an array of ids” do
Order.should_receive(:find).with([“1”, “2”, “3”])
get :download, :ids => “1/2/3”
end

(or whatever ids you pass to the action).

Now, if the current, buggy behaviour just passes the string as “1/2/3”
to Order.find, the spec above will break, because it will not receive
an array but a string. After you add the split("/") call to the actual
code, your broken spec is fixed, and the code works as expected. Tada!
No need to stub String#split anywhere.

//jarkko


Jarkko L.
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs