forked from fixin.me/fixin.me
Better string input randomization
This commit is contained in:
parent
5c70736a91
commit
d1bfabc105
@ -18,8 +18,11 @@ class UnitsTest < ApplicationSystemTestCase
|
||||
|
||||
within first('tbody > tr') do
|
||||
assert_selector ':focus'
|
||||
fill_in 'unit[symbol]', with: SecureRandom.random_symbol(rand(1..16))
|
||||
fill_in 'unit[name]', with: [nil, SecureRandom.alphanumeric(rand(1..255))].sample
|
||||
maxlength = all(:fillable_field).to_h { |f| [f[:name], f[:maxlength].to_i || 1000] }
|
||||
fill_in 'unit[symbol]',
|
||||
with: SecureRandom.random_symbol(rand([1..15, 15..maxlength['unit[symbol]']].sample))
|
||||
fill_in 'unit[name]',
|
||||
with: [nil, SecureRandom.alphanumeric(rand(1..maxlength['unit[name]']))].sample
|
||||
assert_difference ->{ Unit.count }, 1 do
|
||||
click_on t(:add)
|
||||
end
|
||||
|
@ -16,7 +16,7 @@ class ActiveSupport::TestCase
|
||||
SecureRandom.class_eval do
|
||||
def self.random_symbol(n = 10)
|
||||
# Unicode characters: 32-126, 160-383
|
||||
choose([*' '..'~', 160.chr, *'¡'..'ſ'], n)
|
||||
choose([*' '..'~', 160.chr(Encoding::UTF_8), *'¡'..'ſ'], n)
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user