views:

63

answers:

1

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

end

And error message i got is

29) 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

A: 

It looks like the Country object is not being created in the create action. There's not enough presented to determine the reason, but here are a few common cases (in order of most common).

  • validation is failing on Country model
  • authentication or authorization is being triggered
  • some other redirection through a before filter (for https or domain name change)

Take a look at your validations on the Country model, does the :country option given in the test make a valid model? If not I recommend using factories to generate valid model attributes.

If validation isn't the problem, take a look at the controller before filters to ensure a redirect isn't happening there.

You may want to move the assert_redirect into the assert_difference block which could give a more descriptive error.

ryanb