0

For some reason Figaro is not setting my DATABASE_URL properly when testing. It uses the development DATABASE_URL for some reason. Here's the final few rows of my application.yml:

development:
  DATABASE_URL:               'postgres:///xxx-development'

test:
  DATABASE_URL:               'postgres:///xxx_test'

In my test I added a few print lines to help debug:

require 'rails_helper'
require 'json'
require 'rake'

RSpec.describe 'HealthProfile::HealthProfileTypeformParser' do
    
    before(:all) do
        p "ENV", ENV['RAILS_ENV'], ENV['DATABASE_URL']
        # prints "ENV", "test", "postgres:///xxx-development"
    end
 end

It makes no sense as clearly the environement is being set. Is there something else I need to do?

Jeremy Thomas
  • 6,240
  • 9
  • 47
  • 92
  • What version of `figaro` are you using? Also do you have any of these configs in your application.yml? – engineersmnky Feb 27 '23 at 21:48
  • It's v1.2. Not sure what you mean by "these configs". I have a typo up there. Should have been `application.yml`, not `database.yml`. – Jeremy Thomas Feb 27 '23 at 22:17
  • check your `database.yml` and see if you setting the correct `url` key for the `test` environment. based on your configuration, it should be `url: 'postgres:///xxx_test'` – Sachin Singh Feb 28 '23 at 06:08
  • It uses `ENV['DATABASE_URL']` in the `database.yml` – Jeremy Thomas Feb 28 '23 at 11:22
  • Even when I hard code it in `database.yml` it still picks up `postgres:///xxx-development` – Jeremy Thomas Feb 28 '23 at 11:56
  • I had to add this to `spec_helper` to get it working but I have no idea why? Does anyone know why this would be necessary? `ActiveRecord::Base.establish_connection(YAML.load(File.open(File.expand_path("../../lib/my_gem_config/database.yml", __FILE__)))["test"])` – Jeremy Thomas Mar 01 '23 at 13:25

0 Answers0