Tests: Can't use items(:fixture_name) in setup method!

Hi all

I don’t know what happened, but since some time I can’t run my tests
anymore because I’m getting the following error:

chraftbuech:~/Webwork/pgbookings josh$ ruby
test/functional/admin/music_labels_
controller_test.rb
Loaded suite test/functional/admin/music_labels_controller_test
Started
EEEEEEEE
Finished in 0.156566 seconds.

  1. Error:
    test_create(Admin::MusicLabelsControllerTest):
    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.[]
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:498:in
    music_labels' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:496:inmusic_labels’
    test/functional/admin/music_labels_controller_test.rb:17:in `setup’
    …etc…

My setup method looks like that:

def setup
@controller = Admin::MusicLabelsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new

@bionics_records_id = music_labels(:bionics_records).id

end

I tracked the error down to the following line (line 17):

@bionics_records_id = music_labels(:bionics_records).id

It seems that music_labels() does not return the corresponding object
anymore! But in my fixtures everything seems ok:

music_labels.yml:
bionics_records:
id: 1
name: Bionics Records
origin_country_id: 4
index_records:
id: 2
name: Index Records
origin_country_id: 1

Can anyone give me a hint what’s the problem? When replacing

@bionics_records_id = music_labels(:bionics_records).id

with

@bionics_records_id = 1

everything works again…

Thanks a lot
Josh

Did you remember to call “fixtures :music_labels” ?

On Apr 26, 11:31 am, Joshua M. [email protected]

Jon wrote:

Did you remember to call “fixtures :music_labels” ?

On Apr 26, 11:31 am, Joshua M. [email protected]

Yes, that’s not the problem.

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