user2884789
user2884789

Reputation: 533

rails test database cloning dev database

I'm new to Ruby on Rails and following Michael Hartls Ruby on Rails Tutorial. When I run bundle rake exec test, I am getting this error:

ERROR["test_should_get_new", SessionsControllerTest, 2.331314]
test_should_get_new#SessionsControllerTest (2.33s)
ActiveRecord::StatementInvalid:         
ActiveRecord::StatementInvalid: Could    not find table 'users'

and once similar for all of my tests. I see that my test database: test.sqlite3 is empty. My development database development.sqlite3 does have the users table in it.

I tried running the following to attempt cloning the users database to the test database, but nothing is working:

rake db:migrate:reset
rake db:migrate db:test:prepare

rake db:test:clone

rake db:test:prepare
rake db:test:load

but it's still empty. Any suggestions please?

Upvotes: 1

Views: 393

Answers (2)

user2884789
user2884789

Reputation: 533

I figured out a fix, although I'm still not sure why there was a problem to begin with. What I did was I took the pure Sql CREATE TABLE used to create the development table and executed it in the users table. Now everything is working fine.

Upvotes: 1

James Milani
James Milani

Reputation: 1943

I think you might be able to get it with:

RAILS_ENV=test rake db:migrate

Give it a try, I've had this problem before myself. I believe that

rake db:test:prepare

is deprecated. What version of ruby and rails are you using?

Upvotes: 1

Related Questions