Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adapt test suite for multiple versions of rails

* initialize an app inside test_helper for rails 3
* gemfiles/ contains gemfiles for 2.3, 3.0, 3.1, and 3.2
* rake bundles:test runes tests against all gemfiles
* rake bundles:install and bundles:update installs/updates
  • Loading branch information...
commit 33d4c3a8528f00e7cea2f8d5a910e88566b8ecda 1 parent 37ad67f
John Hawthorn jhawthorn authored
22 Rakefile
View
@@ -2,8 +2,26 @@ require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
-desc 'Default: run unit tests.'
-task :default => :test
+desc 'Default: run unit tests against all versions.'
+task :default => 'bundles:test'
+
+def run_for_bundles cmd
+ Dir['gemfiles/*.gemfile'].each do |gemfile|
+ puts "\n#{gemfile}: #{cmd}"
+ ENV['BUNDLE_GEMFILE'] = gemfile
+ system(cmd)
+ end
+end
+
+task 'bundles:install' do
+ run_for_bundles 'bundle install'
+end
+task 'bundles:update' do
+ run_for_bundles 'bundle update'
+end
+task 'bundles:test' do
+ run_for_bundles 'bundle exec rake test'
+end
desc 'Test the authorization plugin.'
Rake::TestTask.new(:test) do |t|
8 gemfiles/2.3.gemfile
View
@@ -0,0 +1,8 @@
+source 'https://rubygems.org'
+
+gem 'rails', '~> 2.3.0'
+gem 'sqlite3'
+gem 'ruby_parser'
+gem 'rdoc'
+gemspec :path => '..'
+
44 gemfiles/2.3.gemfile.lock
View
@@ -0,0 +1,44 @@
+PATH
+ remote: /home/jhawthorn/code/declarative_authorization
+ specs:
+ declarative_authorization (0.5.5)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (2.3.14)
+ actionpack (= 2.3.14)
+ actionpack (2.3.14)
+ activesupport (= 2.3.14)
+ rack (~> 1.1.0)
+ activerecord (2.3.14)
+ activesupport (= 2.3.14)
+ activeresource (2.3.14)
+ activesupport (= 2.3.14)
+ activesupport (2.3.14)
+ json (1.7.3)
+ rack (1.1.3)
+ rails (2.3.14)
+ actionmailer (= 2.3.14)
+ actionpack (= 2.3.14)
+ activerecord (= 2.3.14)
+ activeresource (= 2.3.14)
+ activesupport (= 2.3.14)
+ rake (>= 0.8.3)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ ruby_parser (2.3.1)
+ sexp_processor (~> 3.0)
+ sexp_processor (3.2.0)
+ sqlite3 (1.3.6)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ declarative_authorization!
+ rails (~> 2.3.0)
+ rdoc
+ ruby_parser
+ sqlite3
8 gemfiles/3.0.gemfile
View
@@ -0,0 +1,8 @@
+source 'https://rubygems.org'
+
+gem 'rails', '~> 3.0.0'
+gem 'sqlite3'
+gem 'ruby_parser'
+gem 'rdoc'
+gemspec :path => '..'
+
89 gemfiles/3.0.gemfile.lock
View
@@ -0,0 +1,89 @@
+PATH
+ remote: /home/jhawthorn/code/declarative_authorization
+ specs:
+ declarative_authorization (0.5.5)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.15)
+ actionpack (= 3.0.15)
+ mail (~> 2.2.19)
+ actionpack (3.0.15)
+ activemodel (= 3.0.15)
+ activesupport (= 3.0.15)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.5.0)
+ rack (~> 1.2.5)
+ rack-mount (~> 0.6.14)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.15)
+ activesupport (= 3.0.15)
+ builder (~> 2.1.2)
+ i18n (~> 0.5.0)
+ activerecord (3.0.15)
+ activemodel (= 3.0.15)
+ activesupport (= 3.0.15)
+ arel (~> 2.0.10)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.15)
+ activemodel (= 3.0.15)
+ activesupport (= 3.0.15)
+ activesupport (3.0.15)
+ arel (2.0.10)
+ builder (2.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.5.0)
+ json (1.7.3)
+ mail (2.2.19)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.19)
+ polyglot (0.3.3)
+ rack (1.2.5)
+ rack-mount (0.6.14)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.15)
+ actionmailer (= 3.0.15)
+ actionpack (= 3.0.15)
+ activerecord (= 3.0.15)
+ activeresource (= 3.0.15)
+ activesupport (= 3.0.15)
+ bundler (~> 1.0)
+ railties (= 3.0.15)
+ railties (3.0.15)
+ actionpack (= 3.0.15)
+ activesupport (= 3.0.15)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.4)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ ruby_parser (2.3.1)
+ sexp_processor (~> 3.0)
+ sexp_processor (3.2.0)
+ sqlite3 (1.3.6)
+ thor (0.14.6)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.33)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ declarative_authorization!
+ rails (~> 3.0.0)
+ rdoc
+ ruby_parser
+ sqlite3
8 gemfiles/3.1.gemfile
View
@@ -0,0 +1,8 @@
+source 'https://rubygems.org'
+
+gem 'rails', '~> 3.1.0'
+gem 'sqlite3'
+gem 'ruby_parser'
+gem 'rdoc'
+gemspec :path => '..'
+
100 gemfiles/3.1.gemfile.lock
View
@@ -0,0 +1,100 @@
+PATH
+ remote: /home/jhawthorn/code/declarative_authorization
+ specs:
+ declarative_authorization (0.5.5)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (3.1.6)
+ actionpack (= 3.1.6)
+ mail (~> 2.3.3)
+ actionpack (3.1.6)
+ activemodel (= 3.1.6)
+ activesupport (= 3.1.6)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.6)
+ rack-cache (~> 1.2)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.4)
+ activemodel (3.1.6)
+ activesupport (= 3.1.6)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.6)
+ activemodel (= 3.1.6)
+ activesupport (= 3.1.6)
+ arel (~> 2.2.3)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.6)
+ activemodel (= 3.1.6)
+ activesupport (= 3.1.6)
+ activesupport (3.1.6)
+ multi_json (>= 1.0, < 1.3)
+ arel (2.2.3)
+ builder (3.0.0)
+ erubis (2.7.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ json (1.7.3)
+ mail (2.3.3)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.19)
+ multi_json (1.2.0)
+ polyglot (0.3.3)
+ rack (1.3.6)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.6)
+ actionmailer (= 3.1.6)
+ actionpack (= 3.1.6)
+ activerecord (= 3.1.6)
+ activeresource (= 3.1.6)
+ activesupport (= 3.1.6)
+ bundler (~> 1.0)
+ railties (= 3.1.6)
+ railties (3.1.6)
+ actionpack (= 3.1.6)
+ activesupport (= 3.1.6)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ ruby_parser (2.3.1)
+ sexp_processor (~> 3.0)
+ sexp_processor (3.2.0)
+ sprockets (2.0.4)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.6)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.33)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ declarative_authorization!
+ rails (~> 3.1.0)
+ rdoc
+ ruby_parser
+ sqlite3
8 gemfiles/3.2.gemfile
View
@@ -0,0 +1,8 @@
+source 'https://rubygems.org'
+
+gem 'rails', '~> 3.2.0'
+gem 'sqlite3'
+gem 'ruby_parser'
+gem 'rdoc'
+gemspec :path => '..'
+
98 gemfiles/3.2.gemfile.lock
View
@@ -0,0 +1,98 @@
+PATH
+ remote: /home/jhawthorn/code/declarative_authorization
+ specs:
+ declarative_authorization (0.5.5)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (3.2.6)
+ actionpack (= 3.2.6)
+ mail (~> 2.4.4)
+ actionpack (3.2.6)
+ activemodel (= 3.2.6)
+ activesupport (= 3.2.6)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.3)
+ activemodel (3.2.6)
+ activesupport (= 3.2.6)
+ builder (~> 3.0.0)
+ activerecord (3.2.6)
+ activemodel (= 3.2.6)
+ activesupport (= 3.2.6)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.6)
+ activemodel (= 3.2.6)
+ activesupport (= 3.2.6)
+ activesupport (3.2.6)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.2)
+ builder (3.0.0)
+ erubis (2.7.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ journey (1.0.4)
+ json (1.7.3)
+ mail (2.4.4)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.19)
+ multi_json (1.3.6)
+ polyglot (0.3.3)
+ rack (1.4.1)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.2.6)
+ actionmailer (= 3.2.6)
+ actionpack (= 3.2.6)
+ activerecord (= 3.2.6)
+ activeresource (= 3.2.6)
+ activesupport (= 3.2.6)
+ bundler (~> 1.0)
+ railties (= 3.2.6)
+ railties (3.2.6)
+ actionpack (= 3.2.6)
+ activesupport (= 3.2.6)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (>= 0.14.6, < 2.0)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ ruby_parser (2.3.1)
+ sexp_processor (~> 3.0)
+ sexp_processor (3.2.0)
+ sprockets (2.1.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.6)
+ thor (0.15.4)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.33)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ declarative_authorization!
+ rails (~> 3.2.0)
+ rdoc
+ ruby_parser
+ sqlite3
3  test/database.yml
View
@@ -0,0 +1,3 @@
+test:
+ adapter: sqlite3
+ database: ":memory:"
52 test/test_helper.rb
View
@@ -1,31 +1,24 @@
require 'test/unit'
require 'pathname'
-unless defined?(RAILS_ROOT)
- RAILS_ROOT = ENV['RAILS_ROOT'] ?
- ENV['RAILS_ROOT'] + "" :
- File.join(File.dirname(__FILE__), %w{.. .. .. ..})
+ENV['RAILS_ENV'] = 'test'
+
+require 'bundler/setup'
+begin
+ # rails 3
+ require 'rails/all'
+rescue LoadError
+ # rails 2.3
+ %w(action_pack action_controller active_record active_support initializer).each {|f| require f}
end
+Bundler.require
-unless defined?(ActiveRecord)
- if File.directory? RAILS_ROOT + '/config'
- puts 'Using config/boot.rb'
- ENV['RAILS_ENV'] = 'test'
- require File.join(RAILS_ROOT, 'config', 'environment.rb')
- else
- # simply use installed gems if available
- version_requirement = ENV['RAILS_VERSION'] ? "= #{ENV['RAILS_VERSION']}" : "> 2.1.0"
- puts "Using Rails from RubyGems (#{version_requirement || "default"})"
- require 'rubygems'
- %w{actionpack activerecord activesupport rails}.each do |gem_name|
- gem gem_name, version_requirement
- end
- end
+# rails 2.3 and ruby 1.9.3 fix
+MissingSourceFile::REGEXPS.push([/^cannot load such file -- (.+)$/i, 1])
- unless defined?(Rails) # needs to be explicit in Rails < 3
- %w(action_pack action_controller active_record active_support initializer).each {|f| require f}
- end
-end
+puts "Testing against rails #{Rails::VERSION::STRING}"
+
+RAILS_ROOT = File.dirname(__FILE__)
DA_ROOT = Pathname.new(File.expand_path("..", File.dirname(__FILE__)))
@@ -114,10 +107,25 @@ def warn?; end
end
if Rails.version < "3"
+ ActiveRecord::Base.establish_connection({:adapter => 'sqlite3', :database => ':memory:'})
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
end
else
+ class TestApp
+ class Application < ::Rails::Application
+ config.active_support.deprecation = :stderr
+ database_path = File.expand_path('../database.yml', __FILE__)
+ if Rails.version.start_with? '3.0.'
+ config.paths.config.database database_path
+ else
+ config.paths['config/database'] = database_path
+ end
+ initialize!
+ end
+ end
+ class ApplicationController < ActionController::Base
+ end
#Rails::Application.routes.draw do
Rails.application.routes.draw do
match '/name/spaced_things(/:action)' => 'name/spaced_things'
Please sign in to comment.
Something went wrong with that request. Please try again.