<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:garamond, 'new york', times, serif;font-size:12pt">Ah, thanks! That was a breakthrough. My mock object "ids_string" isn't receiving the method calls I expect (even though the code under test actually does what I want it to do and works correctly), but at least I'm past the params issue.<br><br><div>Al<div><div style="font-family:garamond, new york, times, serif;font-size:12pt"><br class="webkit-block-placeholder"></div><div style="font-family:garamond, new york, times, serif;font-size:12pt"><br><div style="font-family:times new roman, new york, times, serif;font-size:12pt">----- Original Message ----<br>From: Daniel Tenner <daniel.ruby@tenner.org><br>To: rspec-users <rspec-users@rubyforge.org><br>Sent: Tuesday, December 4, 2007 1:56:25 AM<br>Subject: Re: [rspec-users] params not available for controller specs?<br><br>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;"><font face="Helvetica" size="3" style="font:12.0px Helvetica;">Try:</font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;"><font face="Helvetica" size="3" style="font:12.0px Helvetica;">get :download, :ids => ids_string</font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 12px/normal Helvetica;min-height:14px;"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;"><font face="Helvetica" size="3" style="font:12.0px Helvetica;">You need the ":" in front of the action name.</font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 12px/normal Helvetica;min-height:14px;"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;"><font face="Helvetica"
size="3" style="font:12.0px Helvetica;">Daniel</font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;"><br class="webkit-block-placeholder"></div><div><div>On 4 Dec 2007, at 09:28 4 Dec 2007, Al Chou wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family:garamond, 'new york', times, serif;font-size:12pt;">I actually did stub Order.find() but was getting a nil object error because params[:ids] was nil. I can't write<div><br class="webkit-block-placeholder"></div><div>controller.download :ids => '1/2/3'</div><div><br class="webkit-block-placeholder"></div><div>in the controller spec, and</div><div><br class="webkit-block-placeholder"></div><div>get download, :ids => ids_string</div><div><br class="webkit-block-placeholder"></div><div>results in the following error message:</div><div><br class="webkit-block-placeholder"></div><div><div>NameError in
'Admin::OrdersController should split the params[:ids] string to create an array of id's to find for downloading'</div><div>undefined local variable or method `download' for [RSpec example]:#<Class:0x34939e8></div><div>./spec/controllers/admin/orders_controller_spec.rb:14:</div></div><div><br><div><div><br class="webkit-block-placeholder"></div><div>Al<div><div style="font-family:garamond, new york, times, serif;font-size:12pt;"><br><div style="font-family:times new roman, new york, times, serif;font-size:12pt;">----- Original Message ----<br>From: Jarkko Laine <<a rel="nofollow" ymailto="mailto:jarkko@jlaine.net" target="_blank" href="mailto:jarkko@jlaine.net">jarkko@jlaine.net</a>><br>To: rspec-users <<a rel="nofollow" ymailto="mailto:rspec-users@rubyforge.org" target="_blank" href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a>><br>Sent: Tuesday, December 4, 2007 12:33:11 AM<br>Subject: Re: [rspec-users] params not
available for controller specs?<br><br> <br>On 4.12.2007, at 10.17, Al Chou wrote:<br><br>> Hi, all,<br>><br>> I'm trying to write a spec for a controller method that starts out:<br>><br>><br>> def download<br>> @orders = Order.find( params[:ids] )<br>> ...<br>><br>> and started writing a spec that set params[:ids] to a mock.<br><br>Why would you want to set params[:ids] to a mock? params values are <br>always basically strings (or hashes/arrays of strings) and you can set <br>them in the actual action call:<br><br>get :foo, :ids => [1,2,3]<br><br>Moreover, in your case Order.find should be the thing you want to <br>stub. You don't want the finder call to go to the database, since <br>you're speccing the controller behaviour here, not business logic.<br><br>//jarkko<br><br>--<br>Jarkko Laine<br><a rel="nofollow" target="_blank" href="http://jlaine.net">http://jlaine.net</a><br><a rel="nofollow"
target="_blank" href="http://dotherightthing.com">http://dotherightthing.com</a><br><a rel="nofollow" target="_blank" href="http://www.railsecommerce.com">http://www.railsecommerce.com</a><br><a rel="nofollow" target="_blank" href="http://odesign.fi">http://odesign.fi</a><br><br><br>_______________________________________________<br>rspec-users mailing list<br><a rel="nofollow" ymailto="mailto:rspec-users@rubyforge.org" target="_blank" href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br><a rel="nofollow" target="_blank" href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a></div></div></div></div></div></div></div></blockquote></div></div></div></div></div></div><br>
<hr size=1>Looking for last minute shopping deals? <a href="http://us.rd.yahoo.com/evt=51734/*http://tools.search.yahoo.com/newsearch/category.php?category=shopping">
Find them fast with Yahoo! Search.</a></body></html>