diff options
author | Dmitri Dolguikh <dmitri@appliedlogic.ca> | 2017-11-29 16:27:27 -0800 |
---|---|---|
committer | Dmitri Dolguikh <dmitri@appliedlogic.ca> | 2017-12-12 11:23:54 -0800 |
commit | 82822a34217503336d51b7baab82cd18cf71e435 (patch) | |
tree | 478fd6d03d57db8a45d0bade4eb4702850a003ed /activesupport/test | |
parent | d2aca50bbd69c7a12cdcbeaba3dbef2679927b90 (diff) | |
download | rails-82822a34217503336d51b7baab82cd18cf71e435.tar.gz rails-82822a34217503336d51b7baab82cd18cf71e435.tar.bz2 rails-82822a34217503336d51b7baab82cd18cf71e435.zip |
Introduced `ActiveSupport::Digest` that allows to specify hash function implementation
and defaults to `Digest::MD5`.
Replaced calls to `::Digest::MD5.hexdigest` with calls to `ActiveSupport::Digest.hexdigest`.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/digest_test.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/activesupport/test/digest_test.rb b/activesupport/test/digest_test.rb new file mode 100644 index 0000000000..5dec75b9fe --- /dev/null +++ b/activesupport/test/digest_test.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require "abstract_unit" +require "openssl" + +class DigestTest < ActiveSupport::TestCase + class InvalidDigest; end + def test_with_default_hash_digest_class + assert_equal ::Digest::MD5.hexdigest("hello friend"), ActiveSupport::Digest.hexdigest("hello friend") + end + + def test_with_custom_hash_digest_class + original_hash_digest_class = ActiveSupport::Digest.hash_digest_class + + ActiveSupport::Digest.hash_digest_class = ::Digest::SHA1 + digest = ActiveSupport::Digest.hexdigest("hello friend") + + assert_equal 32, digest.length + assert_equal ::Digest::SHA1.hexdigest("hello friend").truncate(32), digest + ensure + ActiveSupport::Digest.hash_digest_class = original_hash_digest_class + end + + def test_should_raise_argument_error_if_custom_digest_is_missing_hexdigest_method + assert_raises(ArgumentError) { ActiveSupport::Digest.hash_digest_class = InvalidDigest } + end +end |