#!/bin/bash

# Only sync what is needed to run the tests
echo "Syncing files..."
sudo rsync -aq --ignore-missing-args --include-from=- /obs_readonly/ /obs/ <<EOF
+ Rakefile
+ docs/
+ docs/api/
+ docs/api/api/***
+ src/
+ src/api/
+ src/api/app/***
+ src/api/bin/***
- src/api/config/options.yml
- src/api/config/database.yml
+ src/api/config/***
+ src/api/db/***
+ src/api/lib/***
+ src/api/public/***
+ src/api/script/***
+ src/api/test/***
- src/backend/build/.git
- src/backend/build/.gitignore
+ src/backend/build/***
- src/backend/examples
- src/backend/t
- src/backend/testdata
+ src/backend/***
- *
EOF

echo "Preparing application..."
bundle exec rake dev:bootstrap[old_test_suite] RAILS_ENV=test

echo "Changing source_port to 3200..."
perl -pi -e 's/source_port: 5352/source_port: 3200/' config/options.yml

echo "Setting up sphinx..."
cp config/thinking_sphinx.yml{.example,}
touch config/test.sphinx.conf

echo "Running api test suite..."
if [[ -n $1 ]]
then
  bin/rails test $1
else
  bundle exec rake test:api
fi
