This project is archived and is in readonly mode.

#5100 ✓stale

Test env ignores AR set_table_name

Reported by mguymon | July 12th, 2010 @ 10:18 PM

I have legacy tables that uses studdly caps for table and column names, so the models must explicit set the table and primary key:

  class InventoryBlueprintType < ActiveRecord::Base
    set_table_name "invBlueprintTypes"
    set_primary_key "blueprintTypeID"

While the app works, all of the model tests would fail with NoMethodError: undefined method eq for nil:NilClass. Perplex I rummaged around until I luckily tried loading models in the test console vs the development console.

imperator:theapp zinger$ rails console test
Loading test environment (Rails 3.0.0.beta4)
>> InventoryBlueprintType
=> InventoryBlueprintType(Table doesn't exist)
>> exit
imperator:theapp zinger$ rails console
Loading development environment (Rails 3.0.0.beta4)
>> InventoryBlueprintType
=> InventoryBlueprintType(blueprintTypeID: integer, parentBlueprintTypeID: integer, productTypeID: integer, productionTime: integer, techLevel: integer, researchProductivityTime: integer, researchMaterialTime: integer, researchCopyTime: integer, researchTechTime: integer, productivityModifier: integer, materialModifier: integer, wasteFactor: integer, maxProductionLimit: integer)
>> exit

The above shows the RAILS_ENV for test is not using the model's set_table_name, while the RAILS_ENV for development is. It looks like the NoMethodError: undefined method eq for nil:NilClass error is happening from AR joins to the tables with set_table_name.

Comments and changes to this ticket

  • Rohit Arondekar

    Rohit Arondekar September 13th, 2010 @ 02:20 AM

    • Importance changed from “” to “Low”

    mguymon, is this still an issue with Rails 3.0?

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:31 PM

    • State changed from “new” to “open”
    • Tag changed from rails 3.0.0.beta4, testing to rails 300beta4, testing

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:31 PM

    • State changed from “open” to “stale”
  • Andrew Burns

    Andrew Burns March 9th, 2011 @ 11:34 PM

    I just ran into this with AR 3.0.5 and think I found the culprit, an edge case (obviously). The set_table_name does not match the table name in the connection.tables array. For me this was caused by passing a string into set_table_name (because it was easier to copy and paste from the legacy system), changing this to a symbol resolved my issue.

    Here are the relevant portions of my rails c test session:

    Loading test environment (Rails 3.0.5)
    irb(main):001:0> a = ChadApplication.find(1)
    NoMethodError: undefined method `eq' for nil:NilClass
            ...snip stack trace...
    irb(main):002:0> ActiveRecord::Base.connection.tables
    => ["appconfigodbc", "appconfigodbcprop", "appconfigoraclenet", "appconfigregistry", 
    "application", "applicationcomponent", "applicationconfig", "applicationtype", 
    "registrykey", "sequencereference", "userapplicationconfig", "userconfig", 
    irb(main):003:0> ChadApplication.table_name
    irb(main):004:0> ChadApplication.table_name = 'application'
    => "application"
    irb(main):005:0> a = ChadApplication.find(1)
    ActiveRecord::RecordNotFound: Couldn't find ChadApplication with ID=1
            ...snip stack trace...

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>