From: Guillermo Roditi Date: Wed, 4 Feb 2009 21:23:06 +0000 (+0000) Subject: adding failing test to make sure insert doesnt call set_column X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6e6b37a79565584afc1fe55037b0d1b113d28765;p=dbsrgits%2FDBIx-Class-Historic.git adding failing test to make sure insert doesnt call set_column --- diff --git a/t/60core.t b/t/60core.t index d41b551..8e1ff46 100644 --- a/t/60core.t +++ b/t/60core.t @@ -7,7 +7,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 86; +plan tests => 88; eval { require DateTime::Format::MySQL }; my $NO_DTFM = $@ ? 1 : 0; @@ -379,3 +379,11 @@ SKIP: { my $table = $class->table($class->table); is($table, $class->table, '->table($table) returns $table'); } + +#make sure insert doesn't use set_column +{ + my $en_row = $schema->resultset('Encoded')->new_result({encoded => 'wilma'}); + is($en_row->encoded, 'amliw', 'new encodes'); + $en_row->insert; + is($en_row->encoded, 'amliw', 'insert does not encode again'); +} diff --git a/t/lib/DBICTest/Schema.pm b/t/lib/DBICTest/Schema.pm index 3b6a775..5949b44 100644 --- a/t/lib/DBICTest/Schema.pm +++ b/t/lib/DBICTest/Schema.pm @@ -44,7 +44,7 @@ __PACKAGE__->load_classes(qw/ ), qw/SelfRefAlias TreeLike TwoKeyTreeLike Event EventTZ NoPrimaryKey/, qw/Collection CollectionObject TypedObject Owners BooksInLibrary/, - qw/ForceForeign/, + qw/ForceForeign Encoded/, ); sub sqlt_deploy_hook { diff --git a/t/lib/DBICTest/Schema/Encoded.pm b/t/lib/DBICTest/Schema/Encoded.pm new file mode 100644 index 0000000..9d09f31 --- /dev/null +++ b/t/lib/DBICTest/Schema/Encoded.pm @@ -0,0 +1,39 @@ +package # hide from PAUSE + DBICTest::Schema::Encoded; + +use base 'DBIx::Class::Core'; + +use strict; +use warnings; + +__PACKAGE__->table('encoded'); +__PACKAGE__->add_columns( + 'id' => { + data_type => 'integer', + is_auto_increment => 1 + }, + 'encoded' => { + data_type => 'varchar', + size => 100, + is_nullable => 1, + }, +); + +__PACKAGE__->set_primary_key('id'); + +sub set_column { + my ($self, $col, $value) = @_; + if( $col eq 'encoded' ){ + $value = reverse split '', $value; + } + $self->next::method($col, $value); +} + +sub new { + my($self, $attr, @rest) = @_; + $attr->{encoded} = reverse split '', $attr->{encoded} + if defined $attr->{encoded}; + return $self->next::method($attr, @rest); +} + +1; diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index a27d16d..b364cb4 100644 --- a/t/lib/sqlite.sql +++ b/t/lib/sqlite.sql @@ -423,5 +423,12 @@ CREATE TABLE typed_object ( value varchar(100) NOT NULL ); +-- +-- Table: encoded +-- +CREATE TABLE encoded ( + id INTEGER PRIMARY KEY NOT NULL, + encoded varchar(100) NOT NULL +); COMMIT;