Checking Rails via rake: don't touch my dev database

I want rake test: units to successfully run tests in a prepared test database while my development database is down. Rails is currently trying to create a test database from a development database. Is it possible?

I got into a situation where prod / dev databases are disconnected from the host, but for unit tests I use sqlite in the memory database.

EDIT for my exact actions: Note. I am using Rails 2.3

My test database is configured like this: config / database.yml:

test: adapter: sqlite3 database: 'sqlite3_unittest_file.dat' pool: 5 timeout: 5000 

When I run rake db:test:load , the test database (which is just a file) is generated correctly in the rails-root directory. And when I run rake test:units , everything works.

Now, if I edited database.yml to set my DEV database name so that something is wrong (for example, 'sdlkfj'), rake test:units could not instantly complain:

 Access denied for user 'sdlkfj'@'myhostnsmae' (using password: YES) 

When I run this assembly "really", I run it on a system where the assembly is not allowed to speak in the field during the assembly process. Therefore, this attempt to talk to the developer base and instantly croak is killing me and seems wrong.

+6
source share
2 answers

Try running the rake task with an explicit environment:

 rake test:units RAILS_ENV=test 

If you did not specify an environment, development assumed in my experience. Although the test database still receives hardware data into it, material from the development environment is still referenced for some reason.

+7
source

The reason this fails is because the "rake: units test" first tries to verify that the test database is set up correctly. To do this, it calls "rake db: test: prepare", which copies the current schema from the dev database (I think that all migrations should be performed before running the tests).

I think you can work around this in several ways, one of which cancels the db: test: prepare rake task that was proposed in this StackOverflow article .

+4
source

Source: https://habr.com/ru/post/897518/


All Articles