diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-04-06 18:01:03 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-04-06 18:01:03 -0700 |
commit | 32f876786aa1eb718f122b116203b01ee0260113 (patch) | |
tree | 28506fb53e6e887a4b68250a567d1f737846fc51 /actionpack/test/controller | |
parent | 76c2ea7882a83159408bdf1f7c363f442a65c4f1 (diff) | |
download | rails-32f876786aa1eb718f122b116203b01ee0260113.tar.gz rails-32f876786aa1eb718f122b116203b01ee0260113.tar.bz2 rails-32f876786aa1eb718f122b116203b01ee0260113.zip |
getting the flash hash under test
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/flash_hash_test.rb | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/actionpack/test/controller/flash_hash_test.rb b/actionpack/test/controller/flash_hash_test.rb new file mode 100644 index 0000000000..28c338c286 --- /dev/null +++ b/actionpack/test/controller/flash_hash_test.rb @@ -0,0 +1,100 @@ +require 'abstract_unit' + +module ActionDispatch + class FlashHashTest < ActiveSupport::TestCase + def setup + @hash = Flash::FlashHash.new + end + + def test_set_get + @hash[:foo] = 'zomg' + assert_equal 'zomg', @hash[:foo] + end + + def test_keys + assert_equal [], @hash.keys + + @hash['foo'] = 'zomg' + assert_equal ['foo'], @hash.keys + + @hash['bar'] = 'zomg' + assert_equal ['foo', 'bar'].sort, @hash.keys.sort + end + + def test_update + @hash['foo'] = 'bar' + @hash.update('foo' => 'baz', 'hello' => 'world') + + assert_equal 'baz', @hash['foo'] + assert_equal 'world', @hash['hello'] + end + + def test_delete + @hash['foo'] = 'bar' + @hash.delete 'foo' + + assert !@hash.key?('foo') + assert_nil @hash['foo'] + end + + def test_to_hash + @hash['foo'] = 'bar' + assert_equal({'foo' => 'bar'}, @hash.to_hash) + + @hash.to_hash['zomg'] = 'aaron' + assert !@hash.key?('zomg') + assert_equal({'foo' => 'bar'}, @hash.to_hash) + end + + def test_empty? + assert @hash.empty? + @hash['zomg'] = 'bears' + assert !@hash.empty? + @hash.clear + assert @hash.empty? + end + + def test_each + @hash['hello'] = 'world' + @hash['foo'] = 'bar' + + things = [] + @hash.each do |k,v| + things << [k,v] + end + + assert_equal([%w{ hello world }, %w{ foo bar }].sort, things.sort) + end + + def test_replace + @hash['hello'] = 'world' + @hash.replace('omg' => 'aaron') + assert_equal({'omg' => 'aaron'}, @hash.to_hash) + end + + def test_discard_no_args + @hash['hello'] = 'world' + @hash.discard + @hash.sweep + assert_equal({}, @hash.to_hash) + end + + def test_discard_one_arg + @hash['hello'] = 'world' + @hash['omg'] = 'world' + @hash.discard 'hello' + @hash.sweep + assert_equal({'omg' => 'world'}, @hash.to_hash) + end + + def test_discard_many_args + @hash['hello'] = 'world' + @hash['<3'] = 'world' + @hash['omg'] = 'world' + + @hash.discard ['hello', 'omg'] + @hash.sweep + assert_equal({'<3' => 'world'}, @hash.to_hash) + end + end +end |