1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activesupport/test/digest_test.rb
Eugene Kenny b9e7c676ca Don't include ellipsis in truncated digest output
Using `truncate` to limit the length of the digest has the unwanted side
effect of adding an ellipsis when the input is longer than the limit.

Also:
 - Don't instantiate a new object for every digest
 - Rename the configuration option to `hash_digest_class`
 - Update the CHANGELOG entry to describe how to use the feature
2017-12-17 00:49:02 +00:00

27 lines
922 B
Ruby

# 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")[0...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