Skip to content

rake task doesn't load .env.test #302

@ValentinTrinque

Description

@ValentinTrinque

Steps to reproduce

  1. I started a fresh new Rails application using:
rails new . --api --database=postgresql
  1. I inserted dotenv-rails into the Gemfile:
group :development, :test do
  gem 'dotenv-rails'
end
  1. I setup two environment file .env.development and .env.test with:
DATABASE_URL=postgres://val@localhost/myapp_dev

and

DATABASE_URL=postgres://val@localhost/myapp_test

respectively.

  1. Run rake db:create.

Expected behavior

I am expecting rake db:create to load .env.test environment variable as pointed by the README.

Example:

Created database 'myapp_dev'
Created database 'myapp_test'

Actual behavior

But I get:

Created database 'myapp_dev'
ERROR:  database "myapp_dev" already exists
STATEMENT:  CREATE DATABASE "myapp_dev" ENCODING = 'unicode'
Database 'myapp_dev' already exists

As you can see, instead of creating the development and test database, it attempts to create the development database twice. Clearly, dotenv is ignoring the .env.test.

System configuration

dotenv version:
2.2.1

Rails version:
5.1.0

Ruby version:
2.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions