[rspec-users] form action url example

sinclair bain rspec.user at gmail.com
Mon Oct 1 10:53:46 EDT 2007


Living and learning !

Cheers for that David!
Cheers!
sinclair


On 9/28/07, David Chelimsky <dchelimsky at gmail.com> wrote:
>
> On 9/28/07, sinclair bain <rspec.user at gmail.com> wrote:
> > Hi,
> >
> > I have the following example:
> >
> >
> >   it 'should have a form with an action attribute' do
> >      response.should have_tag( "form[action=?]",
> > '/users/1/machines/1/trouble_tickets')
> >   end
> > for a form like so:
> >
> >
> > <% form_for( :trouble_ticket,
> >     :url => { :action => 'create',
> >                  :user_id => @machine.current_owner,
> >                  :machine_id => @machine } ) do |f| %>
>
> When you do this (:machine_id => @machine), rails calls
> @machine.to_param. So as long as you're stubbing the to_param method,
> it should work.
>
> Also, if you use mock_model, this is stubbed for you.
>
> Cheers,
> David
>
> > ...
> >
> > Now this fails.
> >
> > The way it will pass is to change the url parameters to _explicitly_
> call
> > the id method on the
> > parameter values like so:
> >
> >
> > <% form_for( :trouble_ticket,
> >     :url => { :action => 'create',
> >          :user_id => @ machine.current_owner.id,
> >          :machine_id => @machine.id } ) do |f| %>
> > ...
> >
> > (nb. I am stubbing and mock these objects )
> >
> > My thought is that rails does not require this since it helps by making
> sure
> > the #id of each object is used in the action url.
> >
> >
> > Is this an error in rspec or just something (mildly inconsistent? )
> which
> > I'll have to do in this very limited context ?
> >
> > Cheers!
> > sinclair
> >
> >
> >
> >
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071001/b1207f27/attachment.html 


More information about the rspec-users mailing list