version: 2.1

orbs:

ruby: circleci/ruby@1.1.1
<%- unless @skip_node -%>
node: circleci/node@2
<%- end -%>

jobs:

test:
  parallelism: 1
  docker:
    - image: cimg/ruby:<%= @ruby_version %>-node
    - image: circleci/postgres:11.2
      environment:
        POSTGRES_USER: postgres
        POSTGRES_DB: <%= "#{@repository_name}_test" %>
  environment:
    BUNDLE_JOBS: "3"
    BUNDLE_RETRY: "3"
    PGHOST: 127.0.0.1
    PGUSER: postgres
    RAILS_ENV: test
  steps:
    - checkout
    - ruby/install-deps
    <%- unless @skip_node -%>
    # Store bundle cache
    - node/install-packages:
        pkg-manager: yarn
        cache-key: "yarn.lock"
    <%- end -%>
    - run: cp config/database.yml.ci config/database.yml
    - run:
        name: Wait for DB
        command: dockerize -wait tcp://localhost:5432 -timeout 1m
    - run:
        name: Database setup
        command: bundle exec rails db:schema:load --trace
    - run:
        name: Run test
        command: bundle exec rails test

workflows:

version: 2
test:
  jobs:
    - test