Configuring travis.ci with Rails and Postgres

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

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 need to use a separate database configuration.

Any clues what am I doing wrong? Following the documentation is almost exactly at http://about.travis-ci.org/docs/user/database-setup/ , except that I need to copy the database configuration to the right place.

+6
source share
3 answers

The problem was that I needed to enable elasticsearch service on travis. Indexing is required to add records to the database, and a failed connection to a non-existent elasticsearch server.

0
source

Why are you doing

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

db: test: preparation will try to access a development database that does not exist. And the db: migrate rake should automatically start Travis.

+1
source

Based on the doc you must first enable the postgresql service

 services: - postgresql 

And specify DB type with (optional):

  env: - DB=pgsql 

NOTE: postgresql and postgres DO NOT WORK. Use pgsql !!!

Here is the complete code that worked for me:

.travis.yml

 language: ruby rvm: - 2.2 env: - DB=pgsql services: - postgresql script: - RAILS_ENV=test bundle exec rake db:migrate --trace - bundle exec rake db:test:prepare - bundle exec rake before_script: - cp config/database.yml.travis config/database.yml - psql -c 'create database courseselect_test;' -U postgres 

configurations / database.yml.travis

 default: &default adapter: postgresql encoding: unicode pool: 5 development: <<: *default database: courseselect_development test: <<: *default database: courseselect_test production: <<: *default database: courseselect_developement 

By the way, I also have a database.yml file with the same contents as config/database.yml.travis

0
source

Source: https://habr.com/ru/post/955953/


All Articles