diff --git a/t/db_dependent/TestBuilder.t b/t/db_dependent/TestBuilder.t index 6110beac42..6635a0bc23 100644 --- a/t/db_dependent/TestBuilder.t +++ b/t/db_dependent/TestBuilder.t @@ -236,6 +236,7 @@ is( $bookseller_result->in_storage, 1, 'build with only_fk = 1 creates the forei $bookseller = $builder->build({ source => 'Aqbookseller', }); +ok( length( $bookseller->{phone} ) <= 30, 'The length for a generated string should not be longer than the size of the DB field' ); delete $bookseller->{_fk}; $bookseller_from_db = $rs_aqbookseller->find($bookseller); is( $bookseller_from_db->in_storage, 1, 'build without the parameter only_sk stores the entry correctly' ); diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index 2497ffdb05..72364e3a2e 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -288,8 +288,18 @@ sub _gen_date { sub _gen_text { my ($self, $params) = @_; - my $random = String::Random->new( max => $params->{info}->{size} ); - return $random->randregex('[A-Za-z]+[A-Za-z0-9_]*'); + # From perldoc String::Random + # max: specify the maximum number of characters to return for * and other + # regular expression patters that don't return a fixed number of characters + my $regex = '[A-Za-z][A-Za-z0-9_]*'; + my $size = $params->{info}{size}; + if ( defined $size and $size > 1 ) { + $size--; + } elsif ( defined $size and $size == 1 ) { + $regex = '[A-Za-z]'; + } + my $random = String::Random->new( max => $size ); + return $random->randregex($regex); } sub _gen_set_enum {