07 May 2010, 18:50
Generic-user-small

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
Samr_small_pragsmall

Sam Ruby (584 posts)

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

08 May 2010, 04:50
Generic-user-small

future429 (3 posts)

I saw that and even copied the file from

http://media.pragprog.com/titles/rails4/code/depot_c/test/functional/products_controller_test.rb

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
Samr_small_pragsmall

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:

product=Product.new(@update)
product.valid?
p product.errors
08 May 2010, 22:14
Generic-user-small

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
Generic-user-small

srinivas valekar (1 post)

Even then its not working please help..

12 Apr 2013, 22:02
Generic-user-small

Temur Melibaev (1 post)

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

../test/functional/products_controller_test.rb

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

  You must be logged in to comment