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