Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 6395006f

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

AttrDuration: in SL::DB::Object->assign_attributes() auch attr_man_days_string() vor _unit() auswerten

Unterschiede anzeigen:

SL/DB/Object.pm
60 60

  
61 61
  my %types      = map { $_->name => $_->type } ref($self)->meta->columns;
62 62

  
63
  # Special case for *_as_man_days/*_as_man_days_unit: the _unit
64
  # variation must always be called after the non-unit method.
65
  my @man_days_attributes = grep { m/_as_man_days$/ } keys %attributes;
63
  # Special case for *_as_man_days / *_as_man_days_string /
64
  # *_as_man_days_unit: the _unit variation must always be called
65
  # after the non-unit methods.
66
  my @man_days_attributes = grep { m/_as_man_days(?:_string)?$/ } keys %attributes;
66 67
  foreach my $attribute (@man_days_attributes) {
67 68
    my $value = delete $attributes{$attribute};
68 69
    $self->$attribute(defined($value) && ($value eq '') ? undef : $value);
t/db_helper/attr_duration.t
13 13

  
14 14
package main;
15 15

  
16
use Test::More tests => 83;
16
use Test::More tests => 91;
17 17
use Test::Exception;
18 18

  
19 19
use strict;
......
147 147
is(new_item->assign_attributes('dummy_as_man_days',      3,         'dummy_as_man_days_unit', 'man_day')->dummy, 24, 'assign_attributes array 3man_day');
148 148
is(new_item->assign_attributes('dummy_as_man_days_unit', 'man_day', 'dummy_as_man_days',      3        )->dummy, 24, 'assign_attributes array man_day3');
149 149

  
150
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');
151
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');
152

  
153
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');
154
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');
155

  
156
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');
157
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');
158

  
159
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');
160
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');
161

  
150 162
# Parametervalidierung
151 163
throws_ok { new_item()->dummy_as_man_days_unit('invalid') } qr/unknown.*unit/i, 'unknown unit';
152 164
lives_ok  { new_item()->dummy_as_man_days_unit('h')       } 'known unit h';

Auch abrufbar als: Unified diff