Help language development. Donate to The Perl Foundation

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

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

class Person is Model {
  submethod BUILD {
    self.validate: 'username', { :uniqueness }
  }
}

plan 4;

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

Person.destroy-all;

my $person;

$person = Person.create({username => 'alfred'});
ok $person.is-valid;
nok $person.errors.username;

$person = Person.build({username => 'alfred'});
ok $person.is-invalid;
ok $person.errors.username[0] eq 'must be unique';

Person.destroy-all;