Unit test problem,

Hi, I am new in ROR. I have 4 fixtures in my ‘…/test/fixtures’ folder:
user.yml, aggregationfeedmaps.yml, aggregations.yml, and feeds.yml. I
have few test files in unit tests folder like user_test.rb,
feeds_test.rb, aggregation_test.rb and such.

When I wrote test for model ‘user’ using fixture user.yml it worked
fine. But when I tried to run test for my other models using fixtures
aggregationfeedmaps.yml, aggregations.yml, and feeds.yml it shows this
error:

FixtureClassNotFound: No class attached to find

my test file ‘feeds_test.rb’:

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

#class FeedsTest < ActiveSupport::TestCase
class FeedsTest < Test::Unit::TestCase

Replace this with your real tests.

fixtures :feeds

def test_truth
assert true
end

def test_updatefeed
feed1 = feeds(:feed_1)

Feeds.updatefeed(feed1.id)

assert_equal(Time.now, feed1.lastupdate)

end

end

my fixture file: ‘feeds.yml’

Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

feed_1:
id: 1
sourcelink: http://sports.yahoo.com/ncaaf/teams/aad/ical.ics
feeddata: testdata
lastupdate: 2009-02-17 22:42:25
used: 1

feed_2:
id: 2
sourcelink: http://sports.yahoo.com/ncaaf/teams/aae/ical.ics
feeddata: testdata
lastupdate: 2009-02-17 22:42:25
used: 2

test_truth test passes but test_updatefeed shows the
FixtureClassNotFound error
Any help what is going on? Any help on the topic would be highly
appreciated.

On Apr 6, 2009, at 12:45 AM, Ps_gem Sh_gem wrote:

error:

FixtureClassNotFound: No class attached to find

my test file ‘feeds_test.rb’:

You’re probably running into a naming issue. Models are expected to
be the singular name and the tables will be plural as will the fixture
files. You can see them all with the Pluralizer
http://nubyonrails.com/tools/pluralize

But here’s a simple listing:

test/fixtures/feeds.yml
app/model/feed.rb
class Feed < ActiveRecord::Base
in a database tables named “feeds”

It also expects to convert between CamelCase and under_scored so if
your model is AggregationFeedMap, the file defining it should be app/
models/aggregation_feed_map.rb and the table name should be
aggregation_feed_maps and the fixture found in test/fixtures/
aggregation_feed_maps.yml

Does this help you figure out your issues? It all becomes quite
natural after a short while, but there are still times where you’ll
have a model name that the Inflector doesn’t get the pluralization
right and you either have to adjust or define an extra rule for the
word you want to use.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

It also expects to convert between CamelCase and under_scored so if
your model is AggregationFeedMap, the file defining it should be app/
models/aggregation_feed_map.rb and the table name should be
aggregation_feed_maps and the fixture found in test/fixtures/
aggregation_feed_maps.yml

Further, this command line…

script/generate model aggregation_feed_map

…should have set everything up correctly for you. Where’d these
fixtures come
from?

On Apr 6, 7:23 am, Phlip [email protected] wrote:

…should have set everything up correctly for you. Where’d these fixtures come
from?

In my case I have a model named LppBase. Pluralize becomes
lpp_bases. But if you singularize it back, it became lpp_basis. So,
I had to add an entry in the inflections file.

FYI: I debugged this by getting in to script/console and then
executing: “lpp_bases”.pluralize.singularize

HTH

pedz wrote:

In my case I have a model named LppBase. Pluralize becomes
lpp_bases. But if you singularize it back, it became lpp_basis. So,
I had to add an entry in the inflections file.

All your basis are belong to Rails.