Hi all, I'm new to Rails, I got the book and I've got a question unanswered. I need to build a Rail application on top on an existing Database (MS SQL server) and the naming convention for the tables name is not quite the same as Rails. The tables names aren't pluralize and they use capital letter at the beginning of each word instead of using "_" to separate the words. (e.g.: ClientPrice instead of client_price) I've managed to create a model, thanks to Rails ability to override the default settings, however when I come to test it using fixtures I'm running into troubles. I've got a table called "ClientPrice", I've therefore created a model called "ClientPrice" and adjusted the table name and primary key name in the model: class ClientPrice < ActiveRecord::Base set_table_name "ClientPrice" set_primary_key "ClientPrice_id" end This works fine and I can CRUD into this model using scaffolding. Rails also created a fixture file for me called "client_price". However I had to rename it to "clientprice" so it can load the data into the Test database. Here's my sample fixture file: price_for_client_A: ClientPrice_id: 1 Price: 1.5 Unit: Dollars Here's my problem, I wrote the following test file: class ClientPriceTest < Test::Unit::TestCase fixtures :clientprice def test_model assert_equal clientprice(:price_for_client_A).Price, ClientPrice.find (:first).Price end end And the assertion failed saying "NoMethodError: You have a nil object when you didn't expect it!" It means that clientprice(:price_for_client_A) is retuning a NIL object while it should return the 1st object of my fixture, to make the test to work I have to do this: assert_equal 1.5, ClientPrice.find(:first).Price In this case it works because the database is correctly populated with 1.5 However if my table name is just called "Client" and my fixture file called "client.yml" then the above test works fine. Providing that my Model is now called "Client" and my test class called "ClientTest" Any idea why that is? Gael
on 2005-12-10 16:58
on 2006-02-21 21:51
Has anyone come up with a good solution to get around the set_table_name -> fixtures issue?