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/array_ext_test.rb34
-rw-r--r--activesupport/test/core_ext/class/attribute_accessor_test.rb8
-rw-r--r--activesupport/test/core_ext/module/attribute_accessor_test.rb6
3 files changed, 47 insertions, 1 deletions
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/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