#!/bin/bash

set -e

if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
	source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
	source "/usr/local/rvm/scripts/rvm"
else
	printf "ERROR: An RVM installation was not found.n"
fi

function run {
	value=$( gem list --local bundler )
	if [[ ! $value =~ "^bundler " ]]; then
		gem install bundler --no-ri --no-rdoc
	fi

	echo 'Running bundle exec rspec spec against activesupport / activerecord 3.2.17'
	ACTIVE_RECORD_SURVEY_ACTIVERECORD_VERSION=3.2.17 bundle update activerecord
	bundle exec rspec spec

	echo 'Running bundle exec rspec spec against activesupport / activerecord 4.2.0'
	ACTIVE_RECORD_SURVEY_ACTIVERECORD_VERSION=4.2.0 bundle update activerecord
	bundle exec rspec spec

	echo 'Running bundle exec rspec spec against activesupport / activerecord edge'
	ACTIVE_RECORD_SURVEY_ACTIVERECORD_VERSION="edge" bundle update activerecord
	bundle exec rspec spec
}

rvm use ruby-2.1.1@active_record_survey --create
run

rvm use ruby-2.0.0@active_record_survey --create
run

rvm use ruby-1.9.3@active_record_survey --create
run