File: dbic.t

package info (click to toggle)
libdata-stream-bulk-perl 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 208 kB
  • sloc: perl: 976; makefile: 2
file content (77 lines) | stat: -rw-r--r-- 1,533 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

use Test::Requires qw(
    DBIx::Class
    DBI
    DBD::SQLite
    Test::TempDir
);

use Test::TempDir 'temp_root';

our $schema;

BEGIN {
	plan skip_all => $@ unless eval {
		{
			package Schema::Foo;
			use base qw(DBIx::Class);

			__PACKAGE__->load_components(qw(Core));

			__PACKAGE__->table("foo");

			__PACKAGE__->add_columns(qw(id name));

			__PACKAGE__->set_primary_key("id");

			package Schema;
			use base qw(DBIx::Class::Schema);

			__PACKAGE__->load_classes(qw(Foo));

			1;
		}

		my $file = temp_root()->file("db");
		$schema = Schema->connect("dbi:SQLite:dbname=$file", undef, undef, { RaiseError => 1 } );
		$schema->storage->dbh->do("create table foo ( id integer primary key, name varchar )");
	};
}

use Data::Stream::Bulk::DBIC;

{
	my $d = Data::Stream::Bulk::DBIC->new( resultset => $schema->resultset("Foo") );

	ok( !$d->is_done, "not done" );

	is_deeply( [ $d->items ], [], "no items" );

	ok( $d->is_done, "now done" );
}

{
	$schema->resultset("Foo")->populate([
		{ name => "hello" },
		{ name => "goodbye" },
	]);

	my $d = Data::Stream::Bulk::DBIC->new( resultset => $schema->resultset("Foo") );

	ok( !$d->is_done, "not done" );
	is_deeply( [ map { $_->name } $d->items ], [ "hello" ], "one item" );
	ok( !$d->is_done, "not done" );
	is_deeply( [ map { $_->name } $d->items ], [ "goodbye" ], "one item" );
	ok( !$d->is_done, "not done" );
	is_deeply( [ $d->items ], [], "no items" );

	ok( $d->is_done, "now done" );
}

done_testing;