Created
November 16, 2010 23:23
-
-
Save acook/702727 to your computer and use it in GitHub Desktop.
Easy access Ruby on Rails aliases and functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Put this file somewhere in your path then do `chmod +x rails_helpers` on it | |
# Put `source rails_helpers` in your ~/.bash_profile or .bashrc | |
# Type `rails_helpers ?` to get a quick look at the aliases and functions defined within | |
if [ $# -gt 0 ]; then | |
echo 'rails_helpers: rails CLI helpers by Anthony M. Cook 2010-2011' | |
echo "cat $(which $0) for more info." | |
echo '' | |
echo 'aliases:' | |
grep '^alias' $(which $0) | |
echo '' | |
echo 'functions:' | |
grep '^function' $(which $0) | |
exit | |
fi | |
# Pull in RVM's bash script that does stuff | |
if [[ -s ~/.rvm/scripts/rvm ]] ; then source ~/.rvm/scripts/rvm ; fi | |
# This is used for systems with configurable gems, see https://gist.github.com/1098370 | |
export custom_gems=enabled | |
# Run all tests | |
alias all_tests='rake test' | |
# All tests, making sure the DB is prepared with the latest versions | |
alias all_db_tests='empty_db; all_tests; seed_db & feat_tests' | |
# Shortcuts for each basic test type | |
alias unit_tests='rake test:units' | |
alias func_tests='rake test:functionals' | |
alias inte_tests='rake test:integration' | |
alias feat_tests='cucumber' | |
# Run an individual unit test file | |
function unit_test { echo "Starting unit test..."; ruby -I lib:test test/unit/$1_test.rb $2 $3 $4 $5; } | |
# Run an individual functional test file | |
function func_test { echo "Starting func test..."; ruby -I lib:test test/functional/$1_controller_test.rb $2 $3 $4 $5; } | |
# Run an individual feature test file | |
function feat_test { echo "Starting feat test..."; cucumber FEATURE=features/"$1".feature; } | |
# Run a specific line number/scenario from a feature test file | |
function scen_test { echo "Starting scen test..."; cucumber features/"$1".feature:"$2"; } | |
# Database shortcuts | |
alias empty_db='rake db:drop; rake db:create; rake db:migrate' | |
alias seed_db='rake db:seed' | |
alias reset_db='empty_db; seed_db' | |
# Get the DB ready for tests | |
alias test_db_clone='echo "Cloning test db schema from development db..."; rake db:test:clone_structure' | |
alias test_db_prepare='echo "Preparing test DB..."; rake db:test:prepare' | |
alias test_db_fixtures='echo "Loading fixtures..."; RAILS_ENV=test rake db:fixtures:load' | |
alias test_db='test_db_clone; test_db_fixtures' | |
# Clear the logs, makes grepping easier. | |
alias clear_logs='rm -rf logs/' | |
# Loads the test fixtures into the test database and launches the rails test console | |
alias test_console='test_db; rails c test' | |
# Runs the development server using the test database | |
# Uses thin with multitail if you have them installed with my script | |
function test_server { | |
test_db | |
echo "Starting server..." | |
which thinlogs > /dev/null && dev_db=test.bizbuilt.com thinlogs || dev_db=test.bizbuilt.com rails s; | |
} | |
# Generates Railroad diagrams | |
function roadia { | |
railroady -M -a -m -t -i -l "Date: $(date '+%Y.%m.%d %H:%M')" -o "models_$(date '+%Y.%m.%d.%H.%M').dot" | |
railroady -C -i -l "Date: $(date '+%Y.%m.%d %H:%M')" -o "models_$(date '+%Y.%m.%d.%H.%M').dot" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment