Methods
S
T
Instance Public methods
setup()
# File actionpack/test/controller/flash_hash_test.rb, line 5
def setup
  @hash = Flash::FlashHash.new
end
test_clear_sweep()
# File actionpack/test/controller/flash_hash_test.rb, line 165
def test_clear_sweep
  @hash['hello'] = 'world'
  @hash.clear

  @hash.sweep
  assert_equal({}, @hash.to_hash)
end
test_delete()
# File actionpack/test/controller/flash_hash_test.rb, line 41
def test_delete
  @hash['foo'] = 'bar'
  @hash.delete 'foo'

  assert !@hash.key?('foo')
  assert_nil @hash['foo']
end
test_delete_sweep()
# File actionpack/test/controller/flash_hash_test.rb, line 156
def test_delete_sweep
  @hash['hello'] = 'world'
  @hash['hi']    = 'mom'
  @hash.delete 'hi'

  @hash.sweep
  assert_equal({'hello' => 'world'}, @hash.to_hash)
end
test_discard_no_args()
# File actionpack/test/controller/flash_hash_test.rb, line 115
def test_discard_no_args
  @hash['hello'] = 'world'
  @hash.discard

  @hash.sweep
  assert_equal({}, @hash.to_hash)
end
test_discard_one_arg()
# File actionpack/test/controller/flash_hash_test.rb, line 123
def test_discard_one_arg
  @hash['hello'] = 'world'
  @hash['omg']   = 'world'
  @hash.discard 'hello'

  @hash.sweep
  assert_equal({'omg' => 'world'}, @hash.to_hash)
end
test_discard_then_add()
# File actionpack/test/controller/flash_hash_test.rb, line 181
def test_discard_then_add
  @hash['hello'] = 'world'
  @hash['omg']   = 'world'
  @hash.discard 'hello'
  @hash['hello'] = 'world'

  @hash.sweep
  assert_equal({'omg' => 'world', 'hello' => 'world'}, @hash.to_hash)
end
test_double_sweep()
# File actionpack/test/controller/flash_hash_test.rb, line 201
def test_double_sweep
  @hash['hello'] = 'world'
  @hash.sweep

  assert_equal({'hello' => 'world'}, @hash.to_hash)

  @hash.sweep
  assert_equal({}, @hash.to_hash)
end
test_each()
# File actionpack/test/controller/flash_hash_test.rb, line 97
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
test_empty?()
# File actionpack/test/controller/flash_hash_test.rb, line 89
def test_empty?
  assert @hash.empty?
  @hash['zomg'] = 'bears'
  assert !@hash.empty?
  @hash.clear
  assert @hash.empty?
end
test_from_session_value()
# File actionpack/test/controller/flash_hash_test.rb, line 72
def test_from_session_value
  rails_3_2_cookie = 'BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWY4ZTFiODE1MmJhNzYwOWMyOGJiYjE3ZWM5MjYzYmE3BjsAVEkiCmZsYXNoBjsARm86JUFjdGlvbkRpc3BhdGNoOjpGbGFzaDo6Rmxhc2hIYXNoCToKQHVzZWRvOghTZXQGOgpAaGFzaHsAOgxAY2xvc2VkRjoNQGZsYXNoZXN7BkkiDG1lc3NhZ2UGOwBGSSIKSGVsbG8GOwBGOglAbm93MA=='
  session = Marshal.load(Base64.decode64(rails_3_2_cookie))
  hash = Flash::FlashHash.from_session_value(session['flash'])
  assert_equal({'flashes' => {'message' => 'Hello'}, 'discard' => %w[message]}, hash.to_session_value)
end
test_from_session_value_on_json_serializer()
# File actionpack/test/controller/flash_hash_test.rb, line 79
def test_from_session_value_on_json_serializer
  decrypted_data = "{ \"session_id\":\"d98bdf6d129618fc2548c354c161cfb5\", \"flash\":{\"discard\":[], \"flashes\":{\"message\":\"hey you\"}} }"
  session = ActionDispatch::Cookies::JsonSerializer.load(decrypted_data)
  hash = Flash::FlashHash.from_session_value(session['flash'])

  assert_equal({'discard' => %w[message], 'flashes' => { 'message' => 'hey you'}}, hash.to_session_value)
  assert_equal "hey you", hash[:message]
  assert_equal "hey you", hash["message"]
end
test_keep_all_sweep()
# File actionpack/test/controller/flash_hash_test.rb, line 191
def test_keep_all_sweep
  @hash['hello'] = 'world'
  @hash['omg']   = 'world'
  @hash.discard 'hello'
  @hash.keep

  @hash.sweep
  assert_equal({'omg' => 'world', 'hello' => 'world'}, @hash.to_hash)
end
test_keep_sweep()
# File actionpack/test/controller/flash_hash_test.rb, line 132
def test_keep_sweep
  @hash['hello'] = 'world'

  @hash.sweep
  assert_equal({'hello' => 'world'}, @hash.to_hash)
end
test_key()
# File actionpack/test/controller/flash_hash_test.rb, line 32
def test_key
  @hash['foo'] = 'bar'

  assert @hash.key?('foo')
  assert @hash.key?(:foo)
  assert_not @hash.key?('bar')
  assert_not @hash.key?(:bar)
end
test_keys()
# File actionpack/test/controller/flash_hash_test.rb, line 14
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
test_replace()
# File actionpack/test/controller/flash_hash_test.rb, line 109
def test_replace
  @hash['hello'] = 'world'
  @hash.replace('omg' => 'aaron')
  assert_equal({'omg' => 'aaron'}, @hash.to_hash)
end
test_replace_sweep()
# File actionpack/test/controller/flash_hash_test.rb, line 173
def test_replace_sweep
  @hash['hello'] = 'world'
  @hash.replace({'hi' => 'mom'})

  @hash.sweep
  assert_equal({'hi' => 'mom'}, @hash.to_hash)
end
test_set_get()
# File actionpack/test/controller/flash_hash_test.rb, line 9
def test_set_get
  @hash[:foo] = 'zomg'
  assert_equal 'zomg', @hash[:foo]
end
test_to_hash()
# File actionpack/test/controller/flash_hash_test.rb, line 49
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
test_to_session_value()
# File actionpack/test/controller/flash_hash_test.rb, line 58
def test_to_session_value
  @hash['foo'] = 'bar'
  assert_equal({'flashes' => {'foo' => 'bar'}, 'discard' => []}, @hash.to_session_value)

  @hash.discard('foo')
  assert_equal({'flashes' => {'foo' => 'bar'}, 'discard' => %w[foo]}, @hash.to_session_value)

  @hash.now['qux'] = 1
  assert_equal({'flashes' => {'foo' => 'bar', 'qux' => 1}, 'discard' => %w[foo qux]}, @hash.to_session_value)

  @hash.sweep
  assert_equal(nil, @hash.to_session_value)
end
test_update()
# File actionpack/test/controller/flash_hash_test.rb, line 24
def test_update
  @hash['foo'] = 'bar'
  @hash.update('foo' => 'baz', 'hello' => 'world')

  assert_equal 'baz', @hash['foo']
  assert_equal 'world', @hash['hello']
end
test_update_delete_sweep()
# File actionpack/test/controller/flash_hash_test.rb, line 147
def test_update_delete_sweep
  @hash['hello'] = 'world'
  @hash.delete 'hello'
  @hash.update({'hello' => 'mom'})

  @hash.sweep
  assert_equal({'hello' => 'mom'}, @hash.to_hash)
end
test_update_sweep()
# File actionpack/test/controller/flash_hash_test.rb, line 139
def test_update_sweep
  @hash['hello'] = 'world'
  @hash.update({'hi' => 'mom'})

  @hash.sweep
  assert_equal({'hello' => 'world', 'hi' => 'mom'}, @hash.to_hash)
end