diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-12-28 18:07:08 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-12-28 18:27:41 +0000 |
commit | dae7b6545372cba40e08554b9a7b2f391eaa5c6e (patch) | |
tree | 6035c63c71dc0243560412b08110bd7e496f8552 /activerecord/test | |
parent | 93c1f11c0a5097a5431819a1551a02a869a16a38 (diff) | |
download | rails-dae7b6545372cba40e08554b9a7b2f391eaa5c6e.tar.gz rails-dae7b6545372cba40e08554b9a7b2f391eaa5c6e.tar.bz2 rails-dae7b6545372cba40e08554b9a7b2f391eaa5c6e.zip |
Support establishing connection on ActiveRecord::Model.
This is the 'top level' connection, inherited by any models that include
ActiveRecord::Model or inherit from ActiveRecord::Base.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/base_test.rb | 19 | ||||
-rw-r--r-- | activerecord/test/cases/connection_adapters/abstract_adapter_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/connection_specification/resolver_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/inclusion_test.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/inheritance_test.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/unconnected_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/models/teapot.rb | 3 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 1 | ||||
-rw-r--r-- | activerecord/test/support/connection.rb | 6 |
9 files changed, 31 insertions, 14 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index c465e9b556..80a660717e 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -23,6 +23,7 @@ require 'models/edge' require 'models/joke' require 'models/bulb' require 'models/bird' +require 'models/teapot' require 'rexml/document' require 'active_support/core_ext/exception' require 'bcrypt' @@ -1634,10 +1635,7 @@ class BasicsTest < ActiveRecord::TestCase end def test_descends_from_active_record - # Tries to call Object.abstract_class? - assert_raise(NoMethodError) do - ActiveRecord::Base.descends_from_active_record? - end + assert !ActiveRecord::Base.descends_from_active_record? # Abstract subclass of AR::Base. assert LoosePerson.descends_from_active_record? @@ -1660,6 +1658,10 @@ class BasicsTest < ActiveRecord::TestCase # Concrete subclasses an abstract class which has a type column. assert !SubStiPost.descends_from_active_record? + + assert Teapot.descends_from_active_record? + assert !OtherTeapot.descends_from_active_record? + assert CoolTeapot.descends_from_active_record? end def test_find_on_abstract_base_class_doesnt_use_type_condition @@ -1893,4 +1895,13 @@ class BasicsTest < ActiveRecord::TestCase Bird.stubs(:scoped).returns(mock(:uniq => scope)) assert_equal scope, Bird.uniq end + + def test_active_record_super + assert_equal ActiveRecord::Model, ActiveRecord::Base.active_record_super + assert_equal ActiveRecord::Base, Topic.active_record_super + assert_equal Topic, ImportantTopic.active_record_super + assert_equal ActiveRecord::Model, Teapot.active_record_super + assert_equal Teapot, OtherTeapot.active_record_super + assert_equal ActiveRecord::Model, CoolTeapot.active_record_super + end end diff --git a/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb b/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb index 7af9079b48..7dc6e8afcb 100644 --- a/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb +++ b/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb @@ -35,7 +35,7 @@ module ActiveRecord end def test_close - pool = ConnectionPool.new(Base::ConnectionSpecification.new({}, nil)) + pool = ConnectionPool.new(ConnectionSpecification.new({}, nil)) pool.connections << adapter adapter.pool = pool diff --git a/activerecord/test/cases/connection_specification/resolver_test.rb b/activerecord/test/cases/connection_specification/resolver_test.rb index 5f9a742285..e6cb1b9521 100644 --- a/activerecord/test/cases/connection_specification/resolver_test.rb +++ b/activerecord/test/cases/connection_specification/resolver_test.rb @@ -1,7 +1,7 @@ require "cases/helper" module ActiveRecord - module Core + module ConnectionAdapters class ConnectionSpecification class ResolverTest < ActiveRecord::TestCase def resolve(spec) diff --git a/activerecord/test/cases/inclusion_test.rb b/activerecord/test/cases/inclusion_test.rb index f2c442c2e1..8726ba5e51 100644 --- a/activerecord/test/cases/inclusion_test.rb +++ b/activerecord/test/cases/inclusion_test.rb @@ -56,10 +56,13 @@ class InclusionUnitTest < ActiveRecord::TestCase def test_establish_connection assert @klass.respond_to?(:establish_connection) + assert ActiveRecord::Model.respond_to?(:establish_connection) end def test_adapter_connection - assert @klass.respond_to?("#{ActiveRecord::Base.connection_config[:adapter]}_connection") + name = "#{ActiveRecord::Base.connection_config[:adapter]}_connection" + assert @klass.respond_to?(name) + assert ActiveRecord::Model.respond_to?(name) end def test_connection_handler diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index fab858e09c..02df464469 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -65,7 +65,6 @@ class InheritanceTest < ActiveRecord::TestCase end def test_company_descends_from_active_record - assert_raise(NoMethodError) { ActiveRecord::Base.descends_from_active_record? } assert AbstractCompany.descends_from_active_record?, 'AbstractCompany should descend from ActiveRecord::Base' assert Company.descends_from_active_record?, 'Company should descend from ActiveRecord::Base' assert !Class.new(Company).descends_from_active_record?, 'Company subclass should not descend from ActiveRecord::Base' diff --git a/activerecord/test/cases/unconnected_test.rb b/activerecord/test/cases/unconnected_test.rb index e82ca3f93d..5a69054445 100644 --- a/activerecord/test/cases/unconnected_test.rb +++ b/activerecord/test/cases/unconnected_test.rb @@ -7,13 +7,13 @@ class TestUnconnectedAdapter < ActiveRecord::TestCase self.use_transactional_fixtures = false def setup - @underlying = ActiveRecord::Base.connection - @specification = ActiveRecord::Base.remove_connection + @underlying = ActiveRecord::Model.connection + @specification = ActiveRecord::Model.remove_connection end def teardown @underlying = nil - ActiveRecord::Base.establish_connection(@specification) + ActiveRecord::Model.establish_connection(@specification) load_schema if in_memory_db? end diff --git a/activerecord/test/models/teapot.rb b/activerecord/test/models/teapot.rb index ff18b6a96d..b035b18c1b 100644 --- a/activerecord/test/models/teapot.rb +++ b/activerecord/test/models/teapot.rb @@ -12,6 +12,9 @@ class Teapot include ActiveRecord::Model end +class OtherTeapot < Teapot +end + class OMFGIMATEAPOT def aaahhh "mmm" diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 8706732230..b06175cd3f 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -598,6 +598,7 @@ ActiveRecord::Schema.define do create_table :teapots, :force => true do |t| t.string :name + t.string :type t.timestamps end diff --git a/activerecord/test/support/connection.rb b/activerecord/test/support/connection.rb index 56369da346..60fea46fd3 100644 --- a/activerecord/test/support/connection.rb +++ b/activerecord/test/support/connection.rb @@ -12,9 +12,9 @@ module ARTest def self.connect puts "Using #{connection_name} with Identity Map #{ActiveRecord::IdentityMap.enabled? ? 'on' : 'off'}" - ActiveRecord::Base.logger = ActiveSupport::Logger.new("debug.log") - ActiveRecord::Base.configurations = connection_config - ActiveRecord::Base.establish_connection 'arunit' + ActiveRecord::Model.logger = ActiveSupport::Logger.new("debug.log") + ActiveRecord::Model.configurations = connection_config + ActiveRecord::Model.establish_connection 'arunit' Course.establish_connection 'arunit2' end end |