#!/bin/sh

if [ -z "$ADTTMP" ]; then
  ADTTMP=$(mktemp -d)
  cleanup() {
    rm -rf "$ADTTMP"
  }
  trap cleanup INT TERM EXIT
fi

cd $ADTTMP

exec 2>&1
set -ex

rails new myapp
cd myapp

cat <<EOF >> Gemfile
gem 'devise'
EOF

bundle install --local

rails generate devise:install

bin/spring stop
while pgrep -fa spring.*myapp; do
  sleep 1
  pkill -f spring.*myapp || true
done

test -f config/initializers/devise.rb
test -f config/locales/devise.en.yml
