aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/abstract_unit.rb11
-rw-r--r--activesupport/test/callback_inheritance_test.rb1
-rw-r--r--activesupport/test/callbacks_test.rb2
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb34
-rw-r--r--activesupport/test/core_ext/class/attribute_accessor_test.rb8
-rw-r--r--activesupport/test/core_ext/class/delegating_attributes_test.rb22
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb4
-rw-r--r--activesupport/test/core_ext/module/attribute_accessor_test.rb6
-rw-r--r--activesupport/test/core_ext/module_test.rb14
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb2
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb4
-rw-r--r--activesupport/test/dependencies_test.rb2
-rw-r--r--activesupport/test/flush_cache_on_private_memoization_test.rb1
-rw-r--r--activesupport/test/inflector_test_cases.rb16
-rw-r--r--activesupport/test/notifications_test.rb6
-rw-r--r--activesupport/test/ts_isolated.rb2
16 files changed, 103 insertions, 32 deletions
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb
index da338a2a26..67f652325e 100644
--- a/activesupport/test/abstract_unit.rb
+++ b/activesupport/test/abstract_unit.rb
@@ -1,10 +1,17 @@
-require File.expand_path('../../../load_paths', __FILE__)
+begin
+ old, $VERBOSE = $VERBOSE, nil
+ require File.expand_path('../../../load_paths', __FILE__)
+ensure
+ $VERBOSE = old
+end
lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
require 'test/unit'
-require 'mocha'
+require 'active_support/core_ext/kernel/reporting'
+
+silence_warnings { require 'mocha' }
ENV['NO_RELOAD'] = '1'
require 'active_support'
diff --git a/activesupport/test/callback_inheritance_test.rb b/activesupport/test/callback_inheritance_test.rb
index e74c64ba8d..8caf000c5d 100644
--- a/activesupport/test/callback_inheritance_test.rb
+++ b/activesupport/test/callback_inheritance_test.rb
@@ -1,3 +1,4 @@
+require 'abstract_unit'
require 'test/unit'
require 'active_support'
diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb
index 3fb940ad3c..49d9de63b0 100644
--- a/activesupport/test/callbacks_test.rb
+++ b/activesupport/test/callbacks_test.rb
@@ -1,4 +1,4 @@
-# require 'abstract_unit'
+require 'abstract_unit'
require 'test/unit'
require 'active_support'
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index b374eca370..aecc644549 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -4,6 +4,7 @@ require 'active_support/core_ext/big_decimal'
require 'active_support/core_ext/object/conversions'
require 'active_support/core_ext' # FIXME: pulling in all to_xml extensions
+require 'active_support/hash_with_indifferent_access'
class ArrayExtAccessTests < Test::Unit::TestCase
def test_from
@@ -294,12 +295,45 @@ class ArrayToXmlTests < Test::Unit::TestCase
end
class ArrayExtractOptionsTests < Test::Unit::TestCase
+ class HashSubclass < Hash
+ end
+
+ class ExtractableHashSubclass < Hash
+ def extractable_options?
+ true
+ end
+ end
+
def test_extract_options
assert_equal({}, [].extract_options!)
assert_equal({}, [1].extract_options!)
assert_equal({:a=>:b}, [{:a=>:b}].extract_options!)
assert_equal({:a=>:b}, [1, {:a=>:b}].extract_options!)
end
+
+ def test_extract_options_doesnt_extract_hash_subclasses
+ hash = HashSubclass.new
+ hash[:foo] = 1
+ array = [hash]
+ options = array.extract_options!
+ assert_equal({}, options)
+ assert_equal [hash], array
+ end
+
+ def test_extract_options_extracts_extractable_subclass
+ hash = ExtractableHashSubclass.new
+ hash[:foo] = 1
+ array = [hash]
+ options = array.extract_options!
+ assert_equal({:foo => 1}, options)
+ assert_equal [], array
+ end
+
+ def test_extract_options_extracts_hwia
+ hash = [{:foo => 1}.with_indifferent_access]
+ options = hash.extract_options!
+ assert_equal 1, options[:foo]
+ end
end
class ArrayUniqByTests < Test::Unit::TestCase
diff --git a/activesupport/test/core_ext/class/attribute_accessor_test.rb b/activesupport/test/core_ext/class/attribute_accessor_test.rb
index 2214ba9894..0f579d12e5 100644
--- a/activesupport/test/core_ext/class/attribute_accessor_test.rb
+++ b/activesupport/test/core_ext/class/attribute_accessor_test.rb
@@ -5,7 +5,8 @@ class ClassAttributeAccessorTest < Test::Unit::TestCase
def setup
@class = Class.new do
cattr_accessor :foo
- cattr_accessor :bar, :instance_writer => false
+ cattr_accessor :bar, :instance_writer => false
+ cattr_reader :shaq, :instance_reader => false
end
@object = @class.new
end
@@ -29,4 +30,9 @@ class ClassAttributeAccessorTest < Test::Unit::TestCase
assert @object.respond_to?(:bar)
assert !@object.respond_to?(:bar=)
end
+
+ def test_should_not_create_instance_reader
+ assert @class.respond_to?(:shaq)
+ assert !@object.respond_to?(:shaq)
+ end
end
diff --git a/activesupport/test/core_ext/class/delegating_attributes_test.rb b/activesupport/test/core_ext/class/delegating_attributes_test.rb
index 636edb8d4b..6d6cb61571 100644
--- a/activesupport/test/core_ext/class/delegating_attributes_test.rb
+++ b/activesupport/test/core_ext/class/delegating_attributes_test.rb
@@ -11,6 +11,13 @@ module DelegatingFixtures
class Mokopuna < Child
end
+
+ class PercysMom
+ superclass_delegating_accessor :superpower
+ end
+
+ class Percy < PercysMom
+ end
end
class DelegatingAttributesTest < Test::Unit::TestCase
@@ -70,18 +77,17 @@ class DelegatingAttributesTest < Test::Unit::TestCase
end
def test_delegation_stops_at_the_right_level
- assert_nil Mokopuna.some_attribute
- assert_nil Child.some_attribute
- Child.some_attribute="1"
- assert_equal "1", Mokopuna.some_attribute
- ensure
- Child.some_attribute=nil
+ assert_nil Percy.superpower
+ assert_nil PercysMom.superpower
+
+ PercysMom.superpower = :heatvision
+ assert_equal :heatvision, Percy.superpower
end
-
+
def test_delegation_stops_for_nil
Mokopuna.some_attribute = nil
Child.some_attribute="1"
-
+
assert_equal "1", Child.some_attribute
assert_nil Mokopuna.some_attribute
ensure
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 5b1d53ac7b..86272a28c1 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -757,6 +757,7 @@ class HashToXmlTest < Test::Unit::TestCase
<expires-at type="dateTime">2007-12-25T12:34:56+0000</expires-at>
<notes type="string"></notes>
<illustration type="base64Binary">YmFiZS5wbmc=</illustration>
+ <caption type="binary" encoding="base64">VGhhdCdsbCBkbywgcGlnLg==</caption>
</bacon>
EOT
@@ -766,7 +767,8 @@ class HashToXmlTest < Test::Unit::TestCase
:price => BigDecimal("12.50"),
:expires_at => Time.utc(2007,12,25,12,34,56),
:notes => "",
- :illustration => "babe.png"
+ :illustration => "babe.png",
+ :caption => "That'll do, pig."
}.stringify_keys
assert_equal expected_bacon_hash, Hash.from_xml(bacon_xml)["bacon"]
diff --git a/activesupport/test/core_ext/module/attribute_accessor_test.rb b/activesupport/test/core_ext/module/attribute_accessor_test.rb
index bd9461e62c..263e78feaa 100644
--- a/activesupport/test/core_ext/module/attribute_accessor_test.rb
+++ b/activesupport/test/core_ext/module/attribute_accessor_test.rb
@@ -6,6 +6,7 @@ class ModuleAttributeAccessorTest < Test::Unit::TestCase
m = @module = Module.new do
mattr_accessor :foo
mattr_accessor :bar, :instance_writer => false
+ mattr_reader :shaq, :instance_reader => false
end
@class = Class.new
@class.instance_eval { include m }
@@ -31,4 +32,9 @@ class ModuleAttributeAccessorTest < Test::Unit::TestCase
assert @object.respond_to?(:bar)
assert !@object.respond_to?(:bar=)
end
+
+ def test_should_not_create_instance_reader
+ assert @module.respond_to?(:shaq)
+ assert !@object.respond_to?(:shaq)
+ end
end
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb
index 9edd7cc7c0..1712b0649b 100644
--- a/activesupport/test/core_ext/module_test.rb
+++ b/activesupport/test/core_ext/module_test.rb
@@ -141,6 +141,20 @@ class ModuleTest < Test::Unit::TestCase
assert_equal 0.0, nil_project.to_f
end
+ def test_delegation_does_not_raise_error_when_removing_singleton_instance_methods
+ parent = Class.new do
+ def self.parent_method; end
+ end
+
+ assert_nothing_raised do
+ child = Class.new(parent) do
+ class << self
+ delegate :parent_method, :to => :superclass
+ end
+ end
+ end
+ end
+
def test_parent
assert_equal Yz::Zy, Yz::Zy::Cd.parent
assert_equal Yz, Yz::Zy.parent
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index a50e259726..234e41c772 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -285,7 +285,7 @@ class TestGetTextString < Test::Unit::TestCase
def test_percent
assert_equal("% 1", "%% %<num>d" % {:num => 1.0})
- assert_equal("%{num} %<num>d", "%%{num} %%<num>d" % {:num => 1})
+ assert_equal("%{num} %<num>d 1", "%%{num} %%<num>d %<num>d" % {:num => 1})
end
def test_sprintf_percent_in_replacement
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index 08c079e113..159b7d8366 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -761,7 +761,7 @@ class TimeExtMarshalingTest < Test::Unit::TestCase
marshaled = Marshal.dump t
unmarshaled = Marshal.load marshaled
assert_equal t, unmarshaled
- assert_equal t.zone, unmarshaled.zone
+ assert_equal "UTC", unmarshaled.zone
end
def test_marshaling_with_local_instance
@@ -777,7 +777,7 @@ class TimeExtMarshalingTest < Test::Unit::TestCase
marshaled = Marshal.dump t
unmarshaled = Marshal.load marshaled
assert_equal t, unmarshaled
- assert_equal t.zone, unmarshaled.zone
+ assert_equal "UTC", unmarshaled.zone
end
def test_marshaling_with_frozen_local_instance
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index 6ff6dfb607..2cbf9e5042 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -88,7 +88,7 @@ class DependenciesTest < Test::Unit::TestCase
old_warnings, ActiveSupport::Dependencies.warnings_on_first_load = ActiveSupport::Dependencies.warnings_on_first_load, true
filename = "check_warnings"
- expanded = File.expand_path("test/dependencies/#{filename}")
+ expanded = File.expand_path("#{File.dirname(__FILE__)}/dependencies/#{filename}")
$check_warnings_load_count = 0
assert !ActiveSupport::Dependencies.loaded.include?(expanded)
diff --git a/activesupport/test/flush_cache_on_private_memoization_test.rb b/activesupport/test/flush_cache_on_private_memoization_test.rb
index 1cd313ec81..91b856ed7c 100644
--- a/activesupport/test/flush_cache_on_private_memoization_test.rb
+++ b/activesupport/test/flush_cache_on_private_memoization_test.rb
@@ -1,3 +1,4 @@
+require 'abstract_unit'
require 'active_support'
require 'test/unit'
diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb
index ebd26d3fc6..56372903f3 100644
--- a/activesupport/test/inflector_test_cases.rb
+++ b/activesupport/test/inflector_test_cases.rb
@@ -180,18 +180,10 @@ module InflectorTestCases
"Test with + sign" => "test_with_sign"
}
- # Ruby 1.9 doesn't do Unicode normalization yet.
- if RUBY_VERSION >= '1.9'
- StringToParameterizedAndNormalized = {
- "Malmö" => "malm",
- "Garçons" => "gar-ons"
- }
- else
- StringToParameterizedAndNormalized = {
- "Malmö" => "malmo",
- "Garçons" => "garcons"
- }
- end
+ StringToParameterizedAndNormalized = {
+ "Malmö" => "malmo",
+ "Garçons" => "garcons"
+ }
UnderscoreToHuman = {
"employee_salary" => "Employee salary",
diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb
index 67c3527e23..92fbe5b92f 100644
--- a/activesupport/test/notifications_test.rb
+++ b/activesupport/test/notifications_test.rb
@@ -65,7 +65,7 @@ module Notifications
assert_equal [[:foo]] * 4, @events
end
- def test_log_subscriber_with_pattern
+ def test_log_subscriber_with_string
events = []
@notifier.subscribe('1') { |*args| events << args }
@@ -74,10 +74,10 @@ module Notifications
@notifier.publish 'a.1'
@notifier.wait
- assert_equal [['1'], ['1.a']], events
+ assert_equal [['1']], events
end
- def test_log_subscriber_with_pattern_as_regexp
+ def test_log_subscriber_with_pattern
events = []
@notifier.subscribe(/\d/) { |*args| events << args }
diff --git a/activesupport/test/ts_isolated.rb b/activesupport/test/ts_isolated.rb
index cbab61a523..58710e0165 100644
--- a/activesupport/test/ts_isolated.rb
+++ b/activesupport/test/ts_isolated.rb
@@ -1,3 +1,5 @@
+$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
+
require 'test/unit'
require 'rbconfig'
require 'active_support/core_ext/kernel/reporting'