Shreyas
Shreyas

Reputation: 8757

Is there any setting required to be done before unit testing a model that maps to a different table as compared to Rails convention?

I have a model Vehicle which actually maps to the at_vehicles table. So while running my test script for Vehicle, I get the error "'vehicles' relation does not exist". Is there a hack , that could allow me to run my tests with the current db schema as is? Thanks.

Upvotes: 0

Views: 99

Answers (2)

Shreyas
Shreyas

Reputation: 8757

The problem was with the Fixtures. The fixture file 'obus' was trying to reach the obus table. So in case you're straying away from convention and using table names different from that of your models, You will also alter your fixture filenames

Upvotes: 0

Jed Schneider
Jed Schneider

Reputation: 14671

It's not a hack, but you can use set_table_name in your model (assuming rails 2.3.x). The test is doing the right thing, telling you that your active record association is not setup correctly. You need to define the relationship in your model.

class Vehicle < ActiveRecord::Base
  set_table_name "at_vehicles"
end 

Upvotes: 1

Related Questions