From: Peter Rabbitson Date: Sun, 6 Feb 2011 10:31:45 +0000 (+0100) Subject: Fix incorrect default sqlt_deploy_hook signature X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fed15b9163bcb281a3a654643949a9cd1f9a3928;p=dbsrgits%2FDBIx-Class-Historic.git Fix incorrect default sqlt_deploy_hook signature --- diff --git a/Changes b/Changes index 97eef01..ddea653 100644 --- a/Changes +++ b/Changes @@ -66,6 +66,8 @@ Revision history for DBIx::Class a multi relationship ( x -> might_have y -> has_many z ) - Fix object-derived custom-relationship resultsets to resultsources with multilevel monikers (e.g. $schema->source('Foo::Bar') ) + - Fix incorrect signature of the default sqlt_deploy_hook - it now + matches the documentation of passing in the result source object * Misc - Rewire all warnings to a new Carp-like implementation internal diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index d7bcd72..58eed49 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -940,8 +940,8 @@ sub default_sqlt_deploy_hook { my $class = $self->result_class; - if ($class and $class->can('sqlt_deploy_hook')) { - $class->sqlt_deploy_hook(@_); + if ($class and my $hook = $class->can('sqlt_deploy_hook')) { + $self->$hook(@_); } } diff --git a/t/86sqlt.t b/t/86sqlt.t index 3430cec..d240a9c 100644 --- a/t/86sqlt.t +++ b/t/86sqlt.t @@ -5,6 +5,8 @@ use Test::More; use lib qw(t/lib); use DBICTest; +use Scalar::Util 'blessed'; + BEGIN { require DBIx::Class; plan skip_all => @@ -27,7 +29,6 @@ my $schema = DBICTest->init_schema (no_deploy => 1); { my $not_first_table_creation_re = qr/CREATE TABLE fourkeys_to_twokeys/; - my $statements = $schema->deployment_statements; like ( $statements, @@ -50,10 +51,37 @@ my $schema = DBICTest->init_schema (no_deploy => 1); ); } +{ + # use our own throw-away schema, since we'll be deploying twice + my $schema = DBICTest->init_schema (no_deploy => 1); + + my $deploy_hook_called = 0; + $custom_deployment_statements_called = 0; + + # add a temporary sqlt_deploy_hook to a source + no warnings 'once'; + local *DBICTest::Track::sqlt_deploy_hook = sub { + my ($self, $sqlt_table) = @_; + + $deploy_hook_called = 1; + + is (blessed ($self), 'DBIx::Class::ResultSource::Table', 'Source object passed to plain hook'); + is ( + $sqlt_table->schema->translator->producer_type, + join ('::', 'SQL::Translator::Producer', $schema->storage->sqlt_type), + 'Production type passed to translator object', + ); + }; + + $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'); +} { my $deploy_hook_called = 0; + $custom_deployment_statements_called = 0; # replace the sqlt calback with a custom version ading an index $schema->source('Track')->sqlt_deploy_callback(sub {