Skip to content

Commit

Permalink
r3313@asus: jeremy | 2005-11-23 23:03:36 -0800
Browse files Browse the repository at this point in the history
 Apply [3182] to stable.  Reloading a model doesn't lose track of its connection.  Closes #2996.


git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/stable@3183 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Nov 24, 2005
1 parent 9881147 commit 1dc4783
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 19 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


* Introducing the Firebird adapter. Quote columns and use attribute_condition more consistently. Setup guide: http://wiki.rubyonrails.com/rails/pages/Firebird+Adapter #1874 [Ken Kunz <kennethkunz@gmail.com>] * Introducing the Firebird adapter. Quote columns and use attribute_condition more consistently. Setup guide: http://wiki.rubyonrails.com/rails/pages/Firebird+Adapter #1874 [Ken Kunz <kennethkunz@gmail.com>]


* Reloading a model doesn't lose track of its connection. #2996 [junk@miriamtech.com, Jeremy Kemper]

* Fixed bug where using update_attribute after pushing a record to a habtm association of the object caused duplicate rows in the join table. #2888 [colman@rominato.com, Florian Weber] * Fixed bug where using update_attribute after pushing a record to a habtm association of the object caused duplicate rows in the join table. #2888 [colman@rominato.com, Florian Weber]


* Add tasks to create, drop and rebuild the MySQL and PostgreSQL test databases. [Marcel Molina Jr.] * Add tasks to create, drop and rebuild the MySQL and PostgreSQL test databases. [Marcel Molina Jr.]
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def self.establish_connection(spec = nil)
raise AdapterNotSpecified unless defined? RAILS_ENV raise AdapterNotSpecified unless defined? RAILS_ENV
establish_connection(RAILS_ENV) establish_connection(RAILS_ENV)
when ConnectionSpecification when ConnectionSpecification
@@defined_connections[self] = spec @@defined_connections[name] = spec
when Symbol, String when Symbol, String
if configuration = configurations[spec.to_s] if configuration = configurations[spec.to_s]
establish_connection(configuration) establish_connection(configuration)
Expand Down Expand Up @@ -77,9 +77,9 @@ def self.retrieve_connection #:nodoc:
klass = self klass = self
ar_super = ActiveRecord::Base.superclass ar_super = ActiveRecord::Base.superclass
until klass == ar_super until klass == ar_super
if conn = active_connections[klass] if conn = active_connections[klass.name]
return conn return conn
elsif conn = @@defined_connections[klass] elsif conn = @@defined_connections[klass.name]
klass.connection = conn klass.connection = conn
return self.connection return self.connection
end end
Expand All @@ -92,7 +92,7 @@ def self.retrieve_connection #:nodoc:
def self.connected? def self.connected?
klass = self klass = self
until klass == ActiveRecord::Base.superclass until klass == ActiveRecord::Base.superclass
if active_connections[klass] if active_connections[klass.name]
return true return true
else else
klass = klass.superclass klass = klass.superclass
Expand All @@ -106,17 +106,17 @@ def self.connected?
# can be used as argument for establish_connection, for easy # can be used as argument for establish_connection, for easy
# re-establishing of the connection. # re-establishing of the connection.
def self.remove_connection(klass=self) def self.remove_connection(klass=self)
conn = @@defined_connections[klass] conn = @@defined_connections[klass.name]
@@defined_connections.delete(klass) @@defined_connections.delete(klass.name)
active_connections[klass] = nil active_connections[klass.name] = nil
@connection = nil @connection = nil
conn.config if conn conn.config if conn
end end


# Set the connection for the class. # Set the connection for the class.
def self.connection=(spec) def self.connection=(spec)
if spec.kind_of?(ActiveRecord::ConnectionAdapters::AbstractAdapter) if spec.kind_of?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
active_connections[self] = spec active_connections[name] = spec
elsif spec.kind_of?(ConnectionSpecification) elsif spec.kind_of?(ConnectionSpecification)
self.connection = self.send(spec.adapter_method, spec.config) self.connection = self.send(spec.adapter_method, spec.config)
elsif spec.nil? elsif spec.nil?
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/connections/native_db2/connection.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
print "Using native DB2\n" print "Using native DB2\n"
require 'fixtures/course' require_dependency 'fixtures/course'
require 'logger' require 'logger'


ActiveRecord::Base.logger = Logger.new("debug.log") ActiveRecord::Base.logger = Logger.new("debug.log")
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
print "Using native Firebird\n" print "Using native Firebird\n"
require 'fixtures/course' require_dependency 'fixtures/course'
require 'logger' require 'logger'


ActiveRecord::Base.logger = Logger.new("debug.log") ActiveRecord::Base.logger = Logger.new("debug.log")
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/connections/native_mysql/connection.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
print "Using native MySQL\n" print "Using native MySQL\n"
require 'fixtures/course' require_dependency 'fixtures/course'
require 'logger' require 'logger'


ActiveRecord::Base.logger = Logger.new("debug.log") ActiveRecord::Base.logger = Logger.new("debug.log")
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/connections/native_oci/connection.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
print "Using OCI Oracle\n" print "Using OCI Oracle\n"
require 'fixtures/course' require_dependency 'fixtures/course'
require 'logger' require 'logger'


ActiveRecord::Base.logger = Logger.new STDOUT ActiveRecord::Base.logger = Logger.new STDOUT
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
print "Using native PostgreSQL\n" print "Using native PostgreSQL\n"
require 'fixtures/course' require_dependency 'fixtures/course'
require 'logger' require 'logger'


ActiveRecord::Base.logger = Logger.new("debug.log") ActiveRecord::Base.logger = Logger.new("debug.log")
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/connections/native_sqlite/connection.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
print "Using native SQlite\n" print "Using native SQlite\n"
require 'fixtures/course' require_dependency 'fixtures/course'
require 'logger' require 'logger'
ActiveRecord::Base.logger = Logger.new("debug.log") ActiveRecord::Base.logger = Logger.new("debug.log")


Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/connections/native_sqlite3/connection.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
print "Using native SQLite3\n" print "Using native SQLite3\n"
require 'fixtures/course' require_dependency 'fixtures/course'
require 'logger' require 'logger'
ActiveRecord::Base.logger = Logger.new("debug.log") ActiveRecord::Base.logger = Logger.new("debug.log")


Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
print "Using native SQLite3\n" print "Using native SQLite3\n"
require 'fixtures/course' require_dependency 'fixtures/course'
require 'logger' require 'logger'
ActiveRecord::Base.logger = Logger.new("debug.log") ActiveRecord::Base.logger = Logger.new("debug.log")


Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
print "Using native SQLServer\n" print "Using native SQLServer\n"
require 'fixtures/course' require_dependency 'fixtures/course'
require 'logger' require 'logger'


ActiveRecord::Base.logger = Logger.new("debug.log") ActiveRecord::Base.logger = Logger.new("debug.log")
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
print "Using native SQLServer via ODBC\n" print "Using native SQLServer via ODBC\n"
require 'fixtures/course' require_dependency 'fixtures/course'
require 'logger' require 'logger'


ActiveRecord::Base.logger = Logger.new("debug.log") ActiveRecord::Base.logger = Logger.new("debug.log")
Expand Down
14 changes: 13 additions & 1 deletion activerecord/test/multiple_db_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'abstract_unit' require 'abstract_unit'
require 'fixtures/course'
require 'fixtures/entrant' require 'fixtures/entrant'


# So we can test whether Course.connection survives a reload.
require_dependency 'fixtures/course'

class MultipleDbTest < Test::Unit::TestCase class MultipleDbTest < Test::Unit::TestCase
self.use_transactional_fixtures = false self.use_transactional_fixtures = false


Expand Down Expand Up @@ -45,4 +47,14 @@ def test_associations
e3 = Entrant.find(3) e3 = Entrant.find(3)
assert_equal e3.course.id, c2.id assert_equal e3.course.id, c2.id
end end

def test_course_connection_should_survive_dependency_reload
assert Course.connection

Dependencies.clear
Object.send(:remove_const, :Course)
require_dependency 'fixtures/course'

assert Course.connection
end
end end

0 comments on commit 1dc4783

Please sign in to comment.