Skip to content

Commit

Permalink
Tests for the trigger method (attribute option).
Browse files Browse the repository at this point in the history
  • Loading branch information
mendel committed Mar 15, 2011
1 parent c793e25 commit 75a5c51
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
20 changes: 19 additions & 1 deletion agg-t/user/10-add_column.t
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,24 @@ fixtures_ok 'basic', 'installed the basic fixtures from configuration files';
} "value returned by 'title' method is undef";
}

#FIXME other methods/options (trigger, ...)
# tests for the trigger method

{
my $artist1 = Schema->resultset('Artist')->find({ artist_id => 1 });

$artist1->is_active(0);

lives_ok {
$artist1->last_album('Foo Bar');
} "setting the attribute with the trigger does not throw";

cmp_deeply(
$artist1->is_active,
1,
"the trigger set the 'is_active' attribute"
);
}

#FIXME other methods/options

done_testing;
14 changes: 14 additions & 0 deletions t/lib/TestSchema/Result/Artist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ has favourite_color => (
},
);

# used for testing the trigger method
has last_album => (
isa => 'Maybe[Str]',
is => 'rw',
add_column => {
is_nullable => 1,
},
trigger => sub {
my ($self, $new_value, $old_value) = (shift, @_);

$self->is_active(1);
},
);

sub _build_initials
{
my ($self) = (shift, @_);
Expand Down

0 comments on commit 75a5c51

Please sign in to comment.