Form action url example

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| %>

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

Living and learning !

Cheers for that David!
Cheers!
sinclair

On 9/28/07, sinclair bain [email protected] wrote:

<% 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

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