-
Notifications
You must be signed in to change notification settings - Fork 2
Description
ruby-2.1.2 (master)$ rake db:create db:migrate db:seed RAILS_ENV=test
ruby-2.1.2 (master)$ rake test:all
Run options: --seed 957
# Running tests:
F.....F
Finished tests in 2.363902s, 2.9612 tests/s, 4.2303 assertions/s.
1) Failure:
PeopleControllerTest#test_should_create_person [~/platform_validator/test/controllers/people_controller_test.rb:20]:
"Person.count" didn't change by 1.
Expected: 3
Actual: 2
2) Failure:
PeopleControllerTest#test_should_update_person [~/platform_validator/test/controllers/people_controller_test.rb:39]:
Expected response to be a <redirect>, but was <200>
7 tests, 10 assertions, 2 failures, 0 errors, 0 skips
The problem is with the people.yml fixtures. They instantiate two People, but both with the same name: first_name: MyString, last_name: MyString. The Person model meanwhile has a validation validates_uniqueness_of :first_name, :scope => :last_name. So the People table is already populated with rows inconsistent with the model before the tests start. Then...
Failure 1 is from this test
setup do
@person = people(:one)
end
test "should create person" do
assert_difference('Person.count') do
post :create, person: { first_name: @person.first_name, last_name: @person.last_name }
end
assert_redirected_to person_path(assigns(:person))
end
which tries to put a person called MyString MyString into a table of People already called MyString MyString. The model rightly rejects it so Person.count does not change and the assertion fails.
Failure 2 is from this test
setup do
@person = people(:one)
end
test "should update person" do
patch :update, id: @person, person: { first_name: @person.first_name, last_name: @person.last_name }
assert_redirected_to person_path(assigns(:person))
end
which tries to update a Person to have name MyString MyString into a table already containing two(!) people both called MyString MyString. This causes the person model validation to fail but this only causes the controller to send the client back to action: edit (no flash error). Nevertheless this isn't a redirection to person_path so the test fails.