mirror of
https://github.com/github/rails.git
synced 2026-01-30 00:38:00 -05:00
Update Dependencies to ignore constants inherited from ancestors. Closes #6951.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6426 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Update Dependencies to ignore constants inherited from ancestors. Closes #6951. [Nicholas Seckar]
|
||||
|
||||
* Array#to_query preserves its ordering. #7756 [Greg Spurrier]
|
||||
|
||||
* Out-of-range Time calculations transparently overflow to DateTime. Introduce Time#to_datetime. #7706, #7715 [Geoff Buesing]
|
||||
|
||||
@@ -18,4 +18,18 @@ class Module
|
||||
parents << Object unless parents.include? Object
|
||||
parents
|
||||
end
|
||||
|
||||
# Return the constants that have been defined locally by this object and not
|
||||
# in an ancestor. This method may miss some constants if their definition in
|
||||
# the ancestor is identical to their definition in the receiver.
|
||||
def local_constants
|
||||
inherited = {}
|
||||
ancestors.each do |anc|
|
||||
next if anc == self
|
||||
anc.constants.each { |const| inherited[const] = anc.const_get(const) }
|
||||
end
|
||||
constants.select do |const|
|
||||
! inherited.key?(const) || inherited[const].object_id != const_get(const).object_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -318,13 +318,13 @@ module Dependencies #:nodoc:
|
||||
watch_frames = descs.collect do |desc|
|
||||
if desc.is_a? Module
|
||||
mod_name = desc.name
|
||||
initial_constants = desc.constants
|
||||
initial_constants = desc.local_constants
|
||||
elsif desc.is_a?(String) || desc.is_a?(Symbol)
|
||||
mod_name = desc.to_s
|
||||
|
||||
# Handle the case where the module has yet to be defined.
|
||||
initial_constants = if qualified_const_defined?(mod_name)
|
||||
mod_name.constantize.constants
|
||||
mod_name.constantize.local_constants
|
||||
else
|
||||
[]
|
||||
end
|
||||
@@ -349,7 +349,7 @@ module Dependencies #:nodoc:
|
||||
|
||||
mod = mod_name.constantize
|
||||
next [] unless mod.is_a? Module
|
||||
new_constants = mod.constants - prior_constants
|
||||
new_constants = mod.local_constants - prior_constants
|
||||
|
||||
# Make sure no other frames takes credit for these constants.
|
||||
constant_watch_stack.each do |frame_name, constants|
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
require File.dirname(__FILE__) + '/../abstract_unit'
|
||||
|
||||
module One
|
||||
Constant1 = "Hello World"
|
||||
Constant2 = "What's up?"
|
||||
end
|
||||
|
||||
class Ab
|
||||
include One
|
||||
Constant1 = "Hello World" # Will have different object id than One::Constant1
|
||||
Constant3 = "Goodbye World"
|
||||
end
|
||||
|
||||
module Xy
|
||||
@@ -91,6 +95,10 @@ class ModuleTest < Test::Unit::TestCase
|
||||
assert_equal [Yz::Zy, Yz, Object], Yz::Zy::Cd.parents
|
||||
assert_equal [Yz, Object], Yz::Zy.parents
|
||||
end
|
||||
|
||||
def test_local_constants
|
||||
assert_equal %w(Constant1 Constant3), Ab.local_constants.sort
|
||||
end
|
||||
|
||||
def test_as_load_path
|
||||
assert_equal 'yz/zy', Yz::Zy.as_load_path
|
||||
|
||||
@@ -9,6 +9,10 @@ module ModuleWithMissing
|
||||
end
|
||||
end
|
||||
|
||||
module ModuleWithConstant
|
||||
InheritedConstant = "Hello"
|
||||
end
|
||||
|
||||
class DependenciesTest < Test::Unit::TestCase
|
||||
def teardown
|
||||
Dependencies.clear
|
||||
@@ -574,6 +578,13 @@ class DependenciesTest < Test::Unit::TestCase
|
||||
Object.send :remove_const, :M rescue nil
|
||||
end
|
||||
|
||||
def test_new_constants_in_with_inherited_constants
|
||||
m = Dependencies.new_constants_in(:Object) do
|
||||
Object.send :include, ModuleWithConstant
|
||||
end
|
||||
assert_equal [], m
|
||||
end
|
||||
|
||||
def test_file_with_multiple_constants_and_require_dependency
|
||||
with_loading 'autoloading_fixtures' do
|
||||
assert ! defined?(MultipleConstantFile)
|
||||
|
||||
Reference in New Issue
Block a user