diff options
author | David <DevilDavidWang@gmail.com> | 2013-01-20 07:17:50 +0800 |
---|---|---|
committer | David <DevilDavidWang@gmail.com> | 2013-01-20 07:56:43 +0800 |
commit | bc43763247e25058ca1ab50637a649f0b5b186eb (patch) | |
tree | f6b9feeecf417f7c98e2e80c02e1b6b1610525e3 /activerecord | |
parent | 760b8d37d4628a26642d4efa571eaf104880a0ea (diff) | |
download | rails-bc43763247e25058ca1ab50637a649f0b5b186eb.tar.gz rails-bc43763247e25058ca1ab50637a649f0b5b186eb.tar.bz2 rails-bc43763247e25058ca1ab50637a649f0b5b186eb.zip |
fix anonymous class issue
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/connection_pool_test.rb | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index 27e6e8898c..3675184193 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -517,6 +517,7 @@ module ActiveRecord def establish_connection(owner, spec) @class_to_pool.clear + raise RuntimeError, "Anonymous class is not allowed." unless owner.name owner_to_pool[owner.name] = ConnectionAdapters::ConnectionPool.new(spec) end diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index 0718d0886f..ea344e992b 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/activerecord/test/cases/connection_pool_test.rb @@ -327,6 +327,20 @@ module ActiveRecord def test_pool_sets_connection_visitor assert @pool.connection.visitor.is_a?(Arel::Visitors::ToSql) end + + + #make sure exceptions are thrown when establish_connection + #is called with a anonymous class + def test_anonymous_class_exception + anonymous = Class.new(ActiveRecord::Base) + handler = ActiveRecord::Base.connection_handler + + assert_raises(RuntimeError){ + handler.establish_connection anonymous, nil + } + end + + end end end |