2006-07-08 14:14:49 -04:00
|
|
|
require File.dirname(__FILE__) + '/abstract_unit'
|
2006-02-01 23:54:07 -05:00
|
|
|
|
2006-09-04 02:02:16 -04:00
|
|
|
ActiveSupport::Deprecation.silence do
|
|
|
|
module ReloadableTestSandbox
|
|
|
|
class AReloadableClass
|
|
|
|
include Reloadable
|
2006-02-01 23:54:07 -05:00
|
|
|
end
|
2006-09-04 02:02:16 -04:00
|
|
|
class AReloadableClassWithSubclasses
|
|
|
|
include Reloadable
|
|
|
|
end
|
|
|
|
class AReloadableSubclass < AReloadableClassWithSubclasses
|
|
|
|
end
|
|
|
|
class ANonReloadableSubclass < AReloadableClassWithSubclasses
|
|
|
|
def self.reloadable?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class AClassWhichDefinesItsOwnReloadable
|
|
|
|
def self.reloadable?
|
|
|
|
10
|
|
|
|
end
|
|
|
|
include Reloadable
|
2006-02-01 23:54:07 -05:00
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2006-09-04 02:02:16 -04:00
|
|
|
class SubclassesReloadable
|
|
|
|
include Reloadable::Subclasses
|
|
|
|
end
|
|
|
|
class ASubclassOfSubclassesReloadable < SubclassesReloadable
|
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2006-09-04 02:02:16 -04:00
|
|
|
class AnOnlySubclassReloadableClassSubclassingAReloadableClass
|
|
|
|
include Reloadable::Subclasses
|
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2006-09-04 02:02:16 -04:00
|
|
|
class ASubclassofAOnlySubclassReloadableClassWhichWasSubclassingAReloadableClass < AnOnlySubclassReloadableClassSubclassingAReloadableClass
|
|
|
|
end
|
2006-02-02 00:41:00 -05:00
|
|
|
end
|
2006-02-01 23:54:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class ReloadableTest < Test::Unit::TestCase
|
|
|
|
def test_classes_receive_reloadable
|
|
|
|
assert ReloadableTestSandbox::AReloadableClass.respond_to?(:reloadable?)
|
|
|
|
end
|
|
|
|
def test_classes_inherit_reloadable
|
|
|
|
assert ReloadableTestSandbox::AReloadableSubclass.respond_to?(:reloadable?)
|
|
|
|
end
|
|
|
|
def test_reloadable_is_not_overwritten_if_present
|
|
|
|
assert_equal 10, ReloadableTestSandbox::AClassWhichDefinesItsOwnReloadable.reloadable?
|
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2006-02-02 00:41:00 -05:00
|
|
|
def test_only_subclass_reloadable
|
2006-09-04 02:02:16 -04:00
|
|
|
assert_deprecated_reloadable do
|
|
|
|
assert !ReloadableTestSandbox::SubclassesReloadable.reloadable?
|
|
|
|
assert ReloadableTestSandbox::ASubclassOfSubclassesReloadable.reloadable?
|
|
|
|
end
|
2006-02-02 00:41:00 -05:00
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2006-02-02 00:41:00 -05:00
|
|
|
def test_inside_hierarchy_only_subclass_reloadable
|
2006-09-04 02:02:16 -04:00
|
|
|
assert_deprecated_reloadable do
|
|
|
|
assert !ReloadableTestSandbox::AnOnlySubclassReloadableClassSubclassingAReloadableClass.reloadable?
|
|
|
|
assert ReloadableTestSandbox::ASubclassofAOnlySubclassReloadableClassWhichWasSubclassingAReloadableClass.reloadable?
|
|
|
|
end
|
2006-02-02 00:41:00 -05:00
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2006-02-01 23:54:07 -05:00
|
|
|
def test_removable_classes
|
2006-02-02 00:41:00 -05:00
|
|
|
reloadables = %w(
|
|
|
|
AReloadableClass
|
|
|
|
AReloadableClassWithSubclasses
|
|
|
|
AReloadableSubclass
|
|
|
|
AClassWhichDefinesItsOwnReloadable
|
2006-02-04 01:11:42 -05:00
|
|
|
ASubclassOfSubclassesReloadable
|
2006-02-02 00:41:00 -05:00
|
|
|
)
|
|
|
|
non_reloadables = %w(
|
|
|
|
ANonReloadableSubclass
|
2006-02-04 01:11:42 -05:00
|
|
|
SubclassesReloadable
|
2006-02-02 00:41:00 -05:00
|
|
|
)
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2006-09-04 02:02:16 -04:00
|
|
|
results = []
|
|
|
|
assert_deprecated_reloadable { results = Reloadable.reloadable_classes }
|
2006-02-01 23:54:07 -05:00
|
|
|
reloadables.each do |name|
|
|
|
|
assert results.include?(ReloadableTestSandbox.const_get(name)), "Expected #{name} to be reloadable"
|
|
|
|
end
|
|
|
|
non_reloadables.each do |name|
|
|
|
|
assert ! results.include?(ReloadableTestSandbox.const_get(name)), "Expected #{name} NOT to be reloadable"
|
|
|
|
end
|
|
|
|
end
|
2006-08-08 17:21:04 -04:00
|
|
|
|
|
|
|
def test_including_reloadable_should_warn
|
|
|
|
c = Class.new
|
2006-09-04 02:02:16 -04:00
|
|
|
assert_deprecated_reloadable do
|
2006-08-08 17:21:04 -04:00
|
|
|
c.send :include, Reloadable
|
|
|
|
end
|
|
|
|
|
2006-09-04 02:02:16 -04:00
|
|
|
assert_deprecated_reloadable { c.reloadable? }
|
2006-08-08 17:21:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_include_subclasses_should_warn
|
|
|
|
c = Class.new
|
2006-09-15 01:54:18 -04:00
|
|
|
result, deps = collect_deprecations do
|
2006-08-08 17:21:04 -04:00
|
|
|
c.send :include, Reloadable::Subclasses
|
|
|
|
end
|
|
|
|
assert_equal 1, deps.size
|
|
|
|
assert_match %r{Reloadable::Subclasses}, deps.first
|
2006-09-15 01:54:18 -04:00
|
|
|
|
2006-09-04 02:02:16 -04:00
|
|
|
assert_deprecated_reloadable { c.reloadable? }
|
2006-08-08 17:21:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_include_deprecated_should_not_warn
|
|
|
|
c = Class.new
|
2006-09-15 01:54:18 -04:00
|
|
|
result, deps = collect_deprecations do
|
2006-08-08 17:21:04 -04:00
|
|
|
c.send :include, Reloadable::Deprecated
|
|
|
|
end
|
|
|
|
assert_equal 0, deps.size
|
|
|
|
|
|
|
|
assert c.respond_to?(:reloadable?)
|
2006-09-04 02:02:16 -04:00
|
|
|
assert_deprecated_reloadable { c.reloadable? }
|
2006-08-08 17:21:04 -04:00
|
|
|
end
|
|
|
|
|
2006-09-04 02:02:16 -04:00
|
|
|
protected
|
|
|
|
def assert_deprecated_reloadable(&block)
|
|
|
|
assert_deprecated(/reloadable/, &block)
|
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
end
|