spring icon indicating copy to clipboard operation
spring copied to clipboard

ActiveRecord connection leaking to other envs

Open lowang opened this issue 7 years ago • 1 comments

Hi, I'm posting this here, but I'm unsure which component is directly responsible for that problem. I guess that it would be nice to have some guard to prevent this inside rspec-rails/rails itself.

REPLICATION run console attaching it to remote DB like this: DATABASE_URL=$PSQL_REMOTE rails c (development env) then I'm using rspec for running specs, now rspec (using spring) when executing tests is already connected to remote DB instead of local one. Add sth like database cleaner to the stack and you have just wiped remote database.

One safeguard for that could be adding inside rails_spec.rb following line: ActiveRecord::Tasks::DatabaseTasks.check_protected_environments! but I imagine that check as something internal to ... (rails? rspec-rails?) so we do not have to add it to all projects. I'm waiting for your comments here, please point me in the right direction.

lowang avatar Apr 03 '18 10:04 lowang

I am experiencing exactly this problem (and arrived at this issue while searching for guidance).

I'm working around the issue by using a different environment variable, which I give significance by conditionally injecting it into database.yml; this allows me to avoid ActiveRecord's response to DATABASE_URL which ends up having the test environment point in the same place.

More detailed notes of mine are here: https://gist.github.com/wxgeorge/ed5be6abab69b2eb33044f2264068d6b. I would be grateful for insight of those that better understand spring.

wxgeorge avatar Jan 25 '19 20:01 wxgeorge