Help language development. Donate to The Perl Foundation

ORM::ActiveRecord cpan:GDONALD last updated on 2019-10-24

t/002-validate-inclusion.t6
use v6.d;
use lib 'lib';
use ORM::ActiveRecord::Model;
use Test;

class Image is Model {
  submethod BUILD {
    self.validate: 'ext', { :presence, inclusion => { in => <gif jpeg jpg png> } }
  }
}

plan 7;

%*ENV<DISABLE-SQL-LOG> = True;

my @errors;
my Image $image;

$image = Image.build({});
ok $image.is-invalid;
@errors = ['must be present', 'is invalid'];
ok @errors.grep: $image.errors.ext[0];
ok @errors.grep: $image.errors.ext[1];

$image = Image.build({ext => 'foo'});
ok $image.is-invalid;
ok $image.errors.ext[0] eq 'is invalid';

$image = Image.build({ext => 'jpg'});
ok $image.is-valid;
nok $image.errors.format;

Image.destroy-all;