Bug 23185: (QA follow-up) Semantics, split fields and options
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 1 May 2020 13:12:09 +0000 (14:12 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 5 May 2020 09:58:14 +0000 (10:58 +0100)
This patch improves the semantics of the update routine to more clearly
separate the 'fields' we're modifying from the 'options' we wish to
apply to the modification.

Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/Objects.pm
t/db_dependent/Koha/Objects.t

index 7512f26..9427192 100644 (file)
@@ -199,9 +199,9 @@ sub delete {
 =cut
 
 sub update {
-    my ($self, $params) = @_;
+    my ($self, $fields, $options) = @_;
 
-    my $no_triggers = delete $params->{no_triggers};
+    my $no_triggers = $options->{no_triggers};
 
     if (
         !$no_triggers
@@ -212,14 +212,14 @@ sub update {
         my $objects_updated;
         $self->_resultset->result_source->schema->txn_do( sub {
             while ( my $o = $self->next ) {
-                $o->update($params);
+                $o->update($fields);
                 $objects_updated++;
             }
         });
         return $objects_updated;
     }
 
-    return $self->_resultset->update($params);
+    return $self->_resultset->update($fields);
 }
 
 =head3 single
index beeac1b..96a6bc6 100644 (file)
@@ -995,7 +995,7 @@ subtest 'Return same values as DBIx::Class' => sub {
                 $patrons_us->update({ surname => 'foo' }); # Koha::Patron->store is supposed to uppercase the surnames
                 is( $patrons_us->search({ surname => 'FOO' })->count, 2, 'Koha::Patron->store is hit' );
 
-                $patrons_us->update({ surname => 'foo', no_triggers => 1 }); # The surnames won't be uppercase as we won't hit Koha::Patron->store
+                $patrons_us->update({ surname => 'foo' }, { no_triggers => 1 }); # The surnames won't be uppercase as we won't hit Koha::Patron->store
                 is( $patrons_us->search({ surname => 'foo' })->count, 2, 'Koha::Patron->store is not hit');
 
             };