I’m working with a legacy postgresql database where the names of tables,
columns, etc., do not usually follow Rails conventions.
I’ve been able to work around it for the most part, but I ran into this:
I have the following test:
require File.dirname(FILE) + ‘/…/test_helper’
class SponsorTest < Test::Unit::TestCase
self.use_transactional_fixtures = true
fixture :sponsors, :table_name => “sponsor”
fixture :eligibilities, :table_name => “topic_eligibility”
Replace this with your real tests.
assert_kind_of Sponsor, sponsors(:first)
(The “fixture” method comes from a patch that allows me to specify
non-standard table names–the table in this case is called sponsor, not
The sponsor table’s primary key column is called “sponsor_key” instead
of id, and instead of it being a serial type, it is just an integer. It
is incremented using a sequence named “sponsor_seq”.
I also have a sponsors.yml fixture with unremarkable contents.
When I try and run the test I get this:
Loaded suite test/unit/sponsor_test
EWARNING: there is no transaction in progress
Finished in 0.831961 seconds.
ActiveRecord::StatementInvalid: PGError: ERROR: relation
“sponsor_sponsor_key_seq” does not exist
: SELECT setval(‘sponsor_sponsor_key_seq’, (SELECT
COALESCE(MAX(sponsor_key), 0)+1 FROM sponsor), false)
It looks like the code in fixture.rb hardcodes an assumption about
sequence names. Any way that could be parameterized?