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-kZbwfhiKUx26c6uEtOJ/EA@public.gmane.org
Tim Bates wrote:> 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.Thanks for the report; new_model pluralization is fixed in CVS. Grab the beta gems to see fixes and features ahead of the the next release: gem update -s http://gems.rubyonrails.org jeremy
Tim Bates wrote:> 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.Actually, in an almost identical manner, I don''t like the way the `rails` command does an `rm -rf` on the folder name I specify - because if means that to run `rails` on a directory, I have to have permissions to the parent directory, which I may not have. Rather than destroying the directory (or database), why can''t Rails just remove everything in it? This would allow the superuser to create the directory (or database) and give permissions for it to a user, who can call `rails` on it (or run tests on the database) without needing any more permissions than that. Tim. -- Tim Bates tim-kZbwfhiKUx26c6uEtOJ/EA@public.gmane.org