From 6395006f1bb009faaf6762f9d21949bbc2f6a0ff Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 11 Mar 2013 12:50:06 +0100 Subject: [PATCH] AttrDuration: in SL::DB::Object->assign_attributes() auch attr_man_days_string() vor _unit() auswerten --- SL/DB/Object.pm | 7 ++++--- t/db_helper/attr_duration.t | 14 +++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/SL/DB/Object.pm b/SL/DB/Object.pm index 3cf670d55..1c7c050ea 100755 --- a/SL/DB/Object.pm +++ b/SL/DB/Object.pm @@ -60,9 +60,10 @@ sub _assign_attributes { my %types = map { $_->name => $_->type } ref($self)->meta->columns; - # Special case for *_as_man_days/*_as_man_days_unit: the _unit - # variation must always be called after the non-unit method. - my @man_days_attributes = grep { m/_as_man_days$/ } keys %attributes; + # Special case for *_as_man_days / *_as_man_days_string / + # *_as_man_days_unit: the _unit variation must always be called + # after the non-unit methods. + my @man_days_attributes = grep { m/_as_man_days(?:_string)?$/ } keys %attributes; foreach my $attribute (@man_days_attributes) { my $value = delete $attributes{$attribute}; $self->$attribute(defined($value) && ($value eq '') ? undef : $value); diff --git a/t/db_helper/attr_duration.t b/t/db_helper/attr_duration.t index 3af729687..da05a3211 100644 --- a/t/db_helper/attr_duration.t +++ b/t/db_helper/attr_duration.t @@ -13,7 +13,7 @@ __PACKAGE__->attr_duration('dummy'); package main; -use Test::More tests => 83; +use Test::More tests => 91; use Test::Exception; use strict; @@ -147,6 +147,18 @@ is(new_item->assign_attributes('dummy_as_man_days_unit', 'h', 'dummy_as_ma is(new_item->assign_attributes('dummy_as_man_days', 3, 'dummy_as_man_days_unit', 'man_day')->dummy, 24, 'assign_attributes array 3man_day'); is(new_item->assign_attributes('dummy_as_man_days_unit', 'man_day', 'dummy_as_man_days', 3 )->dummy, 24, 'assign_attributes array man_day3'); +is(new_item->assign_attributes(dummy_as_man_days_string => '5,25', dummy_as_man_days_unit => 'h' )->dummy, 5.25, 'assign_attributes hash string 5,25h'); +is(new_item->assign_attributes(dummy_as_man_days_unit => 'h', dummy_as_man_days_string => '5,25')->dummy, 5.25, 'assign_attributes hash string h5,25'); + +is(new_item->assign_attributes(dummy_as_man_days_string => '5,25', dummy_as_man_days_unit => 'man_day')->dummy, 42, 'assign_attributes hash string 5,25man_day'); +is(new_item->assign_attributes(dummy_as_man_days_unit => 'man_day', dummy_as_man_days_string => '5,25' )->dummy, 42, 'assign_attributes hash string man_day5,25'); + +is(new_item->assign_attributes('dummy_as_man_days_string', '5,25', 'dummy_as_man_days_unit', 'h' )->dummy, 5.25, 'assign_attributes array 5,25h'); +is(new_item->assign_attributes('dummy_as_man_days_unit', 'h', 'dummy_as_man_days_string', '5,25')->dummy, 5.25, 'assign_attributes array h5,25'); + +is(new_item->assign_attributes('dummy_as_man_days_string', '5,25', 'dummy_as_man_days_unit', 'man_day')->dummy, 42, 'assign_attributes array 5,25man_day'); +is(new_item->assign_attributes('dummy_as_man_days_unit', 'man_day', 'dummy_as_man_days_string', '5,25' )->dummy, 42, 'assign_attributes array man_day5,25'); + # Parametervalidierung throws_ok { new_item()->dummy_as_man_days_unit('invalid') } qr/unknown.*unit/i, 'unknown unit'; lives_ok { new_item()->dummy_as_man_days_unit('h') } 'known unit h'; -- 2.20.1