diff --git a/lib/multi_db/active_record_extensions.rb b/lib/multi_db/active_record_extensions.rb index 4cbdd39..1e0bdde 100644 --- a/lib/multi_db/active_record_extensions.rb +++ b/lib/multi_db/active_record_extensions.rb @@ -18,7 +18,7 @@ def reload(options = nil) module ClassMethods # Make sure transactions always switch to the master - def transaction(&block) + def transaction(options = {}, &block) if self.connection.kind_of?(ConnectionProxy) super else @@ -51,4 +51,4 @@ def connection end end end -end \ No newline at end of file +end diff --git a/lib/multi_db/connection_proxy.rb b/lib/multi_db/connection_proxy.rb index ce51434..4b4e0a2 100644 --- a/lib/multi_db/connection_proxy.rb +++ b/lib/multi_db/connection_proxy.rb @@ -23,7 +23,7 @@ class ConnectionProxy class << self - # defaults to RAILS_ENV if multi_db is used with Rails + # defaults to Rails.env if multi_db is used with Rails # defaults to 'development' when used outside Rails attr_accessor :environment @@ -47,7 +47,7 @@ class << self # establishes the connections to the slaves. def setup!(scheduler = Scheduler) self.master_models ||= DEFAULT_MASTER_MODELS - self.environment ||= (defined?(RAILS_ENV) ? RAILS_ENV : 'development') + self.environment ||= (defined?(Rails) ? Rails.env : 'development') self.sticky_slave ||= false master = ActiveRecord::Base @@ -218,4 +218,4 @@ def logger end end -end \ No newline at end of file +end diff --git a/multi_db.gemspec b/multi_db.gemspec index 191462a..ba9166b 100644 --- a/multi_db.gemspec +++ b/multi_db.gemspec @@ -1,3 +1,4 @@ +# coding: utf-8 # -*- encoding: utf-8 -*- Gem::Specification.new do |s| diff --git a/spec/connection_proxy_spec.rb b/spec/connection_proxy_spec.rb index a7dfd6d..6c40bd8 100644 --- a/spec/connection_proxy_spec.rb +++ b/spec/connection_proxy_spec.rb @@ -5,8 +5,6 @@ require MULTI_DB_SPEC_DIR + '/../lib/multi_db/scheduler' require MULTI_DB_SPEC_DIR + '/../lib/multi_db/connection_proxy' -RAILS_ROOT = MULTI_DB_SPEC_DIR - describe MultiDb::ConnectionProxy do before(:all) do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0e6def1..bae44c2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,10 +2,14 @@ gem 'activerecord', '3.0.5' %w[tlattr_accessors active_record yaml erb rspec logger].each {|lib| require lib} -RAILS_ENV = ENV['RAILS_ENV'] = 'test' +module Rails + def self.env + ActiveSupport::StringInquirer.new("test") + end +end MULTI_DB_SPEC_DIR = File.dirname(__FILE__) MULTI_DB_SPEC_CONFIG = YAML::load(File.open(MULTI_DB_SPEC_DIR + '/config/database.yml')) ActiveRecord::Base.logger = Logger.new(MULTI_DB_SPEC_DIR + "/debug.log") -ActiveRecord::Base.configurations = MULTI_DB_SPEC_CONFIG \ No newline at end of file +ActiveRecord::Base.configurations = MULTI_DB_SPEC_CONFIG diff --git a/spec/weighted_scheduler_spec.rb b/spec/weighted_scheduler_spec.rb index aff074b..c8fdce8 100644 --- a/spec/weighted_scheduler_spec.rb +++ b/spec/weighted_scheduler_spec.rb @@ -6,7 +6,6 @@ require MULTI_DB_SPEC_DIR + '/../lib/multi_db/scheduler' require MULTI_DB_SPEC_DIR + '/../lib/multi_db/weighted_scheduler' -RAILS_ROOT = MULTI_DB_SPEC_DIR describe MultiDb::WeightedScheduler do before(:each) do @@ -64,4 +63,4 @@ class FooModel < ActiveRecord::Base; end end end end -end \ No newline at end of file +end