add sleep 1 to t/admin/02ddl.t so insert into upgrade table does not happen too quickly
[dbsrgits/DBIx-Class.git] / t / admin / 03data.t
CommitLineData
a1696195 1#
2#===============================================================================
3#
4# FILE: 03sql.t
5#
6# DESCRIPTION: test sql manipulation funtions
7#
8# FILES: ---
9# BUGS: ---
10# NOTES: ---
11# AUTHOR: Gordon Irving (), <Gordon.irving@sophos.com>
12# VERSION: 1.0
13# CREATED: 12/12/09 12:44:57 GMT
14# REVISION: ---
15#===============================================================================
16
17use strict;
18use warnings;
19
20use Test::More;
21
22use Test::Exception;
23use Test::Deep;
24
25use Path::Class;
26use FindBin qw($Bin);
27
28use lib dir($Bin,'..', '..','lib')->stringify;
29use lib dir($Bin,'..', 'lib')->stringify;
30
31use ok 'DBIx::Class::Admin';
32
33use DBICTest;
34
35{ # test data maniplulation functions
36
37 # create a DBICTest so we can steal its connect info
38 my $schema = DBICTest->init_schema(
39 # no_deploy=>1,
40 # no_populate=>1,
41 sqlite_use_file => 1,
42 );
43
44
45 my $admin = DBIx::Class::Admin->new(
46 schema_class=> "DBICTest::Schema",
47 connect_info => $schema->storage->connect_info(),
48 quiet => 1,
49 _confirm=>1,
50 );
51 isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
52
53 $admin->insert_data('Employee', { name => 'Matt' });
54 my $employees = $schema->resultset('Employee');
55 is ($employees->count(), 1, "insert okay" );
56
57 my $employee = $employees->find(1);
58 is($employee->name(), 'Matt', "insert valid" );
59
60 $admin->update_data('Employee', {name => 'Trout'}, {name => 'Matt'});
61
62 $employee = $employees->find(1);
63 is($employee->name(), 'Trout', "update Matt to Trout" );
64
65 $admin->insert_data('Employee', {name =>'Aran'});
66
67 my $expected_data = [
68 [$employee->result_source->columns() ],
69 [1,1,undef,undef,undef,'Trout'],
70 [2,2,undef,undef,undef,'Aran']
71 ];
72 my $data;
73 lives_ok { $data = $admin->select_data('Employee')} 'can retrive data from database';
74 cmp_deeply($data, $expected_data, 'DB matches whats expected');
75
76 $admin->delete_data('Employee', {name=>'Trout'});
77 my $del_rs = $employees->search({name => 'Trout'});
78 is($del_rs->count(), 0, "delete Trout" );
79 is ($employees->count(), 1, "left Aran" );
80}
81
82
83
84done_testing;