ok, let me show you my "products" fixtures file: ram: id: 1 title: RAM description: ECC RAM Registered, 512MB image_url: images/test.jpg price: 29.95 date_available: 2005-01-25 00:00:00 busted_arsehole: id: 2 title: Busted Arsehole description: I have an arsehole, it is-e busted image_url: images/test.jpg price: 999.95 date_available: 2005-01-25 00:00:00 hey: id: 3 title: hey description: testinggggg image_url: images/test.jpg price: 999.95 date_available: 2007-01-25 00:00:00 The problem im facing is that for some reason instance variables @hey, @busted_arsehole, @ram are all nil(and according to the book im using they should be associated with the particular fixtures. Otherwise unit testing is working fine. Any ideas? -- Posted via http://www.ruby-forum.com/.
Petr, Try products(:ram) instead of @ram Zack On 8/7/06, Petr <petr@punchyouremployer.com> wrote:> ok, let me show you my "products" fixtures file: > > ram: > id: 1 > title: RAM > description: ECC RAM Registered, 512MB > image_url: images/test.jpg > price: 29.95 > date_available: 2005-01-25 00:00:00 > busted_arsehole: > id: 2 > title: Busted Arsehole > description: I have an arsehole, it is-e busted > image_url: images/test.jpg > price: 999.95 > date_available: 2005-01-25 00:00:00 > hey: > id: 3 > title: hey > description: testinggggg > image_url: images/test.jpg > price: 999.95 > date_available: 2007-01-25 00:00:00 > > The problem im facing is that for some reason instance variables @hey, > @busted_arsehole, @ram are all nil(and according to the book im using > they should be associated with the particular fixtures. Otherwise unit > testing is working fine. > > Any ideas? > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Zack Chandler wrote:> Petr, > > Try products(:ram) instead of @ram > > ZackThanks, that did the trick. I suppose at the time the book was written they were using a different version of rails. By the way, one of the examples in the book is (simplified from my memory) @product = Product.find(1) localvariable = @products["ram"] assert_equal(localvariable["id"], product.id) Will this still work with the current version of rails? Also, with "products(:ram)" how do I "extract" something like the price, id or image_url out of it? In my book they just do it like this @ram.image_url etc, but this now doesnt work. Whats the new way? -- Posted via http://www.ruby-forum.com/.
On 8/7/06, Petr <petr@punchyouremployer.com> wrote:> Also, with "products(:ram)" how do I "extract" something like the price, > id or image_url out of it? In my book they just do it like this > @ram.image_url etc, but this now doesnt work. Whats the new way?like so: product = products(:ram) product.price product.id product.image_url ... or if you fancy, in your setup method, you could have: @ram = products(:ram) cheers, jean-pierre
Being able to access the individual fixture records by instance variable (e.g. @ram) was deprecated with Rails 1.0. If you really want to turn it back on, set use_instantiated_fixtures to true in your test_helper. Note, it is false by default for performance reasons. Chris On 8/8/06, jeanpierre@gmail.com <jeanpierre@gmail.com> wrote:> On 8/7/06, Petr <petr@punchyouremployer.com> wrote: > > Also, with "products(:ram)" how do I "extract" something like the price, > > id or image_url out of it? In my book they just do it like this > > @ram.image_url etc, but this now doesnt work. Whats the new way? > > > like so: > product = products(:ram) > product.price > product.id > product.image_url > ... > > or if you fancy, in your setup method, you could have: > @ram = products(:ram) > > cheers, > jean-pierre > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >