[Bast-commits] r3223 - in trunk/DBIx-Class-Journal: lib/DBIx/Class
lib/DBIx/Class/Schema lib/DBIx/Class/Schema/Journal
lib/DBIx/Class/Schema/Journal/DB t t/lib/DBICTest
castaway at dev.catalyst.perl.org
castaway at dev.catalyst.perl.org
Wed May 2 14:33:47 GMT 2007
Author: castaway
Date: 2007-05-02 14:33:47 +0100 (Wed, 02 May 2007)
New Revision: 3223
Modified:
trunk/DBIx-Class-Journal/lib/DBIx/Class/Journal.pm
trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal.pm
trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB.pm
trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm
trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm
trunk/DBIx-Class-Journal/t/01test.t
trunk/DBIx-Class-Journal/t/lib/DBICTest/Schema.pm
Log:
Add some tests and fix up for the results..
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Journal.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Journal.pm 2007-05-02 12:51:51 UTC (rev 3222)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Journal.pm 2007-05-02 13:33:47 UTC (rev 3223)
@@ -4,29 +4,32 @@
## On create/insert, add new entry to AuditLog
-sub new
-{
- my ($class, $attrs, @rest) = @_;
+# sub new
+# {
+# my ($class, $attrs, @rest) = @_;
- $class->result_source->schema->_journal_schema->current_user(delete $attrs->{user_id});
+# $class->result_source->schema->_journal_schema->current_user(delete $attrs->{user_id});
- $class->next::method($attrs, @rest);
-}
+# $class->next::method($attrs, @rest);
+# }
sub insert
{
my ($self) = @_;
## create new transaction here?
- $self->next::method();
+ my $res = $self->next::method();
if($self->in_storage)
{
- my $s_name = $self->result_source_instance->name();
+ my $s_name = $self->result_source->source_name();
+ print STDERR "Schema: ", ref($self->result_source->schema), "\n";
my $al = $self->result_source->schema->_journal_schema->resultset("${s_name}AuditLog");
$al->create({
changeset => $self->result_source->schema->_journal_schema->current_changeset(),
});
}
+
+ return $res;
}
## On delete, update delete_id of AuditLog
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm 2007-05-02 12:51:51 UTC (rev 3222)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm 2007-05-02 13:33:47 UTC (rev 3223)
@@ -1,6 +1,7 @@
package DBIx::Class::Schema::Journal::DB::AuditHistory;
use base 'DBIx::Class::Schema::Journal::DB::Base';
+__PACKAGE__->table(__PACKAGE__->table);
__PACKAGE__->add_columns(
change_id => {
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm 2007-05-02 12:51:51 UTC (rev 3222)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm 2007-05-02 13:33:47 UTC (rev 3223)
@@ -1,6 +1,7 @@
package DBIx::Class::Schema::Journal::DB::AuditLog;
use base 'DBIx::Class::Schema::Journal::DB::Base';
+__PACKAGE__->table(__PACKAGE__->table);
__PACKAGE__->add_columns(
ID => {
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB.pm 2007-05-02 12:51:51 UTC (rev 3222)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB.pm 2007-05-02 13:33:47 UTC (rev 3223)
@@ -9,6 +9,8 @@
DBIx::Class::Schema::Journal::DB->load_classes(qw/
ChangeSet
Change
+ AuditLog
+ AuditHistory
/);
1;
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal.pm 2007-05-02 12:51:51 UTC (rev 3222)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal.pm 2007-05-02 13:33:47 UTC (rev 3223)
@@ -16,7 +16,8 @@
my $self = shift;
$self->next::method(@_);
- my $journal_schema = (__PACKAGE__ . '::DB')->connect($self->journal_connection || $self->storage->connect_info);
+ my $journal_schema = DBIx::Class::Schema::Journal::DB->connect(@{ $self->journal_connection || $self->storage->connect_info });
+ print STDERR "conn", $journal_schema->storage->connect_info;
if($self->journal_storage_type)
{
$journal_schema->storage_type($self->journal_storage_type);
@@ -31,7 +32,8 @@
{
next unless($j_sources{$s_name});
$self->create_journal_for($s_name);
- $self->source($s_name)->load_component('Journal');
+ $self->class($s_name)->load_components('Journal');
+ print STDERR "$s_name :", $self->class($s_name), "\n";
}
## Set up relationship between changeset->user_id and this schema's user
@@ -41,7 +43,7 @@
return;
}
- $self->_journal_schema->source('ChangeSet')->belongs_to('user', @{$self->journal_user});
+ $self->_journal_schema->class('ChangeSet')->belongs_to('user', @{$self->journal_user});
}
sub get_audit_log_class_name
@@ -65,17 +67,19 @@
my $source = $self->source($s_name);
my $newclass = $self->get_audit_log_class_name($s_name);
DBIx::Class::Componentised->inject_base($newclass, 'DBIx::Class::Schema::Journal::DB::AuditLog');
-# $newclass->table(lc($s_name) . "_audit_log");
- $newclass->result_source_instance->name(lc($s_name) . "_audit_log");
+ $newclass->table(lc($s_name) . "_audit_log");
+ $self->_journal_schema->register_class("${s_name}AuditLog", $newclass);
- my $histclass = $self->get_audit_hisory_class_name($s_name);
+ my $histclass = $self->get_audit_history_class_name($s_name);
DBIx::Class::Componentised->inject_base($histclass, 'DBIx::Class::Schema::Journal::DB::AuditHistory');
- $histclass->result_source_instance->name(lc($s_name) . "_audit_hisory");
+ $histclass->table(lc($s_name) . "_audit_history");
+# $histclass->result_source_instance->name(lc($s_name) . "_audit_hisory");
$histclass->add_columns(
map { $_ => $source->column_info($_) } $source->columns
);
+ $self->_journal_schema->register_class("${s_name}AuditHistory", $histclass);
}
sub create_changeset
Modified: trunk/DBIx-Class-Journal/t/01test.t
===================================================================
--- trunk/DBIx-Class-Journal/t/01test.t 2007-05-02 12:51:51 UTC (rev 3222)
+++ trunk/DBIx-Class-Journal/t/01test.t 2007-05-02 13:33:47 UTC (rev 3223)
@@ -10,11 +10,25 @@
eval "use DBD::SQLite";
plan $@
? ( skip_all => 'needs DBD::SQLite for testing' )
- : ( tests => 2 );
+ : ( tests => 6 );
}
my $schema = DBICTest->init_schema(no_populate => 1);
ok($schema, 'Created a Schema');
-isa_ok($schema->_journal_schema, 'DBIx::Class::Schema::Journal::DB');
+isa_ok($schema->_journal_schema, 'DBIx::Class::Schema::Journal::DB', 'Actually have a schema object for the journaling');
+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,
+ });
+
+isa_ok($new_cd, 'DBIx::Class::Journal', 'Created CD object');
+
+my $search = $schema->_journal_schema->resultset('CDAuditLog')->search();
+ok($search->count, 'Created an entry in the CD audit log');
+
+
Modified: trunk/DBIx-Class-Journal/t/lib/DBICTest/Schema.pm
===================================================================
--- trunk/DBIx-Class-Journal/t/lib/DBICTest/Schema.pm 2007-05-02 12:51:51 UTC (rev 3222)
+++ trunk/DBIx-Class-Journal/t/lib/DBICTest/Schema.pm 2007-05-02 13:33:47 UTC (rev 3223)
@@ -5,8 +5,9 @@
__PACKAGE__->load_components(qw/+DBIx::Class::Schema::Journal/);
+__PACKAGE__->journal_user(['DBICTest::Schema::Artist', {'foreign.artistid' => 'self.user_id'}]);
+
no warnings qw/qw/;
-
__PACKAGE__->load_classes(qw/
Artist
CD
More information about the Bast-commits
mailing list