Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up travis.ci with Rails and Postgres

I'm having trouble getting Rails, postgres travis to work. Keep getting a database connection error when the tests start running.

Errno::ECONNREFUSED: Connection refused - connect(2)

.travis.yml

language: ruby
rvm:
  - "1.9.3"
before_script:
  - cp config/database.travis.yml config/database.yml
  - psql -c 'create database myapp_test;' -U postgres
  - bundle exec rake db:migrate --trace
  - bundle exec rake db:test:prepare --trace
script:
  - RAILS_ENV=test bundle exec rake spec

gemfile: Gemfile.ci

and database.travis.yml

test:
  adapter: postgresql
  database: myapp_test
  username: postgres

I have to use separate database config.

Any clue what I'm doing wrong? Following the documentation almost exactly in http://about.travis-ci.org/docs/user/database-setup/ except I have to copy database config over to the right place.

like image 363
mehulkar Avatar asked Oct 15 '13 03:10

mehulkar


2 Answers

Why are you doing the

bundle exec rake db:migrate
bundle exec rake db:test:prepare

The db:test:prepare is going to try and access the development database, which doesn't exist. And the rake db:migrate should be automatically run by Travis.

like image 140
Peter Goldstein Avatar answered Nov 02 '22 17:11

Peter Goldstein


The problem was that I needed to enable the elasticsearch service on travis. Adding records to the database requires indexing and the refused connection was to a nonexistent elasticsearch server.

like image 27
mehulkar Avatar answered Nov 02 '22 16:11

mehulkar