[Rails] Unit tests broken out-of-the-box
Tim Bates
tim at bates.id.au
Wed Nov 10 03:23:17 GMT 2004
I'm using Postgres. The Rakefile that rails hands me calls dropdb and
createdb to return the test database to a known state (ie empty) before
it loads in db/production_structure.sql. This forces me to run the tests
as a user with the authorisation to create new databases (ie postgres).
I don't want to do this - I've created a test user, who owns the test
database, and if that database gets dropped e doesn't have the
permission to recreate it, and I want it to stay that way. Can the
Rakefile be changed to not destroy the database every time I run the
tests? This would seem to make sense for a commercial installation too -
the users wouldn't need superuser privileges to the database to run
their tests. I'm not sure how existing hosting installations handle this.
Once I resolved this, by (hopefully temporarily) giving Rails superuser
access to the database, I found that there appears to be a bug in the
test case generated by new_model.
I called "new_model User" which among other things created
test/unit/user_test.rb, which contains these lines:
def setup
@user = create_fixtures "user"
end
and also the empty directory test/fixtures/user to match.
`create_fixtures "user"` calls Fixtures.create_fixtures and passes
"user" as the table name, but because of Rails' rewriting, the table is
actually called "users", and my test cases die with
1) Error:
test_something(UserTest):
ActiveRecord::StatementInvalid: ERROR: syntax error at or near "user"
at character 13
: DELETE FROM user
If I change the line above to
@user = create_fixtures "users"
and
$ mv test/fixtures/user test/fixtures/users
then the test passes.
Tim.
--
Tim Bates
tim at bates.id.au
More information about the Rails
mailing list