From: Jason Mills Date: Sat, 1 Mar 2014 01:13:31 +0000 (-0800) Subject: Add empty possible value to Object::Enum values X-Git-Tag: v0.05_r2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;p=dbsrgits%2FDBIx-Class-InflateColumn-Object-Enum.git Add empty possible value to Object::Enum values when is_nullable is true --- diff --git a/lib/DBIx/Class/InflateColumn/Object/Enum.pm b/lib/DBIx/Class/InflateColumn/Object/Enum.pm index b171da5..47040e3 100644 --- a/lib/DBIx/Class/InflateColumn/Object/Enum.pm +++ b/lib/DBIx/Class/InflateColumn/Object/Enum.pm @@ -100,6 +100,10 @@ sub register_column { if defined($info->{default_value}) && !exists $values{$info->{default_value}}; + push(@{$values}, undef) + if defined($info->{is_nullable}) + && $info->{is_nullable}; + $self->inflate_column( $column => { inflate => sub { diff --git a/t/01-object-enum.t b/t/01-object-enum.t index fa7a9cb..cb075c9 100644 --- a/t/01-object-enum.t +++ b/t/01-object-enum.t @@ -1,4 +1,4 @@ -use Test::More tests => 33; +use Test::More tests => 24; BEGIN { use lib 't/lib'; @@ -35,13 +35,14 @@ undef $rs; eval(q/$db->resultset('VarcharEnumNoneNullable')->create({id=>1})/); ok(defined($@),'VarcharEnumNoneNullable(null enum): create with null enum failed as expected'); # test 13 -$rs = $db->resultset('VarcharEnumNoneNullable')->create({id=>2,enum=>'none'}); -ok(defined($rs),'VarcharEnumNoneNullable(invalid enum): create with invalid enum returns row as expected'); # test 14 -_check_column($rs->enum,$rs->result_source->source_name.'(invalid enum)'); # tests 15 thru 21 +# commented tests now conflict with expected behavior +#$rs = $db->resultset('VarcharEnumNoneNullable')->create({id=>2,enum=>'none'}); +#ok(defined($rs),'VarcharEnumNoneNullable(invalid enum): create with invalid enum returns row as expected'); # test 14 +#_check_column($rs->enum,$rs->result_source->source_name.'(invalid enum)'); # tests 15 thru 21 -undef $rs; -$rs = $db->resultset('VarcharEnumNoneNullable')->create({id=>3,enum=>'none'}); -ok($rs->enum->value ne 'none','VarcharEnumNoneNullable(invalid enum) value return undef on valid as expected'); # test 22 +#undef $rs; +#$rs = $db->resultset('VarcharEnumNoneNullable')->create({id=>3,enum=>'none'}); +#ok($rs->enum->value ne 'none','VarcharEnumNoneNullable(invalid enum) value return undef on valid as expected'); # test 22 undef $rs; $rs = $db->resultset('VarcharEnumNoneNullable')->create({id=>4,enum=>'red'});