Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make multi_db compatible with Rails 3.1 #10

Merged
merged 5 commits into from
Mar 29, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/multi_db/active_record_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,4 +51,4 @@ def connection
end
end
end
end
end
6 changes: 3 additions & 3 deletions lib/multi_db/connection_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -218,4 +218,4 @@ def logger
end

end
end
end
1 change: 1 addition & 0 deletions multi_db.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
Expand Down
2 changes: 0 additions & 2 deletions spec/connection_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
ActiveRecord::Base.configurations = MULTI_DB_SPEC_CONFIG
3 changes: 1 addition & 2 deletions spec/weighted_scheduler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,4 +63,4 @@ class FooModel < ActiveRecord::Base; end
end
end
end
end
end