I’m using a gem with my rails 3 project, “rails-settings-cached”, and when I’m in development mode the gem can access the database without any problem.
However, when I run “rake test”, a lot of tests fails because “rails-settings-cached” keeps using the development db instead of the testing one.
The other parts of my application works fine. What should I do to connect the gem to the right database?
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: mmdb_development
pool: 5
username: ***
password: ***
socket: /var/run/mysqld/mysqld.sock
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: mmdb_test
pool: 5
username: ***
password: ***
socket: /var/run/mysqld/mysqld.sock
The problem is that rails-settings-cached… well… caches the settings.
So, when you run your tests, it is actually using the old cached values from the “development” database.
A possible workaround can be running
rake tmp:cache:clearbefore and after the tests.It works, but to automate it you can put these methods inside test_helper.rb: