Help language development. Donate to The Perl Foundation

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

t/005-callback-after-create.t6
use v6.d;
use lib 'lib';
use ORM::ActiveRecord::Model;
use Test;

class Log is Model {};

class Client is Model {
  submethod BUILD {
    self.validate: 'email', { :presence };
    self.after-create: -> { self.log };
  }

  method log {
    my $log = self.email ~ ' was created';
    Log.create({:$log});
  }
}

plan 2;

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

my $client = Client.create({ email => '[email protected]' });
ok Log.count == 1;

$client.email = '[email protected]';
$client.save;
ok Log.count == 1;

Client.destroy-all;
Log.destroy-all;