aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/misc_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-01-02 15:16:59 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-01-02 15:16:59 +0000
commitf4b721904a26f631fbc6d7241b7f9480cc87ea47 (patch)
tree17c00d0e07848e22a0ba270a93c680cff8a4faf9 /activesupport/test/misc_test.rb
parent089ef42520968c7852c97faf07e5101685885150 (diff)
downloadrails-f4b721904a26f631fbc6d7241b7f9480cc87ea47.tar.gz
rails-f4b721904a26f631fbc6d7241b7f9480cc87ea47.tar.bz2
rails-f4b721904a26f631fbc6d7241b7f9480cc87ea47.zip
Added test cases and rakefile to Active Support
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@310 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/misc_test.rb')
-rw-r--r--activesupport/test/misc_test.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/activesupport/test/misc_test.rb b/activesupport/test/misc_test.rb
new file mode 100644
index 0000000000..2a6c40709a
--- /dev/null
+++ b/activesupport/test/misc_test.rb
@@ -0,0 +1,51 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../lib/misc'
+
+class MiscTest < Test::Unit::TestCase
+ def test_silence_warnings
+ silence_warnings { assert_nil $VERBOSE }
+ assert_equal 1234, silence_warnings { 1234 }
+ end
+
+ def test_silence_warnings_verbose_invariant
+ old_verbose = $VERBOSE
+ begin
+ silence_warnings { raise }
+ flunk
+ rescue
+ assert_equal old_verbose, $VERBOSE
+ end
+ end
+end
+
+class HashOptionsTest < Test::Unit::TestCase
+ def setup
+ @strings = { 'a' => 1, 'b' => 2 }
+ @symbols = { :a => 1, :b => 2 }
+ @mixed = { :a => 1, 'b' => 2 }
+ end
+
+ def test_methods
+ h = {}
+ assert_respond_to h, :symbolize_keys
+ assert_respond_to h, :symbolize_keys!
+ assert_respond_to h, :to_options
+ assert_respond_to h, :to_options!
+ end
+
+ def test_symbolize_keys
+ assert_equal @symbols, @symbols.symbolize_keys
+ assert_equal @symbols, @strings.symbolize_keys
+ assert_equal @symbols, @mixed.symbolize_keys
+
+ assert_raises(NoMethodError) { { [] => 1 }.symbolize_keys }
+ end
+
+ def test_symbolize_keys!
+ assert_equal @symbols, @symbols.dup.symbolize_keys!
+ assert_equal @symbols, @strings.dup.symbolize_keys!
+ assert_equal @symbols, @mixed.dup.symbolize_keys!
+
+ assert_raises(NoMethodError) { { [] => 1 }.symbolize_keys! }
+ end
+end