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

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

Hi
   Check for any unsatisfied validations

Sijo

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

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

http://guides.rubyonrails.org/testing.html

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

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

Thank you sijo

I will do that and let you know

thank you Fred

I will do that and let you know

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.