Help language development. Donate to The Perl Foundation

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

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

class Client is Model {
  submethod BUILD {
    self.validate: 'email', { :presence, :confirmation }
  }
}

plan 7;

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

my @errors;
my Client $client;

$client = Client.build({});
ok $client.is-invalid;
@errors = ['must be present', 'must be confirmed'];
ok @errors.grep: $client.errors.email[0];
ok @errors.grep: $client.errors.email[1];

$client = Client.build({email => '[email protected]'});
ok $client.is-invalid;
ok $client.errors.email[0] eq 'must be confirmed';

$client = Client.build({email => '[email protected]', email_confirmation => '[email protected]'});
ok $client.is-valid;
nok $client.errors.email;

Client.destroy-all;