diff --git a/test/system/units_test.rb b/test/system/units_test.rb index 4323d9c..29f714b 100644 --- a/test/system/units_test.rb +++ b/test/system/units_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 87a0161..1e7f8dc 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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