Skip to content

Commit

Permalink
fix anonymous class issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dahakawang committed Jan 19, 2013
1 parent 760b8d3 commit bc43763
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ def connection_pools

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

Expand Down
14 changes: 14 additions & 0 deletions activerecord/test/cases/connection_pool_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,20 @@ def test_automatic_reconnect=
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

0 comments on commit bc43763

Please sign in to comment.