aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/benchmarkable_test.rb11
-rw-r--r--activesupport/test/caching_test.rb49
-rw-r--r--activesupport/test/class_cache_test.rb43
-rw-r--r--activesupport/test/configurable_test.rb22
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb5
-rw-r--r--activesupport/test/core_ext/class/attribute_accessor_test.rb11
-rw-r--r--activesupport/test/core_ext/class/attribute_test.rb6
-rw-r--r--activesupport/test/core_ext/class/class_inheritable_attributes_test.rb230
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb6
-rw-r--r--activesupport/test/core_ext/module/attr_accessor_with_default_test.rb39
-rw-r--r--activesupport/test/core_ext/module/attribute_accessor_test.rb7
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb13
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb20
-rw-r--r--activesupport/test/dependencies_test.rb2
-rw-r--r--activesupport/test/flush_cache_on_private_memoization_test.rb4
-rw-r--r--activesupport/test/inflector_test.rb86
-rw-r--r--activesupport/test/inflector_test_cases.rb3
-rw-r--r--activesupport/test/memoizable_test.rb38
-rw-r--r--activesupport/test/ordered_hash_test.rb23
-rw-r--r--activesupport/test/safe_buffer_test.rb52
-rw-r--r--activesupport/test/test_test.rb2
-rw-r--r--activesupport/test/time_zone_test.rb8
-rw-r--r--activesupport/test/whiny_nil_test.rb3
-rw-r--r--activesupport/test/xml_mini/jdom_engine_test.rb28
24 files changed, 300 insertions, 411 deletions
diff --git a/activesupport/test/benchmarkable_test.rb b/activesupport/test/benchmarkable_test.rb
index 766956f50f..06f5172e1f 100644
--- a/activesupport/test/benchmarkable_test.rb
+++ b/activesupport/test/benchmarkable_test.rb
@@ -26,17 +26,6 @@ class BenchmarkableTest < ActiveSupport::TestCase
assert_last_logged 'test_run'
end
- def test_with_message_and_deprecated_level
- i_was_run = false
-
- assert_deprecated do
- benchmark('debug_run', :debug) { i_was_run = true }
- end
-
- assert i_was_run
- assert_last_logged 'debug_run'
- end
-
def test_within_level
logger.level = ActiveSupport::BufferedLogger::DEBUG
benchmark('included_debug_run', :level => :debug) { }
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 476d55fffd..498127e5bc 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -188,6 +188,11 @@ module CacheStoreBehavior
assert_equal nil, @cache.read('foo')
end
+ def test_should_read_and_write_false
+ assert_equal true, @cache.write('foo', false)
+ assert_equal false, @cache.read('foo')
+ end
+
def test_read_multi
@cache.write('foo', 'bar')
@cache.write('fu', 'baz')
@@ -531,26 +536,6 @@ class FileStoreTest < ActiveSupport::TestCase
include CacheDeleteMatchedBehavior
include CacheIncrementDecrementBehavior
- def test_deprecated_expires_in_on_read
- ActiveSupport::Deprecation.silence do
- old_cache = ActiveSupport::Cache.lookup_store(:file_store, cache_dir)
-
- time = Time.local(2008, 4, 24)
- Time.stubs(:now).returns(time)
-
- old_cache.write("foo", "bar")
- assert_equal 'bar', old_cache.read('foo', :expires_in => 60)
-
- Time.stubs(:now).returns(time + 30)
- assert_equal 'bar', old_cache.read('foo', :expires_in => 60)
-
- Time.stubs(:now).returns(time + 61)
- assert_equal 'bar', old_cache.read('foo')
- assert_nil old_cache.read('foo', :expires_in => 60)
- assert_nil old_cache.read('foo')
- end
- end
-
def test_key_transformation
key = @cache.send(:key_file_path, "views/index?id=1")
assert_equal "views/index?id=1", @cache.send(:file_path_key, key)
@@ -628,18 +613,6 @@ class MemoryStoreTest < ActiveSupport::TestCase
end
end
-class SynchronizedStoreTest < ActiveSupport::TestCase
- def setup
- ActiveSupport::Deprecation.silence do
- @cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60)
- end
- end
-
- include CacheStoreBehavior
- include CacheDeleteMatchedBehavior
- include CacheIncrementDecrementBehavior
-end
-
uses_memcached 'memcached backed store' do
class MemCacheStoreTest < ActiveSupport::TestCase
def setup
@@ -672,18 +645,6 @@ uses_memcached 'memcached backed store' do
end
end
end
-
- class CompressedMemCacheStore < ActiveSupport::TestCase
- def setup
- ActiveSupport::Deprecation.silence do
- @cache = ActiveSupport::Cache.lookup_store(:compressed_mem_cache_store, :expires_in => 60)
- @cache.clear
- end
- end
-
- include CacheStoreBehavior
- include CacheIncrementDecrementBehavior
- end
end
class CacheStoreLoggerTest < ActiveSupport::TestCase
diff --git a/activesupport/test/class_cache_test.rb b/activesupport/test/class_cache_test.rb
index fc2d54515d..752c0ee478 100644
--- a/activesupport/test/class_cache_test.rb
+++ b/activesupport/test/class_cache_test.rb
@@ -51,20 +51,6 @@ module ActiveSupport
assert_equal @cache[ClassCacheTest], @cache.get(ClassCacheTest.name)
end
- def test_new
- assert_deprecated do
- @cache.new ClassCacheTest
- end
- assert @cache.key?(ClassCacheTest.name)
- end
-
- def test_new_rejects_strings_when_called_on_a_new_string
- assert_deprecated do
- @cache.new ClassCacheTest.name
- end
- assert !@cache.key?(ClassCacheTest.name)
- end
-
def test_new_rejects_strings
@cache.store ClassCacheTest.name
assert !@cache.key?(ClassCacheTest.name)
@@ -74,35 +60,6 @@ module ActiveSupport
x = @cache.store ClassCacheTest
assert_equal @cache, x
end
-
- def test_new_returns_proxy
- v = nil
- assert_deprecated do
- v = @cache.new ClassCacheTest.name
- end
-
- assert_deprecated do
- assert_equal ClassCacheTest, v.get
- end
- end
-
- def test_anonymous_class_fail
- assert_raises(ArgumentError) do
- assert_deprecated do
- @cache.new Class.new
- end
- end
-
- assert_raises(ArgumentError) do
- x = Class.new
- @cache[x] = x
- end
-
- assert_raises(ArgumentError) do
- x = Class.new
- @cache.store x
- end
- end
end
end
end
diff --git a/activesupport/test/configurable_test.rb b/activesupport/test/configurable_test.rb
index c6d8191298..2e5ea2c360 100644
--- a/activesupport/test/configurable_test.rb
+++ b/activesupport/test/configurable_test.rb
@@ -58,16 +58,26 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase
child = Class.new(parent)
parent.config.bar = :foo
- assert !parent.config.respond_to?(:bar)
- assert !child.config.respond_to?(:bar)
- assert !child.new.config.respond_to?(:bar)
+ assert_method_not_defined parent.config, :bar
+ assert_method_not_defined child.config, :bar
+ assert_method_not_defined child.new.config, :bar
parent.config.compile_methods!
assert_equal :foo, parent.config.bar
assert_equal :foo, child.new.config.bar
- assert_respond_to parent.config, :bar
- assert_respond_to child.config, :bar
- assert_respond_to child.new.config, :bar
+ assert_method_defined parent.config, :bar
+ assert_method_defined child.config, :bar
+ assert_method_defined child.new.config, :bar
+ end
+
+ def assert_method_defined(object, method)
+ methods = object.public_methods.map(&:to_s)
+ assert methods.include?(method.to_s), "Expected #{methods.inspect} to include #{method.to_s.inspect}"
+ end
+
+ def assert_method_not_defined(object, method)
+ methods = object.public_methods.map(&:to_s)
+ assert !methods.include?(method.to_s), "Expected #{methods.inspect} to not include #{method.to_s.inspect}"
end
end
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index 0e5407bc35..e532010b18 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -456,8 +456,9 @@ class ArrayWrapperTests < Test::Unit::TestCase
assert_equal [o], Array.wrap(o)
end
- def test_wrap_returns_nil_if_to_ary_returns_nil
- assert_nil Array.wrap(NilToAry.new)
+ def test_wrap_returns_wrapped_if_to_ary_returns_nil
+ o = NilToAry.new
+ assert_equal [o], Array.wrap(o)
end
def test_wrap_does_not_complain_if_to_ary_does_not_return_an_array
diff --git a/activesupport/test/core_ext/class/attribute_accessor_test.rb b/activesupport/test/core_ext/class/attribute_accessor_test.rb
index 456f4b7948..6b50f8db37 100644
--- a/activesupport/test/core_ext/class/attribute_accessor_test.rb
+++ b/activesupport/test/core_ext/class/attribute_accessor_test.rb
@@ -5,8 +5,9 @@ class ClassAttributeAccessorTest < Test::Unit::TestCase
def setup
@class = Class.new do
cattr_accessor :foo
- cattr_accessor :bar, :instance_writer => false
- cattr_reader :shaq, :instance_reader => false
+ cattr_accessor :bar, :instance_writer => false
+ cattr_reader :shaq, :instance_reader => false
+ cattr_accessor :camp, :instance_accessor => false
end
@object = @class.new
end
@@ -35,4 +36,10 @@ class ClassAttributeAccessorTest < Test::Unit::TestCase
assert_respond_to @class, :shaq
assert !@object.respond_to?(:shaq)
end
+
+ def test_should_not_create_instance_accessors
+ assert_respond_to @class, :camp
+ assert !@object.respond_to?(:camp)
+ assert !@object.respond_to?(:camp=)
+ end
end
diff --git a/activesupport/test/core_ext/class/attribute_test.rb b/activesupport/test/core_ext/class/attribute_test.rb
index d58b60482b..e290a6e012 100644
--- a/activesupport/test/core_ext/class/attribute_test.rb
+++ b/activesupport/test/core_ext/class/attribute_test.rb
@@ -60,6 +60,12 @@ class ClassAttributeTest < ActiveSupport::TestCase
assert_raise(NoMethodError) { object.setting = 'boom' }
end
+ test 'disabling instance reader' do
+ object = Class.new { class_attribute :setting, :instance_reader => false }.new
+ assert_raise(NoMethodError) { object.setting }
+ assert_raise(NoMethodError) { object.setting? }
+ end
+
test 'works well with singleton classes' do
object = @klass.new
object.singleton_class.setting = 'foo'
diff --git a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb b/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
deleted file mode 100644
index 020dfce56a..0000000000
--- a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
+++ /dev/null
@@ -1,230 +0,0 @@
-require 'abstract_unit'
-require 'active_support/core_ext/class/inheritable_attributes'
-
-class ClassInheritableAttributesTest < Test::Unit::TestCase
- def setup
- ActiveSupport::Deprecation.silenced = true
- @klass = Class.new
- end
-
- def teardown
- ActiveSupport::Deprecation.silenced = false
- end
-
- def test_reader_declaration
- assert_nothing_raised do
- @klass.class_inheritable_reader :a
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- end
- end
-
- def test_writer_declaration
- assert_nothing_raised do
- @klass.class_inheritable_writer :a
- assert_respond_to @klass, :a=
- assert_respond_to @klass.new, :a=
- end
- end
-
- def test_writer_declaration_without_instance_writer
- assert_nothing_raised do
- @klass.class_inheritable_writer :a, :instance_writer => false
- assert_respond_to @klass, :a=
- assert !@klass.new.respond_to?(:a=)
- end
- end
-
- def test_accessor_declaration
- assert_nothing_raised do
- @klass.class_inheritable_accessor :a
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert_respond_to @klass.new, :a=
- end
- end
-
- def test_accessor_declaration_without_instance_writer
- assert_nothing_raised do
- @klass.class_inheritable_accessor :a, :instance_writer => false
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert !@klass.new.respond_to?(:a=)
- end
- end
-
- def test_array_declaration
- assert_nothing_raised do
- @klass.class_inheritable_array :a
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert_respond_to @klass.new, :a=
- end
- end
-
- def test_array_declaration_without_instance_writer
- assert_nothing_raised do
- @klass.class_inheritable_array :a, :instance_writer => false
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert !@klass.new.respond_to?(:a=)
- end
- end
-
- def test_hash_declaration
- assert_nothing_raised do
- @klass.class_inheritable_hash :a
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert_respond_to @klass.new, :a=
- end
- end
-
- def test_hash_declaration_without_instance_writer
- assert_nothing_raised do
- @klass.class_inheritable_hash :a, :instance_writer => false
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert !@klass.new.respond_to?(:a=)
- end
- end
-
- def test_reader
- @klass.class_inheritable_reader :a
- assert_nil @klass.a
- assert_nil @klass.new.a
-
- @klass.send(:write_inheritable_attribute, :a, 'a')
-
- assert_equal 'a', @klass.a
- assert_equal 'a', @klass.new.a
- assert_equal @klass.a, @klass.new.a
- assert_equal @klass.a.object_id, @klass.new.a.object_id
- end
-
- def test_writer
- @klass.class_inheritable_reader :a
- @klass.class_inheritable_writer :a
-
- assert_nil @klass.a
- assert_nil @klass.new.a
-
- @klass.a = 'a'
- assert_equal 'a', @klass.a
- @klass.new.a = 'A'
- assert_equal 'A', @klass.a
- end
-
- def test_array
- @klass.class_inheritable_array :a
-
- assert_nil @klass.a
- assert_nil @klass.new.a
-
- @klass.a = %w(a b c)
- assert_equal %w(a b c), @klass.a
- assert_equal %w(a b c), @klass.new.a
-
- @klass.new.a = %w(A B C)
- assert_equal %w(a b c A B C), @klass.a
- assert_equal %w(a b c A B C), @klass.new.a
- end
-
- def test_hash
- @klass.class_inheritable_hash :a
-
- assert_nil @klass.a
- assert_nil @klass.new.a
-
- @klass.a = { :a => 'a' }
- assert_equal({ :a => 'a' }, @klass.a)
- assert_equal({ :a => 'a' }, @klass.new.a)
-
- @klass.new.a = { :b => 'b' }
- assert_equal({ :a => 'a', :b => 'b' }, @klass.a)
- assert_equal({ :a => 'a', :b => 'b' }, @klass.new.a)
- end
-
- def test_inheritance
- @klass.class_inheritable_accessor :a
- @klass.a = 'a'
-
- @sub = eval("class FlogMe < @klass; end; FlogMe")
-
- @klass.class_inheritable_accessor :b
-
- assert_respond_to @sub, :a
- assert_respond_to @sub, :b
- assert_equal @klass.a, @sub.a
- assert_equal @klass.b, @sub.b
- assert_equal 'a', @sub.a
- assert_nil @sub.b
-
- @klass.b = 'b'
- assert_not_equal @klass.b, @sub.b
- assert_equal 'b', @klass.b
- assert_nil @sub.b
-
- @sub.a = 'A'
- assert_not_equal @klass.a, @sub.a
- assert_equal 'a', @klass.a
- assert_equal 'A', @sub.a
-
- @sub.b = 'B'
- assert_not_equal @klass.b, @sub.b
- assert_equal 'b', @klass.b
- assert_equal 'B', @sub.b
- end
-
- def test_array_inheritance
- @klass.class_inheritable_accessor :a
- @klass.a = []
-
- @sub = eval("class SubbyArray < @klass; end; SubbyArray")
-
- assert_equal [], @klass.a
- assert_equal [], @sub.a
-
- @sub.a << :first
-
- assert_equal [:first], @sub.a
- assert_equal [], @klass.a
- end
-
- def test_array_inheritance_
- @klass.class_inheritable_accessor :a
- @klass.a = {}
-
- @sub = eval("class SubbyHash < @klass; end; SubbyHash")
-
- assert_equal Hash.new, @klass.a
- assert_equal Hash.new, @sub.a
-
- @sub.a[:first] = :first
-
- 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_nil @klass.a
- assert_nil @sub.a
- end
-end
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb
index d81693209f..b4f848cd44 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -454,4 +454,10 @@ class DateExtBehaviorTest < Test::Unit::TestCase
Date.today.freeze.inspect
end
end
+
+ def test_can_freeze_twice
+ assert_nothing_raised do
+ Date.today.freeze.freeze
+ end
+ end
end
diff --git a/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb b/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb
deleted file mode 100644
index 0ecd16b051..0000000000
--- a/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require 'abstract_unit'
-require 'active_support/core_ext/module/attr_accessor_with_default'
-
-class AttrAccessorWithDefaultTest < ActiveSupport::TestCase
- def setup
- @target = Class.new do
- def helper
- 'helper'
- end
- end
- @instance = @target.new
- end
-
- def test_default_arg
- assert_deprecated do
- @target.attr_accessor_with_default :foo, :bar
- end
- assert_equal(:bar, @instance.foo)
- @instance.foo = nil
- assert_nil(@instance.foo)
- end
-
- def test_default_proc
- assert_deprecated do
- @target.attr_accessor_with_default(:foo) {helper.upcase}
- end
- assert_equal('HELPER', @instance.foo)
- @instance.foo = nil
- assert_nil(@instance.foo)
- end
-
- def test_invalid_args
- assert_raise(ArgumentError) do
- assert_deprecated do
- @target.attr_accessor_with_default :foo
- end
- end
- end
-end
diff --git a/activesupport/test/core_ext/module/attribute_accessor_test.rb b/activesupport/test/core_ext/module/attribute_accessor_test.rb
index 118fb070a0..29889b51e0 100644
--- a/activesupport/test/core_ext/module/attribute_accessor_test.rb
+++ b/activesupport/test/core_ext/module/attribute_accessor_test.rb
@@ -7,6 +7,7 @@ class ModuleAttributeAccessorTest < Test::Unit::TestCase
mattr_accessor :foo
mattr_accessor :bar, :instance_writer => false
mattr_reader :shaq, :instance_reader => false
+ mattr_accessor :camp, :instance_accessor => false
end
@class = Class.new
@class.instance_eval { include m }
@@ -37,4 +38,10 @@ class ModuleAttributeAccessorTest < Test::Unit::TestCase
assert_respond_to @module, :shaq
assert !@object.respond_to?(:shaq)
end
+
+ def test_should_not_create_instance_accessors
+ assert_respond_to @module, :camp
+ assert !@object.respond_to?(:camp)
+ assert !@object.respond_to?(:camp=)
+ end
end
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index 32675c884a..4000cc913a 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -158,6 +158,7 @@ class StringInflectionsTest < Test::Unit::TestCase
assert_equal Time.local(2005, 2, 27, 23, 50, 19, 275038), "2005-02-27T23:50:19.275038".to_time(:local)
assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time
assert_equal Time.local_time(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time(:local)
+ assert_equal Time.utc(2039, 2, 27, 23, 50), "2039-02-27 22:50 -0100".to_time
assert_nil "".to_time
end
@@ -251,7 +252,7 @@ class StringInflectionsTest < Test::Unit::TestCase
# And changes the original string:
assert_equal original, expected
end
-
+
def test_string_inquiry
assert "production".inquiry.production?
assert !"production".inquiry.development?
@@ -353,6 +354,10 @@ class OutputSafetyTest < ActiveSupport::TestCase
test "A fixnum is safe by default" do
assert 5.html_safe?
end
+
+ test "a float is safe by default" do
+ assert 5.7.html_safe?
+ end
test "An object is unsafe by default" do
assert !@object.html_safe?
@@ -451,6 +456,12 @@ class OutputSafetyTest < ActiveSupport::TestCase
assert !'ruby'.encoding_aware?
end
end
+
+ test "call to_param returns a normal string" do
+ string = @string.html_safe
+ assert string.html_safe?
+ assert !string.to_param.html_safe?
+ end
end
class StringExcludeTest < ActiveSupport::TestCase
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index 44e02109b1..c4c4381957 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -767,6 +767,26 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal false, Time === DateTime.civil(2000)
end
+ def test_all_day
+ assert_equal Time.local(2011,6,7,0,0,0)..Time.local(2011,6,7,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).all_day
+ end
+
+ def test_all_week
+ assert_equal Time.local(2011,6,6,0,0,0)..Time.local(2011,6,12,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).all_week
+ end
+
+ def test_all_month
+ assert_equal Time.local(2011,6,1,0,0,0)..Time.local(2011,6,30,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).all_month
+ end
+
+ def test_all_quarter
+ assert_equal Time.local(2011,4,1,0,0,0)..Time.local(2011,6,30,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).all_quarter
+ end
+
+ def test_all_year
+ assert_equal Time.local(2011,1,1,0,0,0)..Time.local(2011,12,31,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).all_year
+ end
+
protected
def with_env_tz(new_tz = 'US/Eastern')
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index 2ddbce5150..b4edf0f51d 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -441,7 +441,7 @@ class DependenciesTest < Test::Unit::TestCase
with_autoloading_fixtures do
require_dependency '././counting_loader'
assert_equal 1, $counting_loaded_times
- assert_raise(ArgumentError) { ActiveSupport::Dependencies.load_missing_constant Object, :CountingLoader }
+ assert_raise(NameError) { ActiveSupport::Dependencies.load_missing_constant Object, :CountingLoader }
assert_equal 1, $counting_loaded_times
end
end
diff --git a/activesupport/test/flush_cache_on_private_memoization_test.rb b/activesupport/test/flush_cache_on_private_memoization_test.rb
index a7db96eb71..20768b777a 100644
--- a/activesupport/test/flush_cache_on_private_memoization_test.rb
+++ b/activesupport/test/flush_cache_on_private_memoization_test.rb
@@ -2,7 +2,9 @@ require 'abstract_unit'
require 'test/unit'
class FlashCacheOnPrivateMemoizationTest < Test::Unit::TestCase
- extend ActiveSupport::Memoizable
+ ActiveSupport::Deprecation.silence do
+ extend ActiveSupport::Memoizable
+ end
def test_public
assert_method_unmemoizable :pub
diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb
index 95f18126d4..b9e299af75 100644
--- a/activesupport/test/inflector_test.rb
+++ b/activesupport/test/inflector_test.rb
@@ -94,6 +94,88 @@ class InflectorTest < Test::Unit::TestCase
assert_equal('capital', ActiveSupport::Inflector.camelize('Capital', false))
end
+ def test_camelize_with_underscores
+ assert_equal("CamelCase", ActiveSupport::Inflector.camelize('Camel_Case'))
+ end
+
+ def test_acronyms
+ ActiveSupport::Inflector.inflections do |inflect|
+ inflect.acronym("API")
+ inflect.acronym("HTML")
+ inflect.acronym("HTTP")
+ inflect.acronym("RESTful")
+ inflect.acronym("W3C")
+ inflect.acronym("PhD")
+ inflect.acronym("RoR")
+ inflect.acronym("SSL")
+ end
+
+ # camelize underscore humanize titleize
+ [
+ ["API", "api", "API", "API"],
+ ["APIController", "api_controller", "API controller", "API Controller"],
+ ["Nokogiri::HTML", "nokogiri/html", "Nokogiri/HTML", "Nokogiri/HTML"],
+ ["HTTPAPI", "http_api", "HTTP API", "HTTP API"],
+ ["HTTP::Get", "http/get", "HTTP/get", "HTTP/Get"],
+ ["SSLError", "ssl_error", "SSL error", "SSL Error"],
+ ["RESTful", "restful", "RESTful", "RESTful"],
+ ["RESTfulController", "restful_controller", "RESTful controller", "RESTful Controller"],
+ ["IHeartW3C", "i_heart_w3c", "I heart W3C", "I Heart W3C"],
+ ["PhDRequired", "phd_required", "PhD required", "PhD Required"],
+ ["IRoRU", "i_ror_u", "I RoR u", "I RoR U"],
+ ["RESTfulHTTPAPI", "restful_http_api", "RESTful HTTP API", "RESTful HTTP API"],
+
+ # misdirection
+ ["Capistrano", "capistrano", "Capistrano", "Capistrano"],
+ ["CapiController", "capi_controller", "Capi controller", "Capi Controller"],
+ ["HttpsApis", "https_apis", "Https apis", "Https Apis"],
+ ["Html5", "html5", "Html5", "Html5"],
+ ["Restfully", "restfully", "Restfully", "Restfully"],
+ ["RoRails", "ro_rails", "Ro rails", "Ro Rails"]
+ ].each do |camel, under, human, title|
+ assert_equal(camel, ActiveSupport::Inflector.camelize(under))
+ assert_equal(camel, ActiveSupport::Inflector.camelize(camel))
+ assert_equal(under, ActiveSupport::Inflector.underscore(under))
+ assert_equal(under, ActiveSupport::Inflector.underscore(camel))
+ assert_equal(title, ActiveSupport::Inflector.titleize(under))
+ assert_equal(title, ActiveSupport::Inflector.titleize(camel))
+ assert_equal(human, ActiveSupport::Inflector.humanize(under))
+ end
+ end
+
+ def test_acronym_override
+ ActiveSupport::Inflector.inflections do |inflect|
+ inflect.acronym("API")
+ inflect.acronym("LegacyApi")
+ end
+
+ assert_equal("LegacyApi", ActiveSupport::Inflector.camelize("legacyapi"))
+ assert_equal("LegacyAPI", ActiveSupport::Inflector.camelize("legacy_api"))
+ assert_equal("SomeLegacyApi", ActiveSupport::Inflector.camelize("some_legacyapi"))
+ assert_equal("Nonlegacyapi", ActiveSupport::Inflector.camelize("nonlegacyapi"))
+ end
+
+ def test_acronyms_camelize_lower
+ ActiveSupport::Inflector.inflections do |inflect|
+ inflect.acronym("API")
+ inflect.acronym("HTML")
+ end
+
+ assert_equal("htmlAPI", ActiveSupport::Inflector.camelize("html_api", false))
+ assert_equal("htmlAPI", ActiveSupport::Inflector.camelize("htmlAPI", false))
+ assert_equal("htmlAPI", ActiveSupport::Inflector.camelize("HTMLAPI", false))
+ end
+
+ def test_underscore_acronym_sequence
+ ActiveSupport::Inflector.inflections do |inflect|
+ inflect.acronym("API")
+ inflect.acronym("HTML5")
+ inflect.acronym("HTML")
+ end
+
+ assert_equal("html5_html_api", ActiveSupport::Inflector.underscore("HTML5HTMLAPI"))
+ end
+
def test_underscore
CamelToUnderscore.each do |camel, underscore|
assert_equal(underscore, ActiveSupport::Inflector.underscore(camel))
@@ -148,8 +230,8 @@ class InflectorTest < Test::Unit::TestCase
end
def test_parameterize_with_custom_separator
- StringToParameterized.each do |some_string, parameterized_string|
- assert_equal(parameterized_string.gsub('-', '_'), ActiveSupport::Inflector.parameterize(some_string, '_'))
+ StringToParameterizeWithUnderscore.each do |some_string, parameterized_string|
+ assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string, '_'))
end
end
diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb
index ec9d92794c..0cb1f70657 100644
--- a/activesupport/test/inflector_test_cases.rb
+++ b/activesupport/test/inflector_test_cases.rb
@@ -168,6 +168,7 @@ module InflectorTestCases
StringToParameterizeWithNoSeparator = {
"Donald E. Knuth" => "donaldeknuth",
+ "With-some-dashes" => "with-some-dashes",
"Random text with *(bad)* characters" => "randomtextwithbadcharacters",
"Trailing bad characters!@#" => "trailingbadcharacters",
"!@#Leading bad characters" => "leadingbadcharacters",
@@ -179,6 +180,8 @@ module InflectorTestCases
StringToParameterizeWithUnderscore = {
"Donald E. Knuth" => "donald_e_knuth",
"Random text with *(bad)* characters" => "random_text_with_bad_characters",
+ "With-some-dashes" => "with-some-dashes",
+ "Retain_underscore" => "retain_underscore",
"Trailing bad characters!@#" => "trailing_bad_characters",
"!@#Leading bad characters" => "leading_bad_characters",
"Squeeze separators" => "squeeze_separators",
diff --git a/activesupport/test/memoizable_test.rb b/activesupport/test/memoizable_test.rb
index bceac1315b..e333b9a78c 100644
--- a/activesupport/test/memoizable_test.rb
+++ b/activesupport/test/memoizable_test.rb
@@ -2,7 +2,9 @@ require 'abstract_unit'
class MemoizableTest < ActiveSupport::TestCase
class Person
- extend ActiveSupport::Memoizable
+ ActiveSupport::Deprecation.silence do
+ extend ActiveSupport::Memoizable
+ end
attr_reader :name_calls, :age_calls, :is_developer_calls, :name_query_calls
@@ -65,7 +67,9 @@ class MemoizableTest < ActiveSupport::TestCase
end
module Rates
- extend ActiveSupport::Memoizable
+ ActiveSupport::Deprecation.silence do
+ extend ActiveSupport::Memoizable
+ end
attr_reader :sales_tax_calls
def sales_tax(price)
@@ -77,7 +81,9 @@ class MemoizableTest < ActiveSupport::TestCase
end
class Calculator
- extend ActiveSupport::Memoizable
+ ActiveSupport::Deprecation.silence do
+ extend ActiveSupport::Memoizable
+ end
include Rates
attr_reader :fib_calls
@@ -96,6 +102,15 @@ class MemoizableTest < ActiveSupport::TestCase
end
memoize :fib
+ def add_or_subtract(i, j, add)
+ if add
+ i + j
+ else
+ i - j
+ end
+ end
+ memoize :add_or_subtract
+
def counter
@count ||= 0
@count += 1
@@ -199,9 +214,16 @@ class MemoizableTest < ActiveSupport::TestCase
assert_equal 13, @calculator.fib_calls
end
+ def test_memoization_with_boolean_arg
+ assert_equal 4, @calculator.add_or_subtract(2, 2, true)
+ assert_equal 2, @calculator.add_or_subtract(4, 2, false)
+ end
+
def test_object_memoization
[Company.new, Company.new, Company.new].each do |company|
- company.extend ActiveSupport::Memoizable
+ ActiveSupport::Deprecation.silence do
+ company.extend ActiveSupport::Memoizable
+ end
company.memoize :name
assert_equal "37signals", company.name
@@ -235,11 +257,15 @@ class MemoizableTest < ActiveSupport::TestCase
def test_double_memoization
assert_raise(RuntimeError) { Person.memoize :name }
person = Person.new
- person.extend ActiveSupport::Memoizable
+ ActiveSupport::Deprecation.silence do
+ person.extend ActiveSupport::Memoizable
+ end
assert_raise(RuntimeError) { person.memoize :name }
company = Company.new
- company.extend ActiveSupport::Memoizable
+ ActiveSupport::Deprecation.silence do
+ company.extend ActiveSupport::Memoizable
+ end
company.memoize :name
assert_raise(RuntimeError) { company.memoize :name }
end
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb
index f3dcd7b068..bf851dbcbc 100644
--- a/activesupport/test/ordered_hash_test.rb
+++ b/activesupport/test/ordered_hash_test.rb
@@ -114,6 +114,9 @@ class OrderedHashTest < Test::Unit::TestCase
end
assert_equal @values, values
assert_equal @keys, keys
+
+ expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator
+ assert_kind_of expected_class, @ordered_hash.each_pair
end
def test_find_all
@@ -257,6 +260,26 @@ class OrderedHashTest < Test::Unit::TestCase
assert_equal @values, values
end
+ def test_each_when_yielding_to_block_with_splat
+ hash_values = []
+ ordered_hash_values = []
+
+ @hash.each { |*v| hash_values << v }
+ @ordered_hash.each { |*v| ordered_hash_values << v }
+
+ assert_equal hash_values.sort, ordered_hash_values.sort
+ end
+
+ def test_each_pair_when_yielding_to_block_with_splat
+ hash_values = []
+ ordered_hash_values = []
+
+ @hash.each_pair { |*v| hash_values << v }
+ @ordered_hash.each_pair { |*v| ordered_hash_values << v }
+
+ assert_equal hash_values.sort, ordered_hash_values.sort
+ end
+
def test_order_after_yaml_serialization
@deserialized_ordered_hash = YAML.load(YAML.dump(@ordered_hash))
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb
index a4e2acbb32..46bc0d7a34 100644
--- a/activesupport/test/safe_buffer_test.rb
+++ b/activesupport/test/safe_buffer_test.rb
@@ -4,6 +4,7 @@ begin
rescue LoadError
end
+require 'active_support/core_ext/string/inflections'
require 'yaml'
class SafeBufferTest < ActiveSupport::TestCase
@@ -45,7 +46,7 @@ class SafeBufferTest < ActiveSupport::TestCase
assert_equal ActiveSupport::SafeBuffer, new_buffer.class
end
- def test_to_yaml
+ test "Should be converted to_yaml" do
str = 'hello!'
buf = ActiveSupport::SafeBuffer.new str
yaml = buf.to_yaml
@@ -54,10 +55,57 @@ class SafeBufferTest < ActiveSupport::TestCase
assert_equal 'hello!', YAML.load(yaml)
end
- def test_nested
+ test "Should work in nested to_yaml conversion" do
str = 'hello!'
data = { 'str' => ActiveSupport::SafeBuffer.new(str) }
yaml = YAML.dump data
assert_equal({'str' => str}, YAML.load(yaml))
end
+
+ test "Should work with underscore" do
+ str = "MyTest".html_safe.underscore
+ assert_equal "my_test", str
+ end
+
+ test "Should not return safe buffer from gsub" do
+ altered_buffer = @buffer.gsub('', 'asdf')
+ assert_equal 'asdf', altered_buffer
+ assert !altered_buffer.html_safe?
+ end
+
+ test "Should not return safe buffer from gsub!" do
+ @buffer.gsub!('', 'asdf')
+ assert_equal 'asdf', @buffer
+ assert !@buffer.html_safe?
+ end
+
+ test "Should escape dirty buffers on add" do
+ dirty = @buffer
+ clean = "hello".html_safe
+ @buffer.gsub!('', '<>')
+ assert_equal "hello&lt;&gt;", clean + @buffer
+ end
+
+ test "Should concat as a normal string when dirty" do
+ dirty = @buffer
+ clean = "hello".html_safe
+ @buffer.gsub!('', '<>')
+ assert_equal "<>hello", @buffer + clean
+ end
+
+ test "Should preserve dirty? status on copy" do
+ @buffer.gsub!('', '<>')
+ assert !@buffer.dup.html_safe?
+ end
+
+ test "Should raise an error when safe_concat is called on dirty buffers" do
+ @buffer.gsub!('', '<>')
+ assert_raise ActiveSupport::SafeBuffer::SafeConcatError do
+ @buffer.safe_concat "BUSTED"
+ end
+ end
+
+ test "should not fail if the returned object is not a string" do
+ assert_kind_of NilClass, @buffer.slice("chipchop")
+ end
end
diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb
index ee5a20c789..5bd995aa32 100644
--- a/activesupport/test/test_test.rb
+++ b/activesupport/test/test_test.rb
@@ -50,7 +50,7 @@ class AssertDifferenceTest < ActiveSupport::TestCase
def test_expression_is_evaluated_in_the_appropriate_scope
silence_warnings do
- local_scope = 'foo'
+ local_scope = local_scope = 'foo'
assert_difference('local_scope; @object.num') { @object.increment }
end
end
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index 49cefc6e82..3575175517 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -224,9 +224,9 @@ class TimeZoneTest < Test::Unit::TestCase
end
def test_formatted_offset_positive
- zone = ActiveSupport::TimeZone['Moscow']
- assert_equal "+03:00", zone.formatted_offset
- assert_equal "+0300", zone.formatted_offset(false)
+ zone = ActiveSupport::TimeZone['New Delhi']
+ assert_equal "+05:30", zone.formatted_offset
+ assert_equal "+0530", zone.formatted_offset(false)
end
def test_formatted_offset_negative
@@ -257,7 +257,7 @@ class TimeZoneTest < Test::Unit::TestCase
end
def test_to_s
- assert_equal "(GMT+03:00) Moscow", ActiveSupport::TimeZone['Moscow'].to_s
+ assert_equal "(GMT+05:30) New Delhi", ActiveSupport::TimeZone['New Delhi'].to_s
end
def test_all_sorted
diff --git a/activesupport/test/whiny_nil_test.rb b/activesupport/test/whiny_nil_test.rb
index ec3ca99ee6..1acaf7228f 100644
--- a/activesupport/test/whiny_nil_test.rb
+++ b/activesupport/test/whiny_nil_test.rb
@@ -33,11 +33,10 @@ class WhinyNilTest < Test::Unit::TestCase
end
def test_id
- nil.stubs(:object_id).returns(999)
nil.id
rescue RuntimeError => nme
assert_no_match(/nil:NilClass/, nme.message)
- assert_match(/999/, nme.message)
+ assert_match(Regexp.new(nil.object_id.to_s), nme.message)
end
def test_no_to_ary_coercion
diff --git a/activesupport/test/xml_mini/jdom_engine_test.rb b/activesupport/test/xml_mini/jdom_engine_test.rb
index 3fe5e4fd78..7f809e7898 100644
--- a/activesupport/test/xml_mini/jdom_engine_test.rb
+++ b/activesupport/test/xml_mini/jdom_engine_test.rb
@@ -15,20 +15,20 @@ if RUBY_PLATFORM =~ /java/
XmlMini.backend = @default_backend
end
- # def test_file_from_xml
- # hash = Hash.from_xml(<<-eoxml)
- # <blog>
- # <logo type="file" name="logo.png" content_type="image/png">
- # </logo>
- # </blog>
- # eoxml
- # assert hash.has_key?('blog')
- # assert hash['blog'].has_key?('logo')
- #
- # file = hash['blog']['logo']
- # assert_equal 'logo.png', file.original_filename
- # assert_equal 'image/png', file.content_type
- # end
+ def test_file_from_xml
+ hash = Hash.from_xml(<<-eoxml)
+ <blog>
+ <logo type="file" name="logo.png" content_type="image/png">
+ </logo>
+ </blog>
+ eoxml
+ assert hash.has_key?('blog')
+ assert hash['blog'].has_key?('logo')
+
+ file = hash['blog']['logo']
+ assert_equal 'logo.png', file.original_filename
+ assert_equal 'image/png', file.content_type
+ end
def test_exception_thrown_on_expansion_attack
assert_raise NativeException do