vendredi 1 janvier 2016

assert_difference('Course.count') expects difference but there is no change

I'm running a test to try to add a course to my database, but for some reason it doesn't seem to be adding since when I run:

test "should create course" do
    assert_difference('Course.count') do
      post :create, course: { name: 'New',
                              course_code: '1' }
    end

    assert_redirected_to course_path(assigns(:course))
  end

I get:

"Course.count" didn't change by 1.
<3> expected but was
<2>.

What's weird is that when I run the rails console and do

@course = Course.new(name: 'New', course_id: '1')
@course.save 

the course saves correctly in the database. Does anyone know why I might be getting this error?

Aucun commentaire:

Enregistrer un commentaire