Forum: Ruby on Rails teardown not cleaning the BD?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ab4c5cd5d9cc028fcba7a5eec8e1bf30?d=identicon&s=25 Alain Pilon (Guest)
on 2006-05-17 04:45
Hi,

I am a bit confused, I have a few functionnal tests were I add/delete
records on top of the ones provided in the fixture and it seems like the
records are surviving the teardown. Isnt teardown supposed to be ran
after each test? So if I have something like:

  def teardown
    Client.delete_all
    Concept.delete_all
    Variation.delete_all
    ClientVariation.delete_all
  end

All the records from my DB should be deleted...

Well, when I run my test, I get a faillure on a test that is supposed to
make sure that a specific record is deleted. When I look at the DB, the
record is still there.

The test goes like this:

  def test_delete_concept
    #make sure the concept record is present
    assert_not_nil Concept.find(concepts(:entreprise).id)
    #make sure the variations record is present
    assert_not_nil Variation.find_by_concept_id
(concepts(:entreprise).id)
    #find a client_variation
    first_variation = Variation.find_by_concept_id
(concepts(:entreprise).id, :limit => 1)
    #make sure it is present
    assert_not_nil ClientVariation.find_by_variation_id
(first_variation.id)
    #delete the record from the DB
    get :delete_concept, {:concept_id => concepts(:entreprise).id}
    #search for the record, if not there, raises an exception
    assert_raises(ActiveRecord::RecordNotFound) {
Concept.find(concepts(:entreprise).id) }
    #search for the variation, if not there, raises an exception
    #this is the line that generate the faillure
    assert_raises(ActiveRecord::RecordNotFound) {
Variation.find_by_concept_id(concepts(:entreprise).id) }
    #search for the client_variation, if not there, raises an exception
  end

Any ideas?

thanks a lot!
This topic is locked and can not be replied to.