services:
  - postgres:9.5
  - elasticsearch:2
  - redis:latest

variables:
  POSTGRES_DB: portalmec_test
  POSTGRES_USER: portalmec
  POSTGRES_PASSWORD: 123mudar
  ELASTICSEARCH_URL: http://elasticsearch:9200
  REDIS_HOST: redis:6379
  REDIS_RATE_LIMIT_URL: redis://redis:6379/0

stages:
  - test
  - deploy

before_script:
  - apt-get update -y
  - apt-get install default-jre postgresql-client -y
  - apt-get remove --purge --auto-remove redis-server -y
  - apt-get install redis-server -y
  - apt-get install nodejs -y
  # official way to provide password to psql: http://www.postgresql.org/docs/9.3/static/libpq-envars.html
  - export PGPASSWORD=$POSTGRES_PASSWORD
  - psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT 'OK' AS status;"
  # gems
  - gem install bundler
  - bundle install --jobs $(nproc) --path=/cache/bundler

test:
  stage: test
  script:
    - bundle exec rake db:migrate:reset RAILS_ENV=test
    - rake spec:acceptance
  tags:
    - ruby
    - postgres
    - elasticsearch
    - redis

#deploy:
#  stage: deploy
#  script:
#    - mina deploy
#  only:
#    - master
#  tags:
#    - ruby
#    - postgres
#    - elasticsearch
#    - redis
