开发者

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? Thank开发者_如何学JAVAs.


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 


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜