aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-03-07 01:30:29 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-03-07 01:30:29 +0000
commit5bca6290003650563bea83f3373b4774b93200f5 (patch)
treebbdea7976ba8a71f6d3f2d1e057595bab4af10ac
parent71742114f82562633eedabc3981d7b31ccee0267 (diff)
downloadrails-5bca6290003650563bea83f3373b4774b93200f5.tar.gz
rails-5bca6290003650563bea83f3373b4774b93200f5.tar.bz2
rails-5bca6290003650563bea83f3373b4774b93200f5.zip
Fixed tests for indifferent access
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@873 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb63
1 files changed, 16 insertions, 47 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 0a7a7a41b2..152ce83555 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -47,29 +47,31 @@ class HashExtTest < Test::Unit::TestCase
assert_equal @strings, @mixed.dup.stringify_keys!
end
- def test_indifferent_access
+ def test_indifferent_assorted
@strings = @strings.with_indifferent_access
@symbols = @symbols.with_indifferent_access
@mixed = @mixed.with_indifferent_access
+
+ assert_equal 'a', @strings.send(:convert_key, :a)
+
+ assert_equal 1, @strings.fetch('a')
+ assert_equal 1, @strings.fetch(:a.to_s)
+ assert_equal 1, @strings.fetch(:a)
- assert_equal @strings[:a], @strings['a']
- assert_equal @symbols[:a], @symbols['a']
- assert_equal @strings['b'], @mixed['b']
- assert_equal @strings[:b], @mixed['b']
-
hashes = { :@strings => @strings, :@symbols => @symbols, :@mixed => @mixed }
-
- method_map = { :'[]' => 1, :fetch => 1, :index => 1, :values_at => 1,
- :has_key? => true, :include? => true, :key => true,
- :member? => true }
-
+ method_map = { :'[]' => 1, :fetch => 1, :values_at => [1],
+ :has_key? => true, :include? => true, :key? => true,
+ :member? => true }
+
hashes.each do |name, hash|
method_map.sort_by { |m| m.to_s }.each do |meth, expected|
- assert_equal(expected, hash.send(meth, 'a'), "Calling #{name}.#{meth} 'a'")
- assert_equal(expected, hash.send(meth, :a), "Calling #{name}.#{meth} :a")
+ assert_equal(expected, hash.send(meth, 'a'),
+ "Calling #{name}.#{meth} 'a'")
+ assert_equal(expected, hash.send(meth, :a),
+ "Calling #{name}.#{meth} :a")
end
end
-
+
assert_equal [1, 2], @strings.values_at('a', 'b')
assert_equal [1, 2], @strings.values_at(:a, :b)
assert_equal [1, 2], @symbols.values_at('a', 'b')
@@ -91,39 +93,6 @@ class HashExtTest < Test::Unit::TestCase
assert_equal hash[3], 3
end
- def test_indifferent_assorted
- @strings = @strings.with_indifferent_access
- @symbols = @symbols.with_indifferent_access
- @mixed = @mixed.with_indifferent_access
-
- assert_equal 'a', @strings.send(:convert_key, :a)
-
- assert_equal 1, @strings.fetch('a')
- assert_equal 1, @strings.fetch(:a.to_s)
- assert_equal 1, @strings.fetch(:a)
-
- hashes = { :@strings => @strings, :@symbols => @symbols, :@mixed => @mixed }
- method_map = { :'[]' => 1, :fetch => 1, :values_at => [1],
- :has_key? => true, :include? => true, :key? => true,
- :member? => true }
-
- hashes.each do |name, hash|
- method_map.sort_by { |m| m.to_s }.each do |meth, expected|
- assert_equal(expected, hash.send(meth, 'a'),
- "Calling #{name}.#{meth} 'a'")
- assert_equal(expected, hash.send(meth, :a),
- "Calling #{name}.#{meth} :a")
- end
- end
-
- assert_equal [1, 2], @strings.values_at('a', 'b')
- assert_equal [1, 2], @strings.values_at(:a, :b)
- assert_equal [1, 2], @symbols.values_at('a', 'b')
- assert_equal [1, 2], @symbols.values_at(:a, :b)
- assert_equal [1, 2], @mixed.values_at('a', 'b')
- assert_equal [1, 2], @mixed.values_at(:a, :b)
- end
-
def test_assert_valid_keys
assert_nothing_raised do
{ :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])