View | Details | Raw Unified | Return to bug 38273
Collapse All | Expand All

(-)a/Koha/Object.pm (-1 / +14 lines)
Lines 218-223 sub store { Link Here
218
    }
218
    }
219
}
219
}
220
220
221
222
=head3 discard_changes
223
224
Refetch the row from the DB
225
226
=cut
227
228
sub discard_changes {
229
    my ($self) = @_;
230
    my $object_class = Koha::Object::_get_object_class( $self->_result->result_class );
231
    return $object_class->_new_from_dbic( $self->_result->discard_changes );
232
}
233
221
=head3 $object->update();
234
=head3 $object->update();
222
235
223
A shortcut for set + store in one call.
236
A shortcut for set + store in one call.
Lines 1020-1026 sub AUTOLOAD { Link Here
1020
        return $accessor->( $self, @_ );
1033
        return $accessor->( $self, @_ );
1021
    }
1034
    }
1022
1035
1023
    my @known_methods = qw( is_changed id in_storage get_column discard_changes make_column_dirty );
1036
    my @known_methods = qw( is_changed id in_storage get_column make_column_dirty );
1024
1037
1025
    Koha::Exceptions::Object::MethodNotCoveredByTests->throw(
1038
    Koha::Exceptions::Object::MethodNotCoveredByTests->throw(
1026
        error      => sprintf("The method %s->%s is not covered by tests!", ref($self), $method),
1039
        error      => sprintf("The method %s->%s is not covered by tests!", ref($self), $method),
(-)a/t/db_dependent/Koha/Object.t (-2 / +12 lines)
Lines 153-159 subtest 'get_column' => sub { Link Here
153
};
153
};
154
154
155
subtest 'discard_changes' => sub {
155
subtest 'discard_changes' => sub {
156
    plan tests => 1;
156
    plan tests => 3;
157
157
158
    $schema->storage->txn_begin;
158
    $schema->storage->txn_begin;
159
159
Lines 166-171 subtest 'discard_changes' => sub { Link Here
166
        dt_from_string->truncate( to => 'day' ),
166
        dt_from_string->truncate( to => 'day' ),
167
        'discard_changes should refresh the object'
167
        'discard_changes should refresh the object'
168
    );
168
    );
169
    my $cardnumber   = $patron->cardnumber;
170
    my $categorycode = $patron->categorycode;
171
    my $branchcode   = $patron->branchcode;
172
    $patron->delete;
173
174
    $patron =
175
        Koha::Patron->new( { cardnumber => $cardnumber, categorycode => $categorycode, branchcode => $branchcode } )
176
        ->store->discard_changes;
177
178
    is( ref($patron), 'Koha::Patron', 'discard_changes should return a Koha::Object object' );
179
    isnt( $patron->updated_on, undef, 'discard_changes should have fetched the row from the DB' );
169
180
170
    $schema->storage->txn_rollback;
181
    $schema->storage->txn_rollback;
171
};
182
};
172
- 

Return to bug 38273