ruby on rails - Active Record error to create database -


in spec/rails_helper.rb, have code bellow create test database if doesn`t exits.

def database_exists?   activerecord::base.connection rescue activerecord::nodatabaseerror ? false : true end unless database_exists?   activerecord::base.establish_connection(:"#{env['rails_env']}")   db_config = activerecord::base.configurations[env['rails_env']]   activerecord::base.connection.create_database db_config end 

but got error when rspec called:

.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/mysql2_adapter.rb:23:in `rescue in mysql2_connection': unknown database 'my-db-test' (activerecord::nodatabaseerror)

where problem?

if use system('rake db:create'), works, pratice?

the database doesn't exist avoid error can run:

rake db:create 

or can run:

rake db:setup 

this create database , run migration files.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -