Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 failing tests #1

Open
rogermarlow opened this issue Jan 1, 2015 · 0 comments
Open

2 failing tests #1

rogermarlow opened this issue Jan 1, 2015 · 0 comments

Comments

@rogermarlow
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant