Help language development. Donate to The Perl Foundation

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

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

class User is Model {
  submethod BUILD {
    self.validate: 'fname', { :presence, on => { :create } }
  }
}

plan 9;

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

my @errors;
my $user;

$user = User.create();
ok $user.is-invalid;
ok $user.errors.fname[0] eq 'must be present';

$user = User.create({});
ok $user.is-invalid;
ok $user.errors.fname[0] eq 'must be present';

$user = User.create({fname => 'Greg'});
ok $user.is-valid;
nok $user.errors.fname[0];

$user.fname = Nil;
ok $user.save;
ok $user.is-valid;
nok $user.errors.fname[0];

User.destroy-all;