07 May 2010, 18:50

future429 (3 posts)

` test “should create product” do assert_difference(‘Product.count’ ) do post :create, :product => @update end

assert_redirected_to product_path(assigns(:product))

end `

Always causes this error:

1) Failure: test_should_create_product(ProductsControllerTest) [depot/test/functional/products_controller_test.rb:35]: “Product.count” didn’t change by 1. <3> expected but was <2>.

I have looked at the test.log and it seems to be posting the correct information and the system responds without an error.

07 May 2010, 20:14

Sam Ruby (584 posts)

Beta 2, page 92 talks about this failure and how to correct it.

08 May 2010, 04:50

future429 (3 posts)

I saw that and even copied the file from


but I get the same error. I am sure it is something that I am doing wrong but I am trying to determine what that is. Test.log should show an error or something if the product can not be created right?

08 May 2010, 12:45

Sam Ruby (584 posts)

Could I ask you to add the following code to the top of the test, and report back with what it says:

p product.errors
08 May 2010, 22:14

future429 (3 posts)

{:title=>["has already been taken"]}

I changed @update title to “lorem ipsum 2” and that resolved the problem. I guess the database is not purged when the tests run?

Thanks for taking the time to help me with this. I assumed that validation errors would be logged.

28 Jun 2012, 16:18

srinivas valekar (1 post)

Even then its not working please help..

12 Apr 2013, 22:02

Temur Melibaev (1 post)

Внимательней читайте


test "should create product" do
assert_difference('Product.count') do
post :create, product: @update

  You must be logged in to comment