indifferent_hash.rb 831 B

123456789101112131415161718192021222324252627282930313233
  1. require 'test_helper'
  2. class IndifferentHashTest < ActiveSupport::TestCase
  3. setup do
  4. @hash = Devise::IndifferentHash.new
  5. end
  6. test "it overwrites getter and setter" do
  7. @hash[:foo] = "bar"
  8. assert_equal "bar", @hash["foo"]
  9. assert_equal "bar", @hash[:foo]
  10. @hash["foo"] = "baz"
  11. assert_equal "baz", @hash["foo"]
  12. assert_equal "baz", @hash[:foo]
  13. end
  14. test "it overwrites update" do
  15. @hash.update :foo => "bar"
  16. assert_equal "bar", @hash["foo"]
  17. assert_equal "bar", @hash[:foo]
  18. @hash.update "foo" => "baz"
  19. assert_equal "baz", @hash["foo"]
  20. assert_equal "baz", @hash[:foo]
  21. end
  22. test "it returns a Hash on to_hash" do
  23. @hash[:foo] = "bar"
  24. assert_equal Hash["foo", "bar"], @hash.to_hash
  25. assert_kind_of Hash, @hash.to_hash
  26. end
  27. end if defined?(Devise::IndifferentHash)