[Bast-commits] r9145 - in DBIx-Class/0.08/branches/filter_column:
lib/DBIx/Class t/row
frew at dev.catalyst.perl.org
frew at dev.catalyst.perl.org
Wed Apr 14 15:55:15 GMT 2010
Author: frew
Date: 2010-04-14 16:55:14 +0100 (Wed, 14 Apr 2010)
New Revision: 9145
Modified:
DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/FilterColumn.pm
DBIx-Class/0.08/branches/filter_column/t/row/filter_column.t
Log:
basic tests and a tiny fix
Modified: DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/FilterColumn.pm
===================================================================
--- DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/FilterColumn.pm 2010-04-14 15:50:56 UTC (rev 9144)
+++ DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/FilterColumn.pm 2010-04-14 15:55:14 UTC (rev 9145)
@@ -16,7 +16,7 @@
$self->column_info($col)->{_filter_info} = $attrs;
my $acc = $self->column_info($col)->{accessor};
- $self->mk_group_accessors('filtered_column' => [ (defined $acc ? $acc : $col), $col]);
+ $self->mk_group_accessors('value' => [ (defined $acc ? $acc : $col), $col]);
return 1;
}
@@ -73,18 +73,4 @@
return $filtered;
}
-sub register_column {
- my ($class, $col, $info) = @_;
- my $acc = $col;
- if (exists $info->{accessor}) {
- return unless defined $info->{accessor};
- $acc = [ $info->{accessor}, $col ];
- }
- if ( exists $self->column_info($col)->{_filter_info} ) {
- $class->mk_group_accessors(value => $acc);
- } else {
- $class->mk_group_accessors(column => $acc);
- }
-}
-
1;
Modified: DBIx-Class/0.08/branches/filter_column/t/row/filter_column.t
===================================================================
--- DBIx-Class/0.08/branches/filter_column/t/row/filter_column.t 2010-04-14 15:50:56 UTC (rev 9144)
+++ DBIx-Class/0.08/branches/filter_column/t/row/filter_column.t 2010-04-14 15:55:14 UTC (rev 9145)
@@ -2,6 +2,51 @@
use warnings;
use Test::More;
-use Test::Exception;
use lib qw(t/lib);
use DBICTest;
+
+my $schema = DBICTest->init_schema();
+DBICTest::Schema::Artist->load_components('FilterColumn');
+DBICTest::Schema::Artist->filter_column(rank => {
+ filter => sub { warn "FILTERING!"; $_[1] * 2 },
+ unfilter => sub {warn "UNFILTERING!"; $_[1] / 2 },
+});
+Class::C3->reinitialize();
+
+my $artist = $schema->resultset('Artist')->create( { rank => 20 } );
+
+# this should be using the cursor directly, no inflation/processing of any sort
+my ($raw_db_rank) = $schema->resultset('Artist')
+ ->search ($artist->ident_condition)
+ ->get_column('rank')
+ ->_resultset
+ ->cursor
+ ->next;
+
+is ($raw_db_rank, 10, 'INSERT: correctly unfiltered on insertion');
+
+for my $reloaded (0, 1) {
+ my $test = $reloaded ? 'reloaded' : 'stored';
+ $artist->discard_changes if $reloaded;
+
+ is( $artist->rank , 20, "got $test filtered rank" );
+}
+
+$artist->update;
+$artist->discard_changes;
+is( $artist->rank , 20, "got filtered rank" );
+
+$artist->update ({ rank => 40 });
+($raw_db_rank) = $schema->resultset('Artist')
+ ->search ($artist->ident_condition)
+ ->get_column('rank')
+ ->_resultset
+ ->cursor
+ ->next;
+is ($raw_db_rank, 20, 'UPDATE: correctly unflitered on update');
+
+$artist->discard_changes;
+$artist->rank(40);
+ok( !$artist->is_column_changed('rank'), 'column is not dirty after setting the same value' );
+
+done_testing;
More information about the Bast-commits
mailing list