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

(-)a/Koha/BackgroundJobs.pm (-4 / +24 lines)
Lines 16-33 package Koha::BackgroundJobs; Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use base qw(Koha::Objects);
19
20
use Koha::BackgroundJob;
20
use Koha::BackgroundJob;
21
21
22
use base qw(Koha::Objects);
23
22
=head1 NAME
24
=head1 NAME
23
25
24
Koha::BackgroundJobs - Koha BackgroundJob Object set class
26
Koha::BackgroundJobs - Koha BackgroundJob Object set class
25
27
26
=head1 API
28
=head1 API
27
29
28
=head2 Class Methods
30
=head2 Class methods
29
30
=cut
31
31
32
=head2 search_limited
32
=head2 search_limited
33
33
Lines 57-62 sub search_limited { Link Here
57
      ->search( $params, $attributes );
57
      ->search( $params, $attributes );
58
}
58
}
59
59
60
=head3 filter_by_current
61
62
    my $current_jobs = $jobs->filter_by_current;
63
64
Returns a new resultset, filtering out finished jobs.
65
66
=cut
67
68
sub filter_by_current {
69
    my ($self) = @_;
70
71
    return $self->search(
72
        {
73
            status => { not_in => [ 'cancelled', 'failed', 'finished' ] }
74
        }
75
    );
76
}
77
78
=head2 Internal methods
79
60
=head3 _type
80
=head3 _type
61
81
62
=cut
82
=cut
(-)a/t/db_dependent/Koha/BackgroundJobs.t (-3 / +33 lines)
Lines 19-27 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 12;
22
use Test::More tests => 13;
23
use Test::MockModule;
23
use Test::MockModule;
24
24
25
use List::MoreUtils qw(any);
26
25
use Koha::Database;
27
use Koha::Database;
26
use Koha::BackgroundJobs;
28
use Koha::BackgroundJobs;
27
use Koha::DateUtils qw( dt_from_string );
29
use Koha::DateUtils qw( dt_from_string );
Lines 31-37 use t::lib::Mocks; Link Here
31
use t::lib::Dates;
33
use t::lib::Dates;
32
use t::lib::Koha::BackgroundJob::BatchTest;
34
use t::lib::Koha::BackgroundJob::BatchTest;
33
35
34
my $schema = Koha::Database->new->schema;
36
my $builder = t::lib::TestBuilder->new;
37
my $schema  = Koha::Database->new->schema;
35
$schema->storage->txn_begin;
38
$schema->storage->txn_begin;
36
39
37
t::lib::Mocks::mock_userenv;
40
t::lib::Mocks::mock_userenv;
Lines 91-93 is_deeply( Link Here
91
is_deeply( $new_job->additional_report(), {} );
94
is_deeply( $new_job->additional_report(), {} );
92
95
93
$schema->storage->txn_rollback;
96
$schema->storage->txn_rollback;
94
- 
97
98
subtest 'filter_by_current() tests' => sub {
99
100
    plan tests => 4;
101
102
    $schema->storage->txn_begin;
103
104
    my $job_new       = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'new' } } );
105
    my $job_cancelled = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'cancelled' } } );
106
    my $job_failed    = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'failed' } } );
107
    my $job_finished  = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'finished' } } );
108
109
    my $rs = Koha::BackgroundJobs->search(
110
        {
111
            id => [ $job_new->id, $job_cancelled->id, $job_failed->id, $job_finished->id ]
112
        }
113
    );
114
115
    is( $rs->count, 4, '4 jobs in resultset' );
116
    ok( any {$_->status eq 'new'} @{$rs->as_list}, "There is a 'new' job"  );
117
118
    $rs = $rs->filter_by_current;
119
120
    is( $rs->count, 1, 'Only 1 job in filtered resultset' );
121
    is( $rs->next->status, 'new', "The only job in resultset is 'new'"  );
122
123
    $schema->storage->txn_rollback;
124
};

Return to bug 30982