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. 1) 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Check that you have use_transactional_fixtures = true in test_helper.rb ? On 17 Sep 2006, at 12:00, Alex wrote:> > 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. > 1) 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 > > -- > Posted via http://www.ruby-forum.com/. > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk- > unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > For more options, visit this group at http://groups.google.com/ > group/rubyonrails-talk > -~----------~----~----~----~------~----~------~--~--- >
Jonathan del Strother wrote:> Check that you have use_transactional_fixtures = true in > test_helper.rb ?that did it :) thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---