From: Pedro Melo Date: Tue, 24 May 2011 14:52:33 +0000 (+0100) Subject: Added tests for chained sqlt_deploy_hook()'s X-Git-Tag: v0.08193~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a267ea85dbed950ecd00f5e6a139e33b1a67c7bf;p=dbsrgits%2FDBIx-Class.git Added tests for chained sqlt_deploy_hook()'s We need to declare the sqlt_deploy_hook sub's in the code to make sure the next::method knows they exist. Signed-off-by: Pedro Melo --- diff --git a/t/86sqlt.t b/t/86sqlt.t index 6435ba9..961ca27 100644 --- a/t/86sqlt.t +++ b/t/86sqlt.t @@ -59,8 +59,7 @@ my $schema = DBICTest->init_schema (no_deploy => 1); $custom_deployment_statements_called = 0; # add a temporary sqlt_deploy_hook to a source - no warnings 'once'; - local *DBICTest::Track::sqlt_deploy_hook = sub { + local $DBICTest::Schema::Track::hook_cb = sub { my ($class, $sqlt_table) = @_; $deploy_hook_called = 1; @@ -74,9 +73,15 @@ my $schema = DBICTest->init_schema (no_deploy => 1); ); }; + my $component_deploy_hook_called = 0; + local $DBICTest::DeployComponent::hook_cb = sub { + $component_deploy_hook_called = 1; + }; + $schema->deploy; # do not remove, this fires the is() test in the callback above ok($deploy_hook_called, 'deploy hook got called'); ok($custom_deployment_statements_called, '->deploy used the schemas deploy_statements method'); + ok($component_deploy_hook_called, 'component deploy hook got called'); } { diff --git a/t/lib/DBICTest/DeployComponent.pm b/t/lib/DBICTest/DeployComponent.pm new file mode 100644 index 0000000..590fc25 --- /dev/null +++ b/t/lib/DBICTest/DeployComponent.pm @@ -0,0 +1,16 @@ +# belongs to t/86sqlt.t +package # hide from PAUSE + DBICTest::DeployComponent; +use warnings; +use strict; + +our $hook_cb; + +sub sqlt_deploy_hook { + my $class = shift; + + $hook_cb->($class, @_) if $hook_cb; + $class->next::method(@_) if $class->next::can; +} + +1; diff --git a/t/lib/DBICTest/Schema/Track.pm b/t/lib/DBICTest/Schema/Track.pm index a57fcb5..6360ca0 100644 --- a/t/lib/DBICTest/Schema/Track.pm +++ b/t/lib/DBICTest/Schema/Track.pm @@ -4,7 +4,11 @@ package # hide from PAUSE use base qw/DBICTest::BaseResult/; use Carp qw/confess/; -__PACKAGE__->load_components(qw/InflateColumn::DateTime Ordered/); +__PACKAGE__->load_components(qw{ + +DBICTest::DeployComponent + InflateColumn::DateTime + Ordered +}); __PACKAGE__->table('track'); __PACKAGE__->add_columns( @@ -90,4 +94,13 @@ __PACKAGE__->might_have ( } ); +our $hook_cb; + +sub sqlt_deploy_hook { + my $class = shift; + + $hook_cb->($class, @_) if $hook_cb; + $class->next::method(@_) if $class->next::can; +} + 1;