Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added Bundler for dependency management for running tests, updated lo…

…gger mock for Rails 3.0.0.rc
  • Loading branch information...
commit ac43f52ba9554e65c6954778a002f6572677f0a1 1 parent 0e9470e
@rsim rsim authored
Showing with 112 additions and 51 deletions.
  1. +2 −0  .gitignore
  2. +39 −0 Gemfile
  3. +15 −0 README.rdoc
  4. +56 −51 spec/spec_helper.rb
View
2  .gitignore
@@ -1,3 +1,5 @@
+.bundle
+.rvmrc
.svn
.DS_Store
coverage
View
39 Gemfile
@@ -0,0 +1,39 @@
+source 'http://rubygems.org'
+
+gem 'jeweler'
+gem 'rspec', "~> 1.3.0"
+
+if ENV['RAILS_GEM_VERSION']
+ gem 'activerecord', "=#{ENV['RAILS_GEM_VERSION']}"
+ gem 'actionpack', "=#{ENV['RAILS_GEM_VERSION']}"
+ gem 'activesupport', "=#{ENV['RAILS_GEM_VERSION']}"
+ case ENV['RAILS_GEM_VERSION']
+ when /^2.0/
+ gem 'composite_primary_keys', '=0.9.93'
+ when /^2.1/
+ gem 'composite_primary_keys', '=1.0.8'
+ when /^2.2/
+ gem 'composite_primary_keys', '=2.2.2'
+ when /^2.3.3/
+ gem 'composite_primary_keys', '=2.3.2'
+ when /^3/
+ gem 'railties', "=#{ENV['RAILS_GEM_VERSION']}"
+ end
+else
+ # uses local copy of Rails 3 and Arel gems
+ ENV['RAILS_GEM_PATH'] ||= '../rails'
+ %w(activerecord activemodel activesupport actionpack railties).each do |gem_name|
+ gem gem_name, :path => File.join(ENV['RAILS_GEM_PATH'], gem_name)
+ end
+
+ ENV['AREL_GEM_PATH'] ||= '../arel'
+ gem 'arel', :path => ENV['AREL_GEM_PATH']
+end
+
+if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby'
+ gem 'ruby-oci8', '>=2.0.4'
+elsif RUBY_ENGINE == 'jruby'
+ gem 'activerecord-jdbc-adapter'
+end
+
+gem 'ruby-plsql', '>=0.4.3'
View
15 README.rdoc
@@ -29,6 +29,21 @@ Blog posts about oracle-enahnced can be found at http://blog.rayapps.com/categor
In addition install either ruby-oci8 (for MRI/YARV) or copy Oracle JDBC driver to $JRUBY_HOME/lib (for JRuby).
+== RUNNING TESTS:
+
+It is recommended to use RVM (http://rvm.beginrescueend.com) to run tests with different Ruby implementations.
+
+* Create Oracle database schema for test purposes. Review spec/spec_helper.rb to see default schema/user names and database names (use environment variables to override defaults)
+* If you use RVM then switch to corresponding Ruby (1.8.7, 1.9.2 or JRuby) and it is recommended to create isolated gemset for test purposes (e.g. rvm create gemset oracle_enhanced)
+* Install bundler with
+ gem install bundler
+* Set RAILS_GEM_VERSION to Rails version that you would like to use in oracle_enhanced tests, e.g.
+ export RAILS_GEM_VERSION=2.3.8
+* Install necessary gems with
+ bundle install
+* Run tests with
+ rake spec
+
== LINKS
* Source code: http://github.com/rsim/oracle-enhanced
View
107 spec/spec_helper.rb
@@ -1,55 +1,48 @@
require 'rubygems'
-gem 'rspec'
-require 'spec'
+
+# Set up gems listed in the Gemfile.
+gemfile = File.expand_path('../../Gemfile', __FILE__)
+begin
+ ENV['BUNDLE_GEMFILE'] = gemfile
+ require 'bundler'
+ Bundler.setup
+rescue Bundler::GemNotFound => e
+ STDERR.puts e.message
+ STDERR.puts "Try running `bundle install`."
+ exit!
+end if File.exist?(gemfile)
$:.unshift(File.dirname(__FILE__) + '/../lib')
-if ENV['RAILS_GEM_VERSION'] =~ /^2.0/
- gem 'activerecord', '=2.0.2'
- gem 'actionpack', '=2.0.2'
- gem 'activesupport', '=2.0.2'
- gem 'composite_primary_keys', '=0.9.93'
-elsif ENV['RAILS_GEM_VERSION'] =~ /^2.1/
- gem 'activerecord', '=2.1.2'
- gem 'actionpack', '=2.1.2'
- gem 'activesupport', '=2.1.2'
- gem 'composite_primary_keys', '=1.0.8'
-elsif ENV['RAILS_GEM_VERSION'] =~ /^2.2/
- gem 'activerecord', '=2.2.2'
- gem 'actionpack', '=2.2.2'
- gem 'activesupport', '=2.2.2'
- gem 'composite_primary_keys', '=2.2.2'
-elsif ENV['RAILS_GEM_VERSION'] =~ /^2.3.3/
- gem 'activerecord', '=2.3.3'
- gem 'actionpack', '=2.3.3'
- gem 'activesupport', '=2.3.3'
- gem 'composite_primary_keys', '=2.3.2'
-elsif ENV['RAILS_GEM_VERSION'] =~ /^2.3.5/
- gem 'activerecord', '=2.3.5'
- gem 'actionpack', '=2.3.5'
- gem 'activesupport', '=2.3.5'
- NO_COMPOSITE_PRIMARY_KEYS = true
-elsif ENV['RAILS_GEM_VERSION'] =~ /^2.3/
- gem 'activerecord', '=2.3.8'
- gem 'actionpack', '=2.3.8'
- gem 'activesupport', '=2.3.8'
- NO_COMPOSITE_PRIMARY_KEYS = true
-else
- # uses local copy of Rails 3 gems
- ['rails/activerecord', 'rails/activemodel', 'rails/activesupport', 'arel', 'rails/actionpack', 'rails/railties'].each do |library|
- $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../../' + library + '/lib'))
- end
- ENV['RAILS_GEM_VERSION'] ||= '3.0'
- NO_COMPOSITE_PRIMARY_KEYS = true
+require 'spec'
+
+if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby'
+ puts "==> Running specs with MRI version #{RUBY_VERSION}"
+ require 'oci8'
+elsif RUBY_ENGINE == 'jruby'
+ puts "==> Running specs with JRuby version #{JRUBY_VERSION}"
+ require 'active_record/connection_adapters/jdbc_adapter'
end
+ENV['RAILS_GEM_VERSION'] ||= '3.0.0'
+NO_COMPOSITE_PRIMARY_KEYS = true if ENV['RAILS_GEM_VERSION'] >= '2.3.5'
+
+puts "==> Running specs with Rails version #{ENV['RAILS_GEM_VERSION']}"
+
require 'active_record'
if ENV['RAILS_GEM_VERSION'] >= '3.0'
require 'action_dispatch'
require 'active_support/core_ext/module/attribute_accessors'
- require "rails/log_subscriber"
- require 'active_record/railties/log_subscriber'
+
+ if ENV['RAILS_GEM_VERSION'] =~ /^3.0.0.beta/
+ require "rails/log_subscriber"
+ require 'active_record/railties/log_subscriber'
+ else
+ require "active_support/log_subscriber"
+ require 'active_record/log_subscriber'
+ end
+
require 'logger'
elsif ENV['RAILS_GEM_VERSION'] =~ /^2.3/
require 'action_pack'
@@ -59,13 +52,6 @@
require 'action_pack'
require 'action_controller/session/active_record_store'
end
-if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby'
- gem 'ruby-oci8', '>=2.0.4'
- require 'oci8'
-elsif RUBY_ENGINE == 'jruby'
- gem 'activerecord-jdbc-adapter'
- require 'active_record/connection_adapters/jdbc_adapter'
-end
require 'active_record/connection_adapters/oracle_enhanced_adapter'
require 'ruby-plsql'
@@ -73,18 +59,31 @@
module LoggerSpecHelper
def set_logger
@logger = MockLogger.new
+ @old_logger = ActiveRecord::Base.logger
- if ENV['RAILS_GEM_VERSION'] >= '3.0'
+ if ENV['RAILS_GEM_VERSION'] =~ /^3.0.0.beta/
queue = ActiveSupport::Notifications::Fanout.new
@notifier = ActiveSupport::Notifications::Notifier.new(queue)
Rails::LogSubscriber.colorize_logging = false
ActiveRecord::Base.logger = @logger
+ @old_notifier = ActiveSupport::Notifications.notifier
ActiveSupport::Notifications.notifier = @notifier
Rails::LogSubscriber.add(:active_record, ActiveRecord::Railties::LogSubscriber.new)
+ elsif ENV['RAILS_GEM_VERSION'] >= '3.0'
+ @notifier = ActiveSupport::Notifications::Fanout.new
+
+ ActiveSupport::LogSubscriber.colorize_logging = false
+
+ ActiveRecord::Base.logger = @logger
+ @old_notifier = ActiveSupport::Notifications.notifier
+ ActiveSupport::Notifications.notifier = @notifier
+
+ ActiveRecord::LogSubscriber.attach_to(:active_record)
+
else # ActiveRecord 2.x
if ActiveRecord::Base.respond_to?(:connection_pool)
ActiveRecord::Base.connection_pool.clear_reloadable_connections!
@@ -133,8 +132,14 @@ def clear(level)
end
def clear_logger
- ActiveRecord::Base.logger = @logger = nil
- ActiveSupport::Notifications.notifier = @notifier = nil if @notifier
+ ActiveRecord::Base.logger = @old_logger
+ @logger = nil
+
+ if ENV['RAILS_GEM_VERSION'] >= '3.0'
+ ActiveSupport::Notifications.notifier = @old_notifier
+ @notifier = nil
+ end
+
end
# Wait notifications to be published (for Rails 3.0)
Please sign in to comment.
Something went wrong with that request. Please try again.