Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge [5749],[5750],[5751] from trunk. References #6840.
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5752 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Dec 19, 2006
1 parent fe2e51b commit c3c7648
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*1.15.0 RC2*

* 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]

* find supports :lock with :include. Check whether your database allows SELECT ... FOR UPDATE with outer joins before using. #6764 [vitaly, Jeremy Kemper]
Expand Down
4 changes: 0 additions & 4 deletions activerecord/lib/active_record/associations.rb
Expand Up @@ -947,10 +947,6 @@ def collection_accessor_methods(reflection, association_proxy_class)
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
Expand Down
8 changes: 3 additions & 5 deletions activerecord/lib/active_record/base.rb
Expand Up @@ -1054,8 +1054,6 @@ def instantiate(record)
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)
Expand Down Expand Up @@ -1354,9 +1352,9 @@ def current_scoped_methods #: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

Expand Down
4 changes: 3 additions & 1 deletion activerecord/test/connections/native_mysql/connection.rb
Expand Up @@ -2,7 +2,9 @@
require_dependency 'fixtures/course'
require 'logger'

ActiveRecord::Base.logger = Logger.new("debug.log")
RAILS_DEFAULT_LOGGER = Logger.new('debug.log')
RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
ActiveRecord::Base.logger = RAILS_DEFAULT_LOGGER

ActiveRecord::Base.configurations = {
'arunit' => {
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/fixtures/db_definitions/mysql.sql
Expand Up @@ -37,7 +37,7 @@ CREATE TABLE `topics` (
`parent_id` int(11) default NULL,
`type` varchar(50) default NULL,
PRIMARY KEY (`id`)
) TYPE=InnoDB;
) TYPE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `developers` (
`id` int(11) NOT NULL auto_increment,
Expand Down
36 changes: 36 additions & 0 deletions activerecord/test/inheritance_test.rb
Expand Up @@ -167,3 +167,39 @@ def switch_to_default_inheritance_column
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

0 comments on commit c3c7648

Please sign in to comment.