Dominic Sisneros
2006-Aug-14 19:11 UTC
[Rails] 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:in
`test_department_company_defaults_to_parent''
2) 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060814/f859b339/attachment.html
Brittain
2006-Aug-15 03:57 UTC
[Rails] Re: Testing fails with fixtures not when invoked directly
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 Sisneros
2006-Aug-17 17:34 UTC
Fwd: [Rails] Re: Testing fails with fixtures not when invoked directly
I still have this problem, any ideas? Thanks in advance Dominic ---------- Forwarded message ---------- From: Brittain <scott_brittain@hotmail.com> Date: Aug 14, 2006 9:56 PM Subject: [Rails] Re: Testing fails with fixtures not when invoked directly To: rails@lists.rubyonrails.org 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? _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060817/2ace28f8/attachment.html
Rafael Szuminski
2006-Aug-17 19:27 UTC
[Rails] Re: Testing fails with fixtures not when invoked directly
On 8/17/06, Dominic Sisneros <dsisnero@gmail.com> wrote:> I still have this problem, any ideas? > > Thanks in advance > > DominicDo you by any chance use SQL Server 2000? Raf -- http://www.bdcsoftware.com" - Automotive CRM
Dominic Sisneros
2006-Aug-17 21:48 UTC
[Rails] Re: Testing fails with fixtures not when invoked directly
I am using MySql on a windows development box. On 8/17/06, Rafael Szuminski <raf1hh@gmail.com> wrote:> > On 8/17/06, Dominic Sisneros <dsisnero@gmail.com> wrote: > > I still have this problem, any ideas? > > > > Thanks in advance > > > > Dominic > > Do you by any chance use SQL Server 2000? > > Raf > > -- > http://www.bdcsoftware.com" - Automotive CRM > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060817/ba91774f/attachment.html
Brittain
2006-Aug-18 01:45 UTC
[Rails] Re: Testing fails with fixtures not when invoked directly
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.
Jonathan Viney
2006-Aug-18 06:52 UTC
[Rails] Re: Testing fails with fixtures not when invoked directly
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. On 8/15/06, Brittain <scott_brittain@hotmail.com> wrote:> > 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? > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060818/b1cf84b1/attachment.html