Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #149 from jhawthorn/tests

Improved test infrastructure
  • Loading branch information...
commit 0d0015b4d26dc79e01488594e7177a4f1cda552e 2 parents de590c5 + 9f0c652
@stffn authored
View
1  .gitignore
@@ -2,3 +2,4 @@ garlic.rb
garlic
nbproject
rdoc
+gemfiles/*.lock
View
17 .travis.yml
@@ -0,0 +1,17 @@
+language: ruby
+script: bundle exec rake test
+rvm:
+ - 1.8.7
+ - 1.9.2
+ - 1.9.3
+gemfile:
+ - gemfiles/2.3.gemfile
+ - gemfiles/3.0.gemfile
+ - gemfiles/3.1.gemfile
+ - gemfiles/3.2.gemfile
+matrix:
+ allow_failures:
+ - rvm: 1.9.2
+ gemfile: gemfiles/2.3.gemfile
+ - rvm: 1.9.3
+ gemfile: gemfiles/2.3.gemfile
View
24 Rakefile
@@ -2,12 +2,30 @@ 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|
- t.libs << 'lib'
+ t.libs << 'lib' << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
View
8 gemfiles/2.3.gemfile
@@ -0,0 +1,8 @@
+source 'https://rubygems.org'
+
+gem 'rails', '~> 2.3.0'
+gem 'sqlite3'
+gem 'ruby_parser'
+gem 'rdoc'
+gemspec :path => '..'
+
View
8 gemfiles/3.0.gemfile
@@ -0,0 +1,8 @@
+source 'https://rubygems.org'
+
+gem 'rails', '~> 3.0.0'
+gem 'sqlite3'
+gem 'ruby_parser'
+gem 'rdoc'
+gemspec :path => '..'
+
View
8 gemfiles/3.1.gemfile
@@ -0,0 +1,8 @@
+source 'https://rubygems.org'
+
+gem 'rails', '~> 3.1.0'
+gem 'sqlite3'
+gem 'ruby_parser'
+gem 'rdoc'
+gemspec :path => '..'
+
View
8 gemfiles/3.2.gemfile
@@ -0,0 +1,8 @@
+source 'https://rubygems.org'
+
+gem 'rails', '~> 3.2.0'
+gem 'sqlite3'
+gem 'ruby_parser'
+gem 'rdoc'
+gemspec :path => '..'
+
View
2  test/authorization_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'test_helper.rb')
+require 'test_helper'
class AuthorizationTest < Test::Unit::TestCase
View
2  test/controller_filter_resource_access_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'test_helper.rb')
+require 'test_helper'
class BasicResource < MockDataObject
def self.name
View
4 test/controller_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'test_helper.rb')
+require 'test_helper'
class LoadMockObject < MockDataObject
@@ -477,4 +477,4 @@ def test_context
request!(MockUser.new(:prohibited_role), "update", reader)
assert !@controller.authorized?
end
-end
+end
View
3  test/database.yml
@@ -0,0 +1,3 @@
+test:
+ adapter: sqlite3
+ database: ":memory:"
View
4 test/development_support/analyzer_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), %w{.. test_helper.rb})
+require 'test_helper'
auth_analyzer_loadable = false
begin
@@ -277,4 +277,4 @@ def engine_analyzer_for (rules)
end
end
-end # Authorization::Analyzer was loaded
+end # Authorization::Analyzer was loaded
View
2  test/development_support/change_analyzer_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), %w{.. test_helper.rb})
+require 'test_helper'
require File.join(File.dirname(__FILE__), %w{.. .. lib declarative_authorization development_support change_analyzer})
View
2  test/development_support/change_supporter_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), %w{.. test_helper.rb})
+require 'test_helper'
require File.join(File.dirname(__FILE__), %w{.. .. lib declarative_authorization development_support change_supporter})
View
2  test/dsl_reader_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'test_helper.rb')
+require 'test_helper'
class DSLReaderTest < Test::Unit::TestCase
def test_privileges
View
4 test/helper_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'test_helper.rb')
+require 'test_helper'
require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization helper})
@@ -244,4 +244,4 @@ def test_has_any_role_with_hierarchy
end
assert block_evaled
end
-end
+end
View
4 test/maintenance_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'test_helper.rb')
+require 'test_helper'
require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization maintenance})
class MaintenanceTest < Test::Unit::TestCase
@@ -43,4 +43,4 @@ def test_without_access_control
end
end
-end
+end
View
2  test/model_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'test_helper.rb')
+require 'test_helper'
require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization in_model})
ActiveRecord::Base.send :include, Authorization::AuthorizationInModel
View
52 test/test_helper.rb
@@ -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.