Ruby on Rails testing/ fixtures question

Discussion in 'Ruby' started by Stephen Richards, Aug 19, 2006.

  1. Hi,

    I'm using Test::Unit::TastCase and am having some problems getting
    expected database state before the test methods.

    My Ruby on rails book quite clearly says that the following things
    happen before every test method is run:
    - all records in the database are deleted
    - all the data in the fixtures are loaded into the database
    - the setup method is run.

    In the following situation, the test_deactivate method happens to get
    run first. Then the test_find_all_for_team method runs, and doesn't
    find the expected number of records (because one of them has been
    de-activated).

    Am I doing something wrong, or do the fixtures not get loaded every time?

    code snippet:

    require File.dirname(__FILE__) + '/../test_helper'

    class TaskTest < Test::Unit::TestCase
    fixtures :employees, :teams, :states, :tasks


    def test_find_all_for_team
    active_tasks = Task.find_all_for_team
    assert_equal 3, active_tasks.size
    end

    def test_deactivate
    task = Task.find(1)
    assert task.active?

    task.deactivate
    task.reload
    assert !task.active?
    end

    end
     
    Stephen Richards, Aug 19, 2006
    #1
    1. Advertising

  2. Stephen Richards

    Eric Hodel Guest

    On Aug 19, 2006, at 1:25 AM, Stephen Richards wrote:

    > Hi,


    The Ruby on Rails mailing list is the appropriate place for asking
    Rails questions.

    --
    Eric Hodel - - http://blog.segment7.net
    This implementation is HODEL-HASH-9600 compliant

    http://trackmap.robotcoop.com
     
    Eric Hodel, Aug 19, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Heinemeier Hansson
    Replies:
    3
    Views:
    156
    James Britt
    Nov 18, 2004
  2. Replies:
    1
    Views:
    112
    Timothy Hunter
    Dec 27, 2006
  3. Mayank Srivastava
    Replies:
    1
    Views:
    102
    Brian Candler
    Mar 20, 2007
  4. Mark
    Replies:
    0
    Views:
    102
  5. Vassilis Rizopoulos

    Getting fixtures to work without Rails

    Vassilis Rizopoulos, Jun 28, 2007, in forum: Ruby
    Replies:
    5
    Views:
    156
    Vassilis Rizopoulos
    Jun 28, 2007
Loading...

Share This Page