aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-12-19 19:23:56 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-12-19 19:23:56 +0000
commit8732ce291b6048a4eb80748ea3f404f495b7104c (patch)
tree68aa08e51039022604711b29773ad2bfe334cc2e /activerecord
parent55d248ba721dc417e1e9179b3b14f11e33abfa7b (diff)
downloadrails-8732ce291b6048a4eb80748ea3f404f495b7104c.tar.gz
rails-8732ce291b6048a4eb80748ea3f404f495b7104c.tar.bz2
rails-8732ce291b6048a4eb80748ea3f404f495b7104c.zip
Subclass instantiation doesn't try to explicitly require the corresponding subclass. Closes #6840.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5751 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/associations.rb4
-rwxr-xr-xactiverecord/lib/active_record/base.rb8
-rwxr-xr-xactiverecord/test/inheritance_test.rb36
4 files changed, 41 insertions, 9 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 95cae514ac..72c599fb83 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Subclass instantiation doesn't try to explicitly require the corresponding subclass. #6840 [leei, Jeremy Kemper]
+
* fix faulty inheritance tests and that eager loading grabs the wrong inheritance column when the class of your association is an STI subclass. Closes #6859 [protocool]
* Consolidated different create and create! versions to call through to the base class with scope. This fixes inconsistencies, especially related to protected attribtues. Closes #5847 [Alexander Dymo, Tobias Luetke]
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 05eaf7b458..8a1768dba6 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -947,10 +947,6 @@ module ActiveRecord
end
end
- def require_association_class(class_name)
- require_association(Inflector.underscore(class_name)) if class_name
- end
-
def add_multiple_associated_save_callbacks(association_name)
method_name = "validate_associated_records_for_#{association_name}".to_sym
define_method(method_name) do
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 08df7e6f2e..b0ff70e5af 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1054,8 +1054,6 @@ module ActiveRecord #:nodoc:
allocate
else
- require_association_class(subclass_name)
-
# Ignore type if no column is present since it was probably
# pulled in from a sloppy join.
unless columns_hash.include?(inheritance_column)
@@ -1354,9 +1352,9 @@ module ActiveRecord #:nodoc:
def compute_type(type_name)
modularized_name = type_name_with_module(type_name)
begin
- instance_eval(modularized_name)
- rescue NameError => e
- instance_eval(type_name)
+ class_eval(modularized_name, __FILE__, __LINE__)
+ rescue NameError
+ class_eval(type_name, __FILE__, __LINE__)
end
end
diff --git a/activerecord/test/inheritance_test.rb b/activerecord/test/inheritance_test.rb
index 20f9225004..8b0d70cfa3 100755
--- a/activerecord/test/inheritance_test.rb
+++ b/activerecord/test/inheritance_test.rb
@@ -167,3 +167,39 @@ class InheritanceTest < Test::Unit::TestCase
Company.set_inheritance_column('type')
end
end
+
+
+class InheritanceComputeTypeTest < Test::Unit::TestCase
+ fixtures :companies
+
+ def setup
+ Dependencies.log_activity = true
+ end
+
+ def teardown
+ Dependencies.log_activity = false
+ self.class.const_remove :FirmOnTheFly rescue nil
+ Firm.const_remove :FirmOnTheFly rescue nil
+ end
+
+ def test_instantiation_doesnt_try_to_require_corresponding_file
+ foo = Firm.find(:first).clone
+ foo.ruby_type = foo.type = 'FirmOnTheFly'
+ foo.save!
+
+ # Should fail without FirmOnTheFly in the type condition.
+ assert_raise(ActiveRecord::RecordNotFound) { Firm.find(foo.id) }
+
+ # Nest FirmOnTheFly in the test case where Dependencies won't see it.
+ self.class.const_set :FirmOnTheFly, Class.new(Firm)
+ assert_raise(ActiveRecord::SubclassNotFound) { Firm.find(foo.id) }
+
+ # Nest FirmOnTheFly in Firm where Dependencies will see it.
+ # This is analogous to nesting models in a migration.
+ Firm.const_set :FirmOnTheFly, Class.new(Firm)
+
+ # And instantiate will find the existing constant rather than trying
+ # to require firm_on_the_fly.
+ assert_nothing_raised { assert_kind_of Firm::FirmOnTheFly, Firm.find(foo.id) }
+ end
+end