From: Jess Robinson Date: Thu, 3 May 2007 22:58:13 +0000 (+0000) Subject: aaaalmost fixed tests.. X-Git-Tag: v0.900201~106 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f4f0b7c9e5bd9dc8e508c538d9482e2b614bb0d4;p=dbsrgits%2FDBIx-Class-Journal.git aaaalmost fixed tests.. --- diff --git a/lib/DBIx/Class/Schema/Journal.pm b/lib/DBIx/Class/Schema/Journal.pm index 72d8881..68d6786 100644 --- a/lib/DBIx/Class/Schema/Journal.pm +++ b/lib/DBIx/Class/Schema/Journal.pm @@ -45,7 +45,9 @@ sub connection return; } + $self->_journal_schema->deploy(); $self->_journal_schema->class('ChangeSet')->belongs_to('user', @{$self->journal_user}); + $self->_journal_schema->storage->disconnect(); } sub get_audit_log_class_name @@ -84,19 +86,19 @@ sub create_journal_for $self->_journal_schema->register_class("${s_name}AuditHistory", $histclass); } -sub create_changeset +sub txn_do { my ($self, $code) = @_; ## Create a new changeset, then run $code as a transaction - my $cs = $self->result_source->schema->_journal_schema->resultset('ChangeSet'); + my $cs = $self->_journal_schema->resultset('ChangeSet'); my $changeset = $cs->create({ - user_id => $self->result_source->schema->_journal_schema->current_user(), - session_id => $self->result_source->schema->_journal_schema->current_session(), + user_id => $self->_journal_schema->current_user(), + session_id => $self->_journal_schema->current_session(), }); - $self->result_source->schema->_journal_schema->current_changeset($changeset->ID); + $self->_journal_schema->current_changeset($changeset->ID); - $self->txn_do($code); + $self->next::method($code); } 1; diff --git a/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm b/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm index 6a37d38..9c82466 100644 --- a/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm +++ b/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm @@ -23,13 +23,13 @@ __PACKAGE__->add_columns( sub new { - my ($self, $data, @rest) = @_; + my ($self, $data, $source, @rest) = @_; $data->{created} = { - changeset_id => $self->result_source->schema->_journal_schema->current_changeset, + changeset_id => $source->schema->current_changeset, }; - $self->next::method($data, @rest); + $self->next::method($data, $source, @rest); } 1; diff --git a/t/01test.t b/t/01test.t index 786f126..3efaf6b 100644 --- a/t/01test.t +++ b/t/01test.t @@ -20,12 +20,13 @@ isa_ok($schema->_journal_schema, 'DBIx::Class::Schema::Journal::DB', 'Actually h isa_ok($schema->_journal_schema->source('CDAuditHistory'), 'DBIx::Class::ResultSource', 'CDAuditHistory source exists'); isa_ok($schema->_journal_schema->source('ArtistAuditLog'), 'DBIx::Class::ResultSource', 'ArtistAuditLog source exists'); -my $new_cd = $schema->resultset('CD')->create({ - title => 'Angry young man', - artist => 0, - year => 2000, +my $new_cd = $schema->txn_do( sub { + return $schema->resultset('CD')->create({ + title => 'Angry young man', + artist => 0, + year => 2000, }); - +}); isa_ok($new_cd, 'DBIx::Class::Journal', 'Created CD object'); my $search = $schema->_journal_schema->resultset('CDAuditLog')->search();