Hello, I have been struggling to get fixtures to work here with no success. They just Do Not Work For Me (tm). I have created a model named Headline with the `generate'' script and modified the test/fixtumes/headlines.yml as follows ---------- gita: id: 1 author: raulseixas title: gita happened_at: 2005-01-01 00:00:00 description: gita This is the CD reissue of the 1974 album and second solo release by Raul Seixas, an important figure of Brazilian rock. Acid critic of establishment, he pardodies several figures of Brazilian showbiz in the rocking "Super-Her?is." # more fixtures here ---------- My database table has columns named id, author, title, happened_at and description as expected. My headline_test file is as follows ---------- class HeadlineTest < Test::Unit::TestCase fixtures :headlines def test_fixture h = @headlines[''gita''] puts h.title end end ---------- When I call the test with `ruby test/unit/headline_test'', I get the following output: ---------------- 1) Error: test_fixture(HeadlineTest): NoMethodError: You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occured while evaluating nil.[] test/unit/headline_test.rb:25:in `test_fixture'' ---------------- The call to the `fixtures'' methods is supposed to initalize the @headlines instance variable, isn''t it? I can''t see where is my mistake. Cheers, Thiago Arrais
Thiago Arrais wrote:> The call to the `fixtures'' methods is supposed to initalize the > @headlines instance variable, isn''t it? I can''t see where is my > mistake.The syntax for getting at fixtures changed between the publication of AWDWR and Rails 1.0 - I expect that''s what''s bitten you. Try headlines(''gita'') instead of @headlines[''gita'']. -- Alex
On 3/23/06, Alex Young <alex@blackkettle.org> wrote:> The syntax for getting at fixtures changed between the publication of > AWDWR and Rails 1.0 - I expect that''s what''s bitten you. Try > headlines(''gita'') instead of @headlines[''gita''].Thanks, Alex. Works perfectly now. -- Thiago Arrais
On 3/23/06, Alex Young <alex@blackkettle.org> wrote:> The syntax for getting at fixtures changed between the publication of > AWDWR and Rails 1.0 - I expect that''s what''s bitten you. Try > headlines(''gita'') instead of @headlines[''gita''].Is this outdated too? Is there any other place that I can go for docs? http://api.rubyonrails.org/classes/Fixtures.html Regards, Thiago Arrais
Thiago Arrais wrote:> Is this outdated too? Is there any other place that I can go for docs? > > http://api.rubyonrails.org/classes/Fixtures.htmlIt''s not actually outdated per se - the defaults just changed. You can actually turn the old behaviour back on. There''s an explanation of what changed (and why) here: http://clarkware.com/cgi/blosxom/2005/10/24 -- Alex
On 3/23/06, Alex Young <alex@blackkettle.org> wrote:> It''s not actually outdated per se - the defaults just changed. You can > actually turn the old behaviour back on. There''s an explanation of what > changed (and why) here: > > http://clarkware.com/cgi/blosxom/2005/10/24I need to know how many fixtures are defined in the fixture file. Having read this I went like ------------ class MyControllerTest < Test::Unit::TestCase self.use_instantiated_fixtures = true fixtures :headlines def test_full_loaded get :show_all_headlines assert_equal @headlines.size, assigns(:headline).size end end ------------ Would there be a more recommended way of achieving this? Can I get the number o fixtures loaded without using instantiated fixtures? Thanks, Thiago Arrais
Thiago Arrais wrote:> Would there be a more recommended way of achieving this? Can I get the > number o fixtures loaded without using instantiated fixtures?In this case, I think you could do Headlines.count. -- Alex
On 3/23/06, Alex Young <alex@blackkettle.org> wrote:> In this case, I think you could do Headlines.count.Thanks for this one. I think I had gone into tunnel mode and looking on the woring place. Cheers, Thiago Arrais