Help for Functional Testing?

Hi

Below is my functional test code

def test_should_create_county
assert_difference(‘County.count’) do
post :create, :county =>
{:name=>“myname”,:description=>“mydesc”,:region_id=>“3” }
end
assert_redirected_to county_path(assigns(:county))
end

And error message i got is

  1. Failure:
    test_should_create_county(CountiesControllerTest)
    [/test/functional/counties_controller_test.rb:16]:
    “County.count” didn’t change by 1.
    <3> expected but was
    <2>.

Please help


Karthik.k
Mobile - +91-9894991640

Hi
Can’t say what happens only based on this. Anyway please change
above to

def test_should_create_county
County.destroy_all
assert_difference(‘County.count’) do
post :create, :county =>
{:name=>“myname”,:description=>“mydesc”,:region_id=>“3” }
end
assert_redirected_to county_path(assigns(:county))
end

Sijo

Hi Sijo

Thank you

but Still i find the same error
Can you please say why this happens
Any idea


Karthik.k
Mobile - +91-9894991640

On Tue, Aug 4, 2009 at 12:22 PM, Sijo Kg

Hi
Check for any unsatisfied validations

Sijo

On Tue, Aug 4, 2009 at 1:36 PM, Sijo Kg
[email protected]wrote:

Hi
Check for any unsatisfied validations

Sijo

Posted via http://www.ruby-forum.com/.

hi Sijo

Ya i saw but no unsatisfied validations is there, i have one doubt
in each controller, there is authentication checked, does that affect
this
functional testing

any idea

plz help


Karthik.k
Mobile - +91-9894991640

On Tue, Aug 4, 2009 at 1:53 PM, karthik k [email protected]
wrote:

Posted via http://www.ruby-forum.com/.

plz help

Hi Sijo

I think you are tired helping me

When i run scaffolding and run functional testing also it provides error
message
Is there any initial setup for functional testing

I am not able to run the basic functional testing that scaffolding
generates

karthik.k

Just to know which version of rails r u using Please check this

Sijo

On Tue, Aug 4, 2009 at 4:05 PM, Sijo Kg
[email protected]wrote:

Just to know which version of rails r u using Please check this

Testing Rails Applications — Ruby on Rails Guides

Sijo

Hi Sijo

I use 2.3.2
I use Aptana IDE

Ya i saw the link when i started but i am not getting what i need from
that
link


Karthik.k
Mobile - +91-9894991640

Yes as Fred said you need that and suppose if you are using a session
varible person_id it can be done like for example in test_helper just
write a def like

def login_as(person)
@request.session[:person_id] = person ? person.id : nil
end

And from your test call this by passing administrator object as
variable

Sijo

On Aug 4, 9:23 am, karthik k [email protected] wrote:

On Tue, Aug 4, 2009 at 1:36 PM, Sijo Kg [email protected]wrote:

Ya i saw but no unsatisfied validations is there, i have one doubt
in each controller, there is authentication checked, does that affect this
functional testing

If your controller normally requires users to be logged in then you
will need to make it appear that the test requests are coming from a
logged in user.

Fred

On Tue, Aug 4, 2009 at 4:36 PM, Sijo Kg
[email protected]wrote:

variable

Sijo

Thank you sijo

I will do that and let you know


Karthik.k
Mobile - +91-9894991640

Sijo Kg wrote:

Hi
Can’t say what happens only based on this. Anyway please change
above to

def test_should_create_county
County.destroy_all

That destroy should not matter. (And assert_latest is much more accurate
&
useful than assert_difference here.)

 assert_difference('County.count') do
   post :create, :county =>

{:name=>“myname”,:description=>“mydesc”,:region_id=>“3” }
end
assert_redirected_to county_path(assigns(:county))
end

Most likely you fail validation. If your error flashes to the page, you
can put
assert_match /something/, flash[:warning], or the equivalent, above the
assert_redirect.

Otherwise, change your save to save! and see if you get a crash message.


Phlip

On Tue, Aug 4, 2009 at 4:23 PM, Frederick C.
<[email protected]

wrote:

If your controller normally requires users to be logged in then you
will need to make it appear that the test requests are coming from a
logged in user.

Fred

thank you Fred

I will do that and let you know


Karthik.k
Mobile - +91-9894991640