aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/blank_test.rb12
-rw-r--r--activesupport/test/core_ext/class/class_inheritable_attributes_test.rb16
-rw-r--r--activesupport/test/core_ext/class_test.rb10
-rw-r--r--activesupport/test/core_ext/numeric_ext_test.rb1
4 files changed, 39 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/blank_test.rb b/activesupport/test/core_ext/blank_test.rb
index 0fce470fd5..76a0b39978 100644
--- a/activesupport/test/core_ext/blank_test.rb
+++ b/activesupport/test/core_ext/blank_test.rb
@@ -3,9 +3,21 @@ require File.dirname(__FILE__) + '/../abstract_unit'
class BlankTest < Test::Unit::TestCase
BLANK = [nil, false, '', ' ', " \n\t \r ", [], {}]
NOT = [true, 0, 1, 'a', [nil], { nil => 0 }]
+
+ class EmptyObject
+ def empty?
+ true
+ end
+ alias :strip :empty?
+ end
+ class NoStripObject < EmptyObject; undef :strip; end
+ class NoEmptyStripObject < NoStripObject; undef :empty?; end
def test_blank
BLANK.each { |v| assert v.blank? }
NOT.each { |v| assert !v.blank? }
+ assert EmptyObject.new.blank?
+ assert NoStripObject.new.blank?
+ assert !NoEmptyStripObject.new.blank?
end
end
diff --git a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb b/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
index 8b11e680af..c0bb7acb3d 100644
--- a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
+++ b/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
@@ -205,4 +205,20 @@ class ClassInheritableAttributesTest < Test::Unit::TestCase
assert_equal 1, @sub.a.keys.size
assert_equal 0, @klass.a.keys.size
end
+
+ def test_reset_inheritable_attributes
+ @klass.class_inheritable_accessor :a
+ @klass.a = 'a'
+
+ @sub = eval("class Inheriting < @klass; end; Inheriting")
+
+ assert_equal 'a', @klass.a
+ assert_equal 'a', @sub.a
+
+ @klass.reset_inheritable_attributes
+ @sub = eval("class NotInheriting < @klass; end; NotInheriting")
+
+ assert_equal nil, @klass.a
+ assert_equal nil, @sub.a
+ end
end
diff --git a/activesupport/test/core_ext/class_test.rb b/activesupport/test/core_ext/class_test.rb
index bcb96f5e33..e1b38a1e07 100644
--- a/activesupport/test/core_ext/class_test.rb
+++ b/activesupport/test/core_ext/class_test.rb
@@ -33,4 +33,14 @@ class ClassTest < Test::Unit::TestCase
Class.remove_class(Y::Z::C)
assert_raises(NameError) { Y::Z::C.is_a?(Class) }
end
+
+ def test_retrieving_subclasses
+ @parent = eval("class D; end; D")
+ @sub = eval("class E < D; end; E")
+ @subofsub = eval("class F < E; end; F")
+ assert @parent.subclasses.all? { |i| [@sub.to_s, @subofsub.to_s].include?(i) }
+ assert_equal 2, @parent.subclasses.size
+ assert_equal [@subofsub.to_s], @sub.subclasses
+ assert_equal [], @subofsub.subclasses
+ end
end
diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb
index e69704878b..bbbd706aa1 100644
--- a/activesupport/test/core_ext/numeric_ext_test.rb
+++ b/activesupport/test/core_ext/numeric_ext_test.rb
@@ -104,6 +104,7 @@ end
class NumericExtSizeTest < Test::Unit::TestCase
def test_unit_in_terms_of_another
relationships = {
+ 1024.bytes => 1.kilobyte,
1024.kilobytes => 1.megabyte,
3584.0.kilobytes => 3.5.megabytes,
3584.0.megabytes => 3.5.gigabytes,