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

(-)a/Koha/Patron/Attribute.pm (-14 / +8 lines)
Lines 60-69 sub store { Link Here
60
        unless $type;
60
        unless $type;
61
61
62
    Koha::Exceptions::Patron::Attribute::NonRepeatable->throw( attribute => $self )
62
    Koha::Exceptions::Patron::Attribute::NonRepeatable->throw( attribute => $self )
63
        unless $self->repeatable_ok($type);
63
        unless $self->repeatable_ok();
64
64
65
    Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw( attribute => $self )
65
    Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw( attribute => $self )
66
        unless $self->unique_ok($type);
66
        unless $self->unique_ok();
67
67
68
    return $self->SUPER::store();
68
    return $self->SUPER::store();
69
}
69
}
Lines 146-152 sub to_api_mapping { Link Here
146
146
147
=head3 repeatable_ok
147
=head3 repeatable_ok
148
148
149
    if ( $attr->repeatable_ok( $type ) ) { ... }
149
    if ( $attr->repeatable_ok() ) { ... }
150
150
151
Checks if the attribute type is repeatable and returns a boolean representing
151
Checks if the attribute type is repeatable and returns a boolean representing
152
whether storing the current object state would break the repeatable constraint.
152
whether storing the current object state would break the repeatable constraint.
Lines 155-167 whether storing the current object state would break the repeatable constraint. Link Here
155
155
156
sub repeatable_ok {
156
sub repeatable_ok {
157
157
158
    my ( $self, $type ) = @_;
158
    my ( $self ) = @_;
159
160
    Koha::Exceptions::MissingParameter->throw( "The type parameter is mandatory" )
161
        unless $type;
162
159
163
    my $ok = 1;
160
    my $ok = 1;
164
    if ( !$type->repeatable ) {
161
    if ( !$self->type->repeatable ) {
165
        my $params = {
162
        my $params = {
166
            borrowernumber => $self->borrowernumber,
163
            borrowernumber => $self->borrowernumber,
167
            code           => $self->code
164
            code           => $self->code
Lines 178-184 sub repeatable_ok { Link Here
178
175
179
=head3 unique_ok
176
=head3 unique_ok
180
177
181
    if ( $attr->unique_ok( $type ) ) { ... }
178
    if ( $attr->unique_ok() ) { ... }
182
179
183
Checks if the attribute type is marked as unique and returns a boolean representing
180
Checks if the attribute type is marked as unique and returns a boolean representing
184
whether storing the current object state would break the unique constraint.
181
whether storing the current object state would break the unique constraint.
Lines 187-199 whether storing the current object state would break the unique constraint. Link Here
187
184
188
sub unique_ok {
185
sub unique_ok {
189
186
190
    my ( $self, $type ) = @_;
187
    my ( $self ) = @_;
191
192
    Koha::Exceptions::MissingParameter->throw( "The type parameter is mandatory" )
193
        unless $type;
194
188
195
    my $ok = 1;
189
    my $ok = 1;
196
    if ( $type->unique_id ) {
190
    if ( $self->type->unique_id ) {
197
        my $params = { code => $self->code, attribute => $self->attribute };
191
        my $params = { code => $self->code, attribute => $self->attribute };
198
192
199
        $params->{borrowernumber} = { '!=' => $self->borrowernumber } if $self->borrowernumber;
193
        $params->{borrowernumber} = { '!=' => $self->borrowernumber } if $self->borrowernumber;
(-)a/t/db_dependent/Koha/Patron/Attribute.t (-37 / +1 lines)
Lines 19-31 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 2;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use Test::Exception;
25
use Test::Exception;
26
26
27
use Koha::Database;
27
use Koha::Database;
28
use Koha::Patron::Attribute;
29
use Koha::Patron::Attributes;
28
use Koha::Patron::Attributes;
30
29
31
my $schema  = Koha::Database->new->schema;
30
my $schema  = Koha::Database->new->schema;
Lines 288-324 subtest 'type() tests' => sub { Link Here
288
287
289
    $schema->storage->txn_rollback;
288
    $schema->storage->txn_rollback;
290
};
289
};
291
292
subtest 'repeatable_ok() tests' => sub {
293
294
    plan tests => 1;
295
296
    my $attr = Koha::Patron::Attribute->new(
297
        {
298
            attribute => 'something',
299
            code      => 'some code'
300
        }
301
    );
302
303
    throws_ok
304
        { $attr->repeatable_ok(); }
305
        'Koha::Exceptions::MissingParameter',
306
        'Exception on missing type attribute';
307
};
308
309
subtest 'unique_ok() tests' => sub {
310
311
    plan tests => 1;
312
313
    my $attr = Koha::Patron::Attribute->new(
314
        {
315
            attribute => 'something',
316
            code      => 'some code'
317
        }
318
    );
319
320
    throws_ok
321
        { $attr->unique_ok(); }
322
        'Koha::Exceptions::MissingParameter',
323
        'Exception on missing type attribute';
324
};
325
- 

Return to bug 28031