[rspec-devel] [ rspec-Patches-8316 ] to_param should return a stringified key in resource generator's controller spec

noreply at rubyforge.org noreply at rubyforge.org
Tue Jan 30 19:18:02 EST 2007


Patches item #8316, was opened at 2007-01-31 01:24
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=8316&group_id=797

Category: rails plugin
Group: None
Status: Closed
Resolution: Accepted
Priority: 3
Submitted By: Chris Anderson (jchris)
Assigned to: David Chelimsky (dchelimsky)
Summary: to_param should return a stringified key in resource generator's controller spec

Initial Comment:
Rails expects a string here, raising errors like:

TypeError in 'Requesting /venues using POST should create a new venue'
can't convert Fixnum into String
(eval):19:in `venue_url'

when given a Fixnum param.

This patch simply adds a few quote marks to the rspec resource generator's controller spec template.

----------------------------------------------------------------------

Comment By: Deepak Jois (deepakjois)
Date: 2007-01-31 08:18

Message:
A similar patch needs to be applied to the view spec generators too..

Index: show_rhtml_spec.rb
===================================================================
--- show_rhtml_spec.rb  (revision 136)
+++ show_rhtml_spec.rb  (working copy)
@@ -5,7 +5,7 @@
   
   setup do
     @<%= file_name %> = mock("<%= file_name %>")
-    @<%= file_name %>.stub!(:to_param).and_return(99)
+    @<%= file_name %>.stub!(:to_param).and_return("99")
     @<%= file_name %>.stub!(:errors).and_return(@errors)<% for attribute in attributes -%>
     @<%= file_name %>.should_receive(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)<% end -%>
 
Index: edit_rhtml_spec.rb
===================================================================
--- edit_rhtml_spec.rb  (revision 136)
+++ edit_rhtml_spec.rb  (working copy)
@@ -8,7 +8,7 @@
     @errors.stub!(:count).and_return(0)
 
     @<%= file_name %> = mock("<%= file_name %>")
-    @<%= file_name %>.stub!(:to_param).and_return(99)
+    @<%= file_name %>.stub!(:to_param).and_return("99")
     @<%= file_name %>.stub!(:errors).and_return(@errors)<% for attribute in attributes -%>
     @<%= file_name %>.should_receive(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)<% end -%>
 
Index: new_rhtml_spec.rb
===================================================================
--- new_rhtml_spec.rb   (revision 136)
+++ new_rhtml_spec.rb   (working copy)
@@ -8,7 +8,7 @@
     @errors.stub!(:count).and_return(0)
 
     @<%= file_name %> = mock("<%= file_name %>")
-    @<%= file_name %>.stub!(:to_param).and_return(99)
+    @<%= file_name %>.stub!(:to_param).and_return("99")
     @<%= file_name %>.stub!(:errors).and_return(@errors)<% for attribute in attributes -%>
     @<%= file_name %>.should_receive(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)<% end -%>


----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-01-31 02:38

Message:
Applied in rev 1445

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=8316&group_id=797


More information about the rspec-devel mailing list