From 3ceb7bd768cdec589ef6cf94bf4c16b6fd201e49 Mon Sep 17 00:00:00 2001 From: Andre Duffeck Date: Fri, 12 Aug 2011 14:59:42 +0200 Subject: [PATCH 1/4] fix Rails 3.1 compatibility by getting rid of the RAILS_* constants. The specs still pass. --- lib/multi_db/connection_proxy.rb | 6 +++--- spec/connection_proxy_spec.rb | 2 -- spec/spec_helper.rb | 8 ++++++-- spec/weighted_scheduler_spec.rb | 3 +-- 4 files changed, 10 insertions(+), 9 deletions(-) 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/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 From 326488b7651de74d6c9b0c865e769e7bec658ed5 Mon Sep 17 00:00:00 2001 From: Andre Duffeck Date: Wed, 12 Oct 2011 12:02:05 +0200 Subject: [PATCH 2/4] match Rails' transaction method signature by accepting an optional options parameter In Rails 3.1 the options parameter is always sent, so transactions were completely broken until now. --- lib/multi_db/active_record_extensions.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 0545dd9d17acd5a0443035c90dbf5adab7db97e9 Mon Sep 17 00:00:00 2001 From: Nils Landt Date: Thu, 27 Oct 2011 17:46:44 +0200 Subject: [PATCH 3/4] Umlaut removed --- multi_db.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multi_db.gemspec b/multi_db.gemspec index 191462a..07917ae 100644 --- a/multi_db.gemspec +++ b/multi_db.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.version = "0.3.0" s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version= - s.authors = ["Maximilian Sch\303\266fmann"] + s.authors = ["Maximilian Schoefmann"] s.date = %q{2011-05-17} s.description = "Connection proxy for ActiveRecord for single master / multiple slave database deployments" s.email = "max@pragmatic-it.de" From a853eacc587f27dc592c2cfb1f57a4581ef491c4 Mon Sep 17 00:00:00 2001 From: Nils Landt Date: Thu, 27 Oct 2011 17:55:26 +0200 Subject: [PATCH 4/4] Specified encoding in gemspec --- multi_db.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/multi_db.gemspec b/multi_db.gemspec index 07917ae..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| @@ -5,7 +6,7 @@ Gem::Specification.new do |s| s.version = "0.3.0" s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version= - s.authors = ["Maximilian Schoefmann"] + s.authors = ["Maximilian Sch\303\266fmann"] s.date = %q{2011-05-17} s.description = "Connection proxy for ActiveRecord for single master / multiple slave database deployments" s.email = "max@pragmatic-it.de"