I want to load the test environment for Rails to run my minitest tests.
I require config/environment.rb after setting RAILS_ENV to 'test'.
It seems that this is not the correct way to do it because the test database doesn't seem to be created.
I know this is a pretty noobish question, but I don't see anyone else really asking it.
*Code in my test/test_helper.rb
require 'minitest/autorun'
ENV['RAILS_ENV'] = 'test'
require_relative '../config/environment'
*Basic Boiler Plate and Sanity Test in test/models/users_test.rb
require_relative '../test_helper.rb'
class UserModelTest < MiniTest::Test
def setup
@user = User.new
@user.email = 'me@example.com'
@user.password = 'password'
@user.save
end
def test_sanity
assert true
end
end
*The error I get from the setup method above that makes me think the test db is not being created and migrated
Error:
UserModelTest#test_sanity:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "users" does not exist
LINE 5: WHERE a.attrelid = '"users"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
/home/john/.rvm/gems/ruby-2.1.1@mangam/gems/activerecord-4.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:815:in `async_exec'
.
.
.
/home/john/.rvm/gems/ruby-2.1.1@mangam/gems/activerecord-4.1.0/lib/active_record/inheritance.rb:23:in `new'
test/models/users_test.rb:6:in `setup'