From dea3b1b58e8d23d70a074470c13fc8c649fc7c65 Mon Sep 17 00:00:00 2001 From: Matt Rogers Date: Fri, 19 Oct 2018 09:25:15 -0500 Subject: [PATCH] Update to a more performant random string implementation Since `SecureRandom.alphanumeric` is Ruby 2.5 only, we can't use that for now. Implement a new version until we can get Tracks updated to that version. --- test/test_helper.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index d0e82d8f..9c5aa0ac 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,7 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' +require 'securerandom' # set config for tests. Overwrite those read from config/site.yml. Use inject to avoid warning about changing CONSTANT { @@ -10,6 +11,7 @@ require 'rails/test_help' "time_zone" => "Amsterdam" # force UTC+1 so Travis triggers time zone failures }.inject( SITE_CONFIG ) { |h, elem| h[elem[0]] = elem[1]; h } + class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. # @@ -38,13 +40,8 @@ class ActiveSupport::TestCase # for validation purposes # def generate_random_string(length) - string = "" - characters = %w(a b c d e f g h i j k l m n o p q r s t u v w z y z 1\ 0) - length.times do - pick = characters[rand(26)] - string << pick - end - return string + o = [('a'..'z'), ('A'..'Z'), (0..9)].flat_map(&:to_a) + (0...length).map { o[rand(o.length)] }.join end def assert_equal_dmy(date1, date2)