DBIx-Class-MoreHelpers

 view release on metacpan or  search on metacpan

lib/DBIx/Class/Helper/ResultSet/Shortcut/Search/Is.pm  view on Meta::CPAN


DBIx::Class::Helper::ResultSet::Shortcut::Search::Is

=head1 VERSION

version 1.0001

=head2 is(@columns || \@columns)

 $rs->is('active');
 $rs->is(['active', 'blocked']);

=head1 AUTHOR

D Ruth Holloway <ruth@hiruthie.me>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by D Ruth Holloway.

This is free software; you can redistribute it and/or modify it under

lib/DBIx/Class/Helper/ResultSet/Shortcut/Search/IsNot.pm  view on Meta::CPAN


DBIx::Class::Helper::ResultSet::Shortcut::Search::IsNot

=head1 VERSION

version 1.0001

=head2 is_not(@columns || \@columns)

 $rs->is_not('active');
 $rs->is_not(['active', 'blocked']);

=head1 AUTHOR

D Ruth Holloway <ruth@hiruthie.me>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by D Ruth Holloway.

This is free software; you can redistribute it and/or modify it under

lib/DBIx/Class/Helper/ResultSet/Shortcut/Search/Negative.pm  view on Meta::CPAN


DBIx::Class::Helper::ResultSet::Shortcut::Search::Negative

=head1 VERSION

version 1.0001

=head2 negative(@columns || \@columns)

 $rs->negative('active');
 $rs->negative(['active', 'blocked']);

=head1 AUTHOR

D Ruth Holloway <ruth@hiruthie.me>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by D Ruth Holloway.

This is free software; you can redistribute it and/or modify it under

lib/DBIx/Class/Helper/ResultSet/Shortcut/Search/Nonzero.pm  view on Meta::CPAN


DBIx::Class::Helper::ResultSet::Shortcut::Search::Nonzero

=head1 VERSION

version 1.0001

=head2 nonzero(@columns || \@columns)

 $rs->nonzero('active');
 $rs->nonzero(['active', 'blocked']);

=head1 AUTHOR

D Ruth Holloway <ruth@hiruthie.me>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by D Ruth Holloway.

This is free software; you can redistribute it and/or modify it under

lib/DBIx/Class/Helper/ResultSet/Shortcut/Search/NullOrZero.pm  view on Meta::CPAN


DBIx::Class::Helper::ResultSet::Shortcut::Search::NullOrZero

=head1 VERSION

version 1.0001

=head2 null_or_zero(@columns || \@columns)

 $rs->null_or_zero('active');
 $rs->null_or_zero(['active', 'blocked']);

=head1 AUTHOR

D Ruth Holloway <ruth@hiruthie.me>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by D Ruth Holloway.

This is free software; you can redistribute it and/or modify it under

lib/DBIx/Class/Helper/ResultSet/Shortcut/Search/Positive.pm  view on Meta::CPAN


DBIx::Class::Helper::ResultSet::Shortcut::Search::Positive

=head1 VERSION

version 1.0001

=head2 positive(@columns || \@columns)

 $rs->positive('active');
 $rs->positive(['active', 'blocked']);

=head1 AUTHOR

D Ruth Holloway <ruth@hiruthie.me>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by D Ruth Holloway.

This is free software; you can redistribute it and/or modify it under

t/002_is.t  view on Meta::CPAN

use FindBin qw($Bin);
use lib "$Bin/../lib";
use lib 't/lib';

plan(7);

use Test::DBIx::Class { schema_class => 'TestSchema' }, 'Contraption';

fixtures_ok [
   Contraption => [
      [ 'id', 'color',   'active', 'blocked' ],
      [ '1',  'blue',    'true', 'false' ],
      [ '2',  'purple',  'true', 'true' ],
      [ '3',  'green',   'false', 'true' ],
      [ '4',  'magenta', 'false', 'false' ],
   ],
], 'Installed fixtures';

subtest 'is finds true entries for a single field properly' => sub {
   plan(3);
   my $rs = Contraption->is('active')->search({}, {order_by => ['id']});
   ok (ref $rs eq 'TestSchema::ResultSet', 'returns a ResultSet');
   ok ($rs->count == 2, 'Correctly found the right number of records');
   my @ids = $rs->get_column('id')->all;
   is ( \@ids, [qw/1 2/], 'Correct records found, in the right order');
};

subtest 'is finds true entries for multiple fields properly' => sub {
   plan(3);
   my $rs = Contraption->is([ 'active', 'blocked'])->search({}, {order_by => ['id']});
   ok (ref $rs eq 'TestSchema::ResultSet', 'returns a ResultSet');
   ok ($rs->count == 1, 'Correctly found the right number of records');
   my @ids = $rs->get_column('id')->all;
   is ( \@ids, [qw/2/], 'Correct records found, in correct order');
};

subtest 'is_not finds false entries for a single field properly' => sub {
   plan(3);
   my $rs = Contraption->is_not('active')->search({}, {order_by => ['id']});
   ok (ref $rs eq 'TestSchema::ResultSet', 'returns a ResultSet');
   ok ($rs->count == 2, 'Correctly found the right number of records');
   my @ids = $rs->get_column('id')->all;
   is ( \@ids, [qw/3 4/], 'Correct records found, in the right order');
};

subtest 'is_not finds false entries for multiple fields properly' => sub {
   plan(3);
   my $rs = Contraption->is_not([ 'active', 'blocked'])->search({}, {order_by => ['id']});
   ok (ref $rs eq 'TestSchema::ResultSet', 'returns a ResultSet');
   ok ($rs->count == 1, 'Correctly found the right number of records');
   my @ids = $rs->get_column('id')->all;
   is ( \@ids, [qw/4/], 'Correct records found, in correct order');
};

subtest 'is_any dies if you send it a single field' => sub {
   plan(1);
   my $rs;
   like( dies{ $rs = Contraption->is_any('active')->search({}, {order_by => ['id']}); },
         qr/Why would you only send one column to is_any\?/);
};

subtest 'is_any finds true entries for multiple fields properly' => sub {
   plan(3);
   my $rs = Contraption->is_any([ 'active', 'blocked'])->search({}, {order_by => ['id']});
   ok (ref $rs eq 'TestSchema::ResultSet', 'returns a ResultSet');
   ok ($rs->count == 3, 'Correctly found the right number of records');
   my @ids = $rs->get_column('id')->all;
   is ( \@ids, [qw/1 2 3/], 'Correct records found, in correct order');
};


exit;

t/lib/TestSchema/Result/Contraption.pm  view on Meta::CPAN

package TestSchema::Result::Contraption;
use Modern::Perl;
use base qw(DBIx::Class::Core);

__PACKAGE__->table('contraption');
__PACKAGE__->add_columns(qw(id color));
__PACKAGE__->add_columns( status => { is_nullable => 1, }, );
__PACKAGE__->add_columns( note => { is_nullable => 1, }, );
__PACKAGE__->add_columns( active => { data_type => 'boolean', default_value => 'true' });
__PACKAGE__->add_columns( blocked => { data_type => 'boolean', default_value => 'false' });
__PACKAGE__->add_columns( size => { data_type => 'numeric', is_nullable => 1 });
__PACKAGE__->add_columns( quantity => { data_type => 'numeric', default_value => 0 });
__PACKAGE__->set_primary_key('id');

1;



( run in 0.570 second using v1.01-cache-2.11-cpan-49f99fa48dc )