Search code examples
ruby-on-railsrubyunit-testingpostgresqlsingle-table-inheritance

Ruby on Rails Single Table Inheritance (STI) and unit test problem (with PostgreSQL)


I'm using an STI model with a single "Accounts" table to hold information for Users and Technicians (i.e. User < Account, Technician < Account). Everything works from a functional perspective, but things explode when running unit tests:

... 8) Error: test_the_truth(UserTest): ActiveRecord::StatementInvalid: PGError: ERROR: relation "technicians" does not exist : DELETE FROM "technicians" ...

Essentially, the standard framework doesn't recognize that the Technicians and Users tables (or "relations" as PostgreSQL calls them) don't exist and, in fact, should be aliased to Accounts.

Any ideas? I'm relatively new to RoR and I'm at a loss as how to fix this without ripping out STI all together.


Solution

  • Turns out that the problem was due to the presence of:

    ./test/fixtures/technicians.yml ./test/fixtures/users.yml

    This makes sense as the framework expected to be able to insert data into similarly named tables.