View Testing: Action with parameters

I’m looking for the solution to testing for the correct format of a form
action with extra parameters in the url in my view tests.
I’m probably overlooking something simple, but I cannot figure out why
this is not working. Should i event be testing for this
in my view test, or should this be a controller-with-integrated-views
specific test?

Thanks for the help on my first question to this list!

Test code abbreviated

@person = mock_model(Person)
assigns[:person] = @person

response.should have_tag(“form[action=?][method=post]”,
categorizations_path(:person => @person) do

View code abbreviated

<% form_for :categorization, :url => {:person => @person} do |f| %>

Example should assert

should find form[action=’/categorizations?person=1002’][method=‘post’]
where 1002 is the autogenerated id of @person.

On Jun 21, 2008, at 5:03 PM, Britt Mileshosky wrote:

Test code abbreviated

<% form_for :categorization, :url => {:person => @person} do |f| %>

Example should assert

should find form[action=’/categorizations?person=1002’]
[method=‘post’] where 1002 is the autogenerated id of @person.

A view example is the right place for this.

What’s the failure message you’re getting?

Expected at least 1 element matching
“form[action=’/categorizations?person=1002’][method=‘post’]”, found 0.
is not true.

From: [email protected]
To: [email protected]
Date: Sat, 21 Jun 2008 17:13:14 -0500
Subject: Re: [rspec-users] View Testing: Action with parameters

On Jun 21, 2008, at 5:03 PM, Britt Mileshosky wrote:I’m looking for the
solution to testing for the correct format of a form action with extra
parameters in the url in my view tests.
I’m probably overlooking something simple, but I cannot figure out why
this is not working. Should i event be testing for this
in my view test, or should this be a controller-with-integrated-views
specific test?

Thanks for the help on my first question to this list!

Test code abbreviated

@person = mock_model(Person)
assigns[:person] = @person

response.should have_tag(“form[action=?][method=post]”,
categorizations_path(:person => @person) do

View code abbreviated

<% form_for :categorization, :url => {:person => @person} do |f| %>

Example should assert

should find form[action=’/categorizations?person=1002’][method=‘post’]
where 1002 is the autogenerated id of @person.
A view example is the right place for this.
What’s the failure message you’re getting?

in my view test, or should this be a controller-with-integrated-

Example should assert

should find form[action=’/categorizations?person=1002’]
[method=‘post’] where 1002 is the autogenerated id of @person.

A view example is the right place for this.

What’s the failure message you’re getting?

On Jun 21, 2008, at 5:27 PM, Britt Mileshosky wrote:

Expected at least 1 element matching “form[action=’/categorizations?
person=1002’][method=‘post’]”, found 0.
is not true.

Please add ‘puts response.body’ to your example, run it again and copy
the output back. And please post in-line rather than top posting in
threads like this - it makes it much easier to follow the progression
than top posting.

Thanks.

From: [email protected]
To: [email protected]
Date: Sat, 21 Jun 2008 17:13:14 -0500
Subject: Re: [rspec-users] View Testing: Action with parameters

On Jun 21, 2008, at 5:03 PM, Britt Mileshosky wrote:I’m looking for the
solution to testing for the correct format of a form action with extra
parameters in the url in my view tests.
I’m probably overlooking something simple, but I cannot figure out why
this is not working. Should i event be testing for this
in my view test, or should this be a controller-with-integrated-views
specific test?

Thanks for the help on my first question to this list!

Test code abbreviated

@person = mock_model(Person)
assigns[:person] = @person

response.should have_tag(“form[action=?][method=post]”,
categorizations_path(:person => @person) do

View code abbreviated

<% form_for :categorization, :url => {:person => @person} do |f| %>

Example should assert

should find form[action=’/categorizations?person=1002’][method=‘post’]
where 1002 is the autogenerated id of @person.
A view example is the right place for this.
What’s the failure message you’re getting?

On Jun 21, 2008, at 5:27 PM, Britt Mileshosky wrote:Expected at least 1
element matching
“form[action=’/categorizations?person=1002’][method=‘post’]”, found 0.
is not true.

From: [email protected]

To: [email protected]

Date: Sat, 21 Jun 2008 17:30:10 -0500

Subject: Re: [rspec-users] View Testing: Action with parameters

Please add ‘puts response.body’ to your example, run it again and copy
the output back. And please post in-line rather than top posting in
threads like this - it makes it much easier to follow the progression
than top posting.
Thanks.

That puts did the trick.

I was getting:

Instead of:

because when using:
form_for :categorizations, :url => {:person=>@person} - it defaults to
the current controller action which is ‘new’
the fix:
form_for :categorizations, :url => {:action => “create”, :person =>
@person}

Thank you for your saturday responses! Believe it or not this is the
first list ive ever subscribed to, so I hope this response is ‘inline’.