Testing fails with fixtures not when invoked directly

I have three files organization.rb, company.rb, and department.rb. I
want
to ensure the department always has a company

require File.dirname(FILE) + ‘/…/test_helper’

class OrganizationTest < Test::Unit::TestCase
fixtures :organizations

def setup
@smo = organizations(:smo)
end

def test_department_company_defaults_to_parent
org = Department.new(:name => ‘company’,:cost_code => ‘123’,
:parent_id
=> organizations(:root_dept))
assert org.valid?
assert org.company_id = organizations(:root_dept).company_id
end

end

This fails when loading the fixtures file from rake but works if I do
the
test by itself
ruby test/unit/test_organization.rb => this works

rake => fails

D:\workspace\directory>rake
(in D:/workspace/directory)
c:/ruby/bin/ruby -Ilib;test “c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1
/lib/rake/rake_test_load
er.rb” “test/unit/organization_test.rb” “test/unit/phone_test.rb”
Loaded suite c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1
/lib/rake/rake_test_loader
Started
EEE
Finished in 0.14 seconds.

  1. Error:
    test_department_company_defaults_to_parent(OrganizationTest):
    NoMethodError: You have a nil object when you didn’t expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.[]

D:/workspace/directory/config/…/vendor/rails/activerecord/lib/active_record/fixtures.rb:4
81:in organizations' ./test/unit/organization_test.rb:65:intest_department_company_defaults_to_parent’

  1. Error:
    test_department_company_defaults_to_parent(OrganizationTest):
    NoMethodError: You have a nil object when you didn’t expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.-

D:/workspace/directory/config/…/vendor/rails/activerecord/lib/active_record/transactions.
rb:107:in `decrement_open_transactions’

D:/workspace/directory/config/…/vendor/rails/activerecord/lib/active_record/fixtures.rb:5
45:in `teardown’

********** Files are as below ***********

****** organizations.yml **

smo:
id: 1
name: SLC Systems Management Office
cost_code: 8211
routing:
type: Department
company_id: 4

faa:
id: 4
name: Federal Aviation Administration
type: Company

root_dept:
id: 5
name: root
type: Department
company_id: 4

child1:
id: 6
name: child1
type: Department
company_id: 4
parent_id: 5

child2:
id: 7
name: child2
type: Department
company_id: 4
parent_id: 5

** organization.rb

== Schema Information

Schema version: 1

Table name: organizations

id :integer(11) not null, primary key

name :string(255) default(), not null

routing :string(10)

cost_code :string(10)

url :string(255)

phone :string(14)

fax :string(14)

parent_id :string(255)

type :string(255)

company_id :string(255)

class Organization < ActiveRecord::Base

validates_presence_of :name

end

** company.rb **

class Company < Organization

has_many :departments

end

** department.rb **

class Department < Organization

acts_as_tree

acts_as_list :scope => :parent_id

validates_presence_of :company_id

belongs_to :company

before_validation :set_default_company_from_parent

protected

def set_default_company_from_parent
self.company_id ||= self.parent.company_id if self.parent
end

end

We’re having the same problem. Actually it’s more accurate to say we’re
NOW
having the same problem, after months of development.

Do you our anyone have any thoughts on this occurrence?

I am using MySql on a windows development box.

I still have this problem, any ideas?

Thanks in advance

Dominic

---------- Forwarded message ----------
From: Brittain [email protected]
Date: Aug 14, 2006 9:56 PM
Subject: [Rails] Re: Testing fails with fixtures not when invoked
directly
To: [email protected]

We’re having the same problem. Actually it’s more accurate to say we’re
NOW
having the same problem, after months of development.

Do you our anyone have any thoughts on this occurrence?

Dominic, sorry to say, nothing has changed. We’re also using MySQL on a
windows box, rails 1.1.6.

The errors seem to indicate the fixture isn’t loading (complains of
records
with ID=xyz missing, even though they’re in the fixtures), but
otherwise, no
new info.

On 8/17/06, Dominic S. [email protected] wrote:

I still have this problem, any ideas?

Thanks in advance

Dominic

Do you by any chance use SQL Server 2000?

Raf

I’ve seen this happen before. I think it was caused by having a setup
method declared in both test/test_helper.rb and in your test class…
but I
could be wrong.

-Jonathan.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs