aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/core_ext/class_test.rb40
-rw-r--r--activesupport/test/core_ext/object_and_class_ext_test.rb49
-rw-r--r--activesupport/test/deprecation_test.rb20
-rw-r--r--activesupport/test/descendants_tracker_test.rb8
-rw-r--r--activesupport/test/json/encoding_test.rb6
-rw-r--r--activesupport/test/multibyte_chars_test.rb41
-rw-r--r--activesupport/test/ordered_hash_test.rb1
7 files changed, 74 insertions, 91 deletions
diff --git a/activesupport/test/core_ext/class_test.rb b/activesupport/test/core_ext/class_test.rb
index b7f3dd9930..08bb13dd35 100644
--- a/activesupport/test/core_ext/class_test.rb
+++ b/activesupport/test/core_ext/class_test.rb
@@ -1,29 +1,27 @@
require 'abstract_unit'
require 'active_support/core_ext/class'
-class A
-end
+class ClassTest < Test::Unit::TestCase
+ class Parent; end
+ class Foo < Parent; end
+ class Bar < Foo; end
+ class Baz < Bar; end
-module X
- class B
- end
-end
+ class A < Parent; end
+ class B < A; end
+ class C < B; end
-module Y
- module Z
- class C
- end
+ def test_descendants
+ assert_equal [Foo, Bar, Baz, A, B, C], Parent.descendants
+ assert_equal [Bar, Baz], Foo.descendants
+ assert_equal [Baz], Bar.descendants
+ assert_equal [], Baz.descendants
end
-end
-class ClassTest < Test::Unit::TestCase
- 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_equal 2, @parent.subclasses.size
- assert_equal [@subofsub.to_s], @sub.subclasses
- assert_equal [], @subofsub.subclasses
- assert_equal [@sub.to_s, @subofsub.to_s].sort, @parent.subclasses.sort
+ def test_subclasses
+ assert_equal [Foo, A], Parent.subclasses
+ assert_equal [Bar], Foo.subclasses
+ assert_equal [Baz], Bar.subclasses
+ assert_equal [], Baz.subclasses
end
-end
+end \ No newline at end of file
diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb
index 5e03389dc2..6588f2e345 100644
--- a/activesupport/test/core_ext/object_and_class_ext_test.rb
+++ b/activesupport/test/core_ext/object_and_class_ext_test.rb
@@ -40,55 +40,6 @@ class Foo
include Bar
end
-class ClassExtTest < Test::Unit::TestCase
- def test_subclasses_of_should_find_nested_classes
- assert Class.subclasses_of(ClassK).include?(Nested::ClassL)
- end
-
- def test_subclasses_of_should_not_return_removed_classes
- # First create the removed class
- old_class = Nested.class_eval { remove_const :ClassL }
- new_class = Class.new(ClassK)
- Nested.const_set :ClassL, new_class
- assert_equal "Nested::ClassL", new_class.name # Sanity check
-
- subclasses = Class.subclasses_of(ClassK)
- assert subclasses.include?(new_class)
- assert ! subclasses.include?(old_class)
- ensure
- Nested.const_set :ClassL, old_class unless defined?(Nested::ClassL)
- end
-
- def test_subclasses_of_should_not_trigger_const_missing
- const_missing = false
- Nested.on_const_missing { const_missing = true }
-
- subclasses = Class.subclasses_of ClassK
- assert !const_missing
- assert_equal [ Nested::ClassL ], subclasses
-
- removed = Nested.class_eval { remove_const :ClassL } # keep it in memory
- subclasses = Class.subclasses_of ClassK
- assert !const_missing
- assert subclasses.empty?
- ensure
- Nested.const_set :ClassL, removed unless defined?(Nested::ClassL)
- end
-
- def test_subclasses_of_with_multiple_roots
- classes = Class.subclasses_of(ClassI, ClassK)
- assert_equal %w(ClassJ Nested::ClassL), classes.collect(&:to_s).sort
- end
-
- def test_subclasses_of_doesnt_find_anonymous_classes
- assert_equal [], Class.subclasses_of(Foo)
- bar = Class.new(Foo)
- assert_nothing_raised do
- assert_equal [bar], Class.subclasses_of(Foo)
- end
- end
-end
-
class ObjectTests < ActiveSupport::TestCase
class DuckTime
def acts_like_time?
diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb
index cf27357b32..cad0810241 100644
--- a/activesupport/test/deprecation_test.rb
+++ b/activesupport/test/deprecation_test.rb
@@ -80,6 +80,19 @@ class DeprecationTest < ActiveSupport::TestCase
assert_deprecated(/foo=nil/) { @dtc.partially }
end
+ def test_several_behaviors
+ @a, @b = nil, nil
+
+ ActiveSupport::Deprecation.behavior = [
+ Proc.new { |msg, callstack| @a = msg },
+ Proc.new { |msg, callstack| @b = msg }
+ ]
+
+ @dtc.partially
+ assert_match(/foo=nil/, @a)
+ assert_match(/foo=nil/, @b)
+ end
+
def test_deprecated_instance_variable_proxy
assert_not_deprecated { @dtc.request.size }
@@ -123,6 +136,13 @@ class DeprecationTest < ActiveSupport::TestCase
assert_equal 123, result
end
+ def test_assert_deprecated_warn_work_with_default_behavior
+ ActiveSupport::Deprecation.instance_variable_set('@behavior' , nil)
+ assert_deprecated('abc') do
+ ActiveSupport::Deprecation.warn 'abc'
+ end
+ end
+
def test_silence
ActiveSupport::Deprecation.silence do
assert_not_deprecated { @dtc.partially }
diff --git a/activesupport/test/descendants_tracker_test.rb b/activesupport/test/descendants_tracker_test.rb
index ff24e310de..79fb893592 100644
--- a/activesupport/test/descendants_tracker_test.rb
+++ b/activesupport/test/descendants_tracker_test.rb
@@ -37,7 +37,9 @@ class DescendantsTrackerTest < Test::Unit::TestCase
def test_clear_with_autoloaded_parent_children_and_granchildren
mark_as_autoloaded(*ALL) do
ActiveSupport::DescendantsTracker.clear
- assert ActiveSupport::DescendantsTracker.descendants.slice(*ALL).empty?
+ ALL.each do |k|
+ assert ActiveSupport::DescendantsTracker.descendants(k).empty?
+ end
end
end
@@ -64,12 +66,12 @@ class DescendantsTrackerTest < Test::Unit::TestCase
old_autoloaded = ActiveSupport::Dependencies.autoloaded_constants.dup
ActiveSupport::Dependencies.autoloaded_constants = klasses.map(&:name)
- old_descendants = ActiveSupport::DescendantsTracker.descendants.dup
+ old_descendants = ActiveSupport::DescendantsTracker.class_eval("@@direct_descendants").dup
old_descendants.each { |k, v| old_descendants[k] = v.dup }
yield
ensure
ActiveSupport::Dependencies.autoloaded_constants = old_autoloaded
- ActiveSupport::DescendantsTracker.descendants.replace(old_descendants)
+ ActiveSupport::DescendantsTracker.class_eval("@@direct_descendants").replace(old_descendants)
end
end \ No newline at end of file
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index a8ecf4e4cf..a679efb41e 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -1,7 +1,5 @@
# encoding: utf-8
require 'abstract_unit'
-require 'bigdecimal'
-require 'active_support/core_ext/big_decimal/conversions'
require 'active_support/json'
class TestJSONEncoding < Test::Unit::TestCase
@@ -138,6 +136,10 @@ class TestJSONEncoding < Test::Unit::TestCase
ActiveSupport.use_standard_json_time_format = false
end
+ def test_hash_with_time_to_json
+ assert_equal '{"time":"2009/01/01 00:00:00 +0000"}', { :time => Time.utc(2009) }.to_json
+ end
+
def test_nested_hash_with_float
assert_nothing_raised do
hash = {
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index 610295fa89..78232d8eb5 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -123,22 +123,30 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
assert_equal 'こに わ', @chars
end
- def test_overridden_bang_methods_return_self
- [:rstrip!, :lstrip!, :strip!, :reverse!, :upcase!, :downcase!, :capitalize!].each do |method|
- assert_equal @chars.object_id, @chars.send(method).object_id
- end
+ %w{capitalize downcase lstrip reverse rstrip strip upcase}.each do |method|
+ class_eval(<<-EOTESTS)
+ def test_#{method}_bang_should_return_self
+ assert_equal @chars.object_id, @chars.send("#{method}!").object_id
+ end
+
+ def test_#{method}_bang_should_change_wrapped_string
+ original = ' él piDió Un bUen café '
+ proxy = chars(original.dup)
+ proxy.send("#{method}!")
+ assert_not_equal original, proxy.to_s
+ end
+ EOTESTS
end
- def test_overridden_bang_methods_change_wrapped_string
- [:rstrip!, :lstrip!, :strip!, :reverse!, :upcase!, :downcase!].each do |method|
- original = ' Café '
- proxy = chars(original.dup)
- proxy.send(method)
- assert_not_equal original, proxy.to_s
- end
- proxy = chars('òu')
- proxy.capitalize!
- assert_equal 'Òu', proxy.to_s
+ def test_tidy_bytes_bang_should_return_self
+ assert_equal @chars.object_id, @chars.tidy_bytes!.object_id
+ end
+
+ def test_tidy_bytes_bang_should_change_wrapped_string
+ original = " Un bUen café \x92"
+ proxy = chars(original.dup)
+ proxy.tidy_bytes!
+ assert_not_equal original, proxy.to_s
end
if RUBY_VERSION >= '1.9'
@@ -417,8 +425,9 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
end
def test_slice_bang_removes_the_slice_from_the_receiver
- @chars.slice!(1..2)
- assert_equal 'こわ', @chars
+ chars = 'úüù'.mb_chars
+ chars.slice!(0,2)
+ assert_equal 'úü', chars
end
def test_slice_should_throw_exceptions_on_invalid_arguments
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb
index 3d1bae163f..d340bed444 100644
--- a/activesupport/test/ordered_hash_test.rb
+++ b/activesupport/test/ordered_hash_test.rb
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'active_support/json'
+require 'active_support/core_ext/object/to_json'
class OrderedHashTest < Test::Unit::TestCase
def setup