From 99e8e078777ea640fe877d733b206e241dc961fc Mon Sep 17 00:00:00 2001 From: Ryan Fitzgerald Date: Wed, 18 Jul 2012 15:15:03 -0700 Subject: [PATCH] Make it easier to test server behavior with all Rails versions --- Appraisals | 1 + Rakefile | 22 +++++++++++++++++----- test/routes.rb | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Appraisals b/Appraisals index 7c60224..d3f9429 100644 --- a/Appraisals +++ b/Appraisals @@ -1,5 +1,6 @@ appraise "rails30" do gem "rails", "3.0.15" + gem "sqlite3" end appraise "rails31" do diff --git a/Rakefile b/Rakefile index f9aba20..f618284 100644 --- a/Rakefile +++ b/Rakefile @@ -3,13 +3,25 @@ require "bundler/setup" require "bundler/gem_tasks" require "appraisal" +include FileUtils + desc 'Create test Rails app' -task :init_test_app do - `rm -rf test/app >/dev/null 2>&1` +task :init_test_app => 'appraisal:install' do + # Remove and generate test app using Rails 3.0 + rm_rf 'test/app' `env BUNDLE_GEMFILE=gemfiles/rails30.gemfile bundle exec rails new test/app` - FileUtils.cp("test/routes.rb", "test/app/config/routes.rb") - File.open("test/app/Gemfile", 'a+') { |f| f.write(%Q{gem "pry-rails", :path => "../../"}) } - FileUtils.cd("test/app") + + # Copy test routes file into place + cp 'test/routes.rb', 'test/app/config/routes.rb' + + # Remove rjs line from environment, since it's gone in versions >= 3.1 + env_contents = File.readlines('test/app/config/environments/development.rb') + File.open('test/app/config/environments/development.rb', 'w') do |f| + f.puts env_contents.reject { |l| l =~ /rjs/ }.join("\n") + end + + # Generate a few models + cd 'test/app' `env BUNDLE_GEMFILE=../../gemfiles/rails30.gemfile bundle exec rails g model Pokemon name:string caught:binary species:string abilities:string` `env BUNDLE_GEMFILE=../../gemfiles/rails30.gemfile bundle exec rails g model Hacker social_ability:integer` `env BUNDLE_GEMFILE=../../gemfiles/rails30.gemfile bundle exec rails g model Beer name:string type:string rating:integer ibu:integer abv:integer` diff --git a/test/routes.rb b/test/routes.rb index 73c4017..21fe5dc 100644 --- a/test/routes.rb +++ b/test/routes.rb @@ -1,3 +1,4 @@ App::Application.routes.draw do resource :pokemon, :beer + get 'pry' => proc { binding.pry; [200, {}, ['']] } end