[Nitro] fixtures not loaded in test database

Humber Aquino humberaquino at gmail.com
Mon Dec 26 14:55:37 EST 2005


Hi everyone!! I have a problem with the fixtures in unit testing..

#This is my model
require 'og'

class User
   property :name, String
   property :telephone, String
   property :username, String, :uniq => true
   property :password, String

#This is the method that i'm trying to test
   def self.find_by_username_and_password(username, password)
      users = find  :condition => "username = '#{username}' and
password = '#{password}'"

      if users.nil? || users.size == 0
        return nil
      else
        return users[0]
      end
   end
end

#The fixture user.yml
user1:
  oid: 1
  name: John Doe
  telephone: '132312'
  username: jduser
  password: jdpassword
user2:
  oid: 2
  name: Some person
  telephone: '11112'
  username: spuser
  password: sppassword

#The test case
require 'test/unit'

require 'glue/fixture'
require 'og/test'
require 'src/model/user'

class TestUsuario < Test::Unit::TestCase

  def setup
    @og = Og.setup(
      :destroy => true,
      :store => :mysql,
      :name => 'test_db',
      :user => 'webuser',
      :password => 'some_pass'
    )

    og_fixture User
  end

  def test_all
    #There are 2 users in the fixture user.yml
    assert_equal 2, @users.size

    #But this assert fails. It looks that the fixture where loaded but
not inserted
    #in the database, but the structure is always updated.
    assert_equal 2, User.count
  end

  def test_find_by_username_password
    #This call returns nil.. because it's not loaded in the database
   john_doe = User.find_by_username_and_password('jduser', 'jdpassword')
  end
end

I don't know if there's a configuration step missing or it's the way it works..
Is there any other alternative for testing the
self.find_by_username_and_password(username, password) method but
using the fixtures? This works with no problem in rails..

Thanks for your help

Humber




More information about the Nitro-general mailing list