DBIx-Class

 view release on metacpan or  search on metacpan

t/60core.t  view on Meta::CPAN

is ($collapsed_or_rs->count, 4, 'Collapsed search count with OR ok');

# make sure sure distinct on a grouped rs is warned about
{
  my $cd_rs = $schema->resultset ('CD')
                ->search ({}, { distinct => 1, group_by => 'title' });
  warnings_exist (sub {
    $cd_rs->next;
  }, qr/Useless use of distinct/, 'UUoD warning');
}

{
  my $tcount = $schema->resultset('Track')->search(
    {},
    {
      select => [ qw/position title/ ],
      distinct => 1,
    }
  );
  is($tcount->count, 13, 'multiple column COUNT DISTINCT ok');

  $tcount = $schema->resultset('Track')->search(
    {},
    {
      columns => [ qw/position title/ ],
      distinct => 1,
    }
  );
  is($tcount->count, 13, 'multiple column COUNT DISTINCT ok');

  $tcount = $schema->resultset('Track')->search(
    {},
    {
       group_by => [ qw/position title/ ]
    }
  );
  is($tcount->count, 13, 'multiple column COUNT DISTINCT using column syntax ok');
}

my $tag_rs = $schema->resultset('Tag')->search(
               [ { 'me.tag' => 'Cheesy' }, { 'me.tag' => 'Blue' } ]);

my $rel_rs = $tag_rs->search_related('cd', {}, { order_by => 'cd.cdid'} );

is($rel_rs->count, 5, 'Related search ok');

is($or_rs->next->cdid, $rel_rs->next->cdid, 'Related object ok');
$or_rs->reset;
$rel_rs->reset;

# at this point there should be no active statements
# (finish() was called everywhere, either explicitly via
# reset() or on DESTROY)
for (keys %{$schema->storage->dbh->{CachedKids}}) {
  fail("Unreachable cached statement still active: $_")
    if $schema->storage->dbh->{CachedKids}{$_}->FETCH('Active');
}

my $tag = $schema->resultset('Tag')->search(
  [ { 'me.tag' => 'Blue' } ],
  { columns => 'tagid' }
)->next;

ok($tag->has_column_loaded('tagid'), 'Has tagid loaded');
ok(!$tag->has_column_loaded('tag'), 'Has not tag loaded');

ok($schema->storage(), 'Storage available');

{
  my $rs = $schema->resultset("Artist")->search({
    -and => [
      artistid => { '>=', 1 },
      artistid => { '<', 3 }
    ]
  });

  $rs->update({ rank => 6134 });

  my $art;

  $art = $schema->resultset("Artist")->find(1);
  is($art->rank, 6134, 'updated first artist rank');

  $art = $schema->resultset("Artist")->find(2);
  is($art->rank, 6134, 'updated second artist rank');
}

# test source_name
{
  # source_name should be set for normal modules
  is($schema->source('CD')->source_name, 'CD', 'source_name is set to moniker');

  # test the result source that sets source_name explictly
  ok($schema->source('SourceNameArtists'), 'SourceNameArtists result source exists');

  my @artsn = $schema->resultset('SourceNameArtists')->search({}, { order_by => 'name DESC' });
  is(@artsn, 4, "Four artists returned");

  # make sure subclasses that don't set source_name are ok
  ok($schema->source('ArtistSubclass'), 'ArtistSubclass exists');
}

my $newbook = $schema->resultset( 'Bookmark' )->find(1);

lives_ok (sub { my $newlink = $newbook->link}, "stringify to false value doesn't cause error");

# test cascade_delete through many_to_many relations
{
  my $art_del = $schema->resultset("Artist")->find({ artistid => 1 });
  lives_ok (sub { $art_del->delete }, 'Cascading delete on Ordered has_many works' );  # real test in ordered.t
  is( $schema->resultset("CD")->search({artist => 1}), 0, 'Cascading through has_many top level.');
  is( $schema->resultset("CD_to_Producer")->search({cd => 1}), 0, 'Cascading through has_many children.');
}

# test column_info
{
  $schema->source("Artist")->{_columns}{'artistid'} = {};
  $schema->source("Artist")->column_info_from_storage(1);

  my $typeinfo = $schema->source("Artist")->column_info('artistid');
  is($typeinfo->{data_type}, 'INTEGER', 'column_info ok');
  $schema->source("Artist")->column_info('artistid');
  ok($schema->source("Artist")->{_columns_info_loaded} == 1, 'Columns info loaded flag set');
}



( run in 0.625 second using v1.01-cache-2.11-cpan-5735350b133 )