Help language development. Donate to The Perl Foundation

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

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

class Contract is Model {
  submethod BUILD {
    self.validate: 'name', { :presence, length => { min => 8, max => 64 } }
    self.validate: 'terms', { :acceptance }
  }
}

plan 4;

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

my Contract $contract;

$contract = Contract.create({name => 'Offical Document', terms => False});
nok $contract.is-valid;
ok $contract.errors.terms[0] eq 'must be accepted';

$contract = Contract.create({name => 'Offical Document', terms => True});
ok $contract.is-valid;
nok $contract.errors.terms;

Contract.destroy-all;