Hi,
I’m writing unit test for the Depot application from “Agile development
with Rails”.
this is my fixture:
version_control_book:
id: 1
title: Pragmatic Version Control
description: How to use version control
image_url: http://www.radrails.org/images/radrails.png
price: 100
date_available: 2006-09-10
automation_book:
id: 2
title: Pragmatic Project Automation
description: How to automate your project
image_url: http://www.radrails.org/images/flagr_brand.png
price: 20.90
date_available: 2006-09-11
Then I have 2 test methods:
def setup
@product = Product.find(1)
end
def test_update
assert_equal 100, @product.price
@product.price = 99.99
@product.save
@product.reload
assert_equal 99.99, @product.price
end
def test_destroy
@product.destroy
assert_raise(ActiveRecord::RecordNotFound)
{Product.find(@product.id)}
end
When I run just test_update, it passes. But when I run all tests, it
fails.
- Error:
test_update(ProductTest):
ActiveRecord::RecordNotFound: Couldn’t find Product with ID=1
In the book it says, that before each method rails recreates the whole
table and calls the setup method. It looks like that it doesn’t happen
in my case. test_destroy method deletes the product with id 1, and
test_update can’t find it.
Is this a bug, or I’m doing something wrong?
Thanks