local 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env ruby
  2. require File.expand_path('../../spec/support/detect_rails_version', __FILE__)
  3. unless ARGV[0]
  4. puts <<-EOF
  5. Usage: ./script/#{__FILE__} COMMAND [ARGS]
  6. The command will be run in the context of the local rails
  7. app stored in test-rails-app.
  8. Examples:
  9. ./script/local server
  10. ./script/local c
  11. ./script/local rake db:migrate
  12. EOF
  13. exit(1)
  14. end
  15. # Set up some variables
  16. rails_version = detect_rails_version || '3.0.0'
  17. test_app_dir = ".test-rails-apps"
  18. test_app_path = "#{test_app_dir}/test-rails-app-#{rails_version}"
  19. # Ensure .test-rails-apps is created
  20. system "mkdir #{test_app_dir}" unless File.exists?(test_app_dir)
  21. # Create the sample rails app if it doesn't already exist
  22. unless File.exists? test_app_path
  23. system "RAILS='#{rails_version}' bundle exec rails new #{test_app_path} -m spec/support/rails_template_with_data.rb"
  24. end
  25. # Link this rails app
  26. system "rm test-rails-app"
  27. system "ln -s #{test_app_path} test-rails-app"
  28. # If it's a rails command, auto add the rails script
  29. RAILS_COMMANDS = %w{generate console server dbconsole g c s runner}
  30. args = RAILS_COMMANDS.include?(ARGV[0]) ? ["rails", ARGV].flatten : ARGV
  31. # Run the command
  32. exec "cd test-rails-app && GEMFILE=../Gemfile bundle exec #{args.join(" ")}"