mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-18 08:10:13 +01:00
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.
This commit is contained in:
parent
bb8fd08685
commit
dea3b1b58e
1 changed files with 4 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
ENV['RAILS_ENV'] ||= 'test'
|
ENV['RAILS_ENV'] ||= 'test'
|
||||||
require File.expand_path('../../config/environment', __FILE__)
|
require File.expand_path('../../config/environment', __FILE__)
|
||||||
require 'rails/test_help'
|
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
|
# 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
|
"time_zone" => "Amsterdam" # force UTC+1 so Travis triggers time zone failures
|
||||||
}.inject( SITE_CONFIG ) { |h, elem| h[elem[0]] = elem[1]; h }
|
}.inject( SITE_CONFIG ) { |h, elem| h[elem[0]] = elem[1]; h }
|
||||||
|
|
||||||
|
|
||||||
class ActiveSupport::TestCase
|
class ActiveSupport::TestCase
|
||||||
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
||||||
#
|
#
|
||||||
|
|
@ -38,13 +40,8 @@ class ActiveSupport::TestCase
|
||||||
# for validation purposes
|
# for validation purposes
|
||||||
#
|
#
|
||||||
def generate_random_string(length)
|
def generate_random_string(length)
|
||||||
string = ""
|
o = [('a'..'z'), ('A'..'Z'), (0..9)].flat_map(&:to_a)
|
||||||
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)
|
(0...length).map { o[rand(o.length)] }.join
|
||||||
length.times do
|
|
||||||
pick = characters[rand(26)]
|
|
||||||
string << pick
|
|
||||||
end
|
|
||||||
return string
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_equal_dmy(date1, date2)
|
def assert_equal_dmy(date1, date2)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue