More tets cleanup
[dbsrgits/DBIx-Class.git] / t / admin / 03data.t
CommitLineData
a705b175 1#
a1696195 2#===============================================================================
3#
4# FILE: 03sql.t
5#
6# DESCRIPTION: test sql manipulation funtions
7#
8# FILES: ---
9# BUGS: ---
10# NOTES: ---
6bceaca3 11# AUTHOR: Gordon Irving (), <goraxe@cpan.org>
a1696195 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
6bceaca3 25BEGIN {
fd9c9ced 26
27 use FindBin qw($Bin);
28 use File::Spec::Functions qw(catdir);
29 use lib catdir($Bin,'..', '..','lib');
30 use lib catdir($Bin,'..', 'lib');
6bceaca3 31 eval "use DBIx::Class::Admin";
32 plan skip_all => "Deps not installed: $@" if $@;
33}
34
a1696195 35use Path::Class;
a1696195 36
37use ok 'DBIx::Class::Admin';
38
39use DBICTest;
40
41{ # test data maniplulation functions
42
1edd4ca6 43 # create a DBICTest so we can steal its connect info
44 my $schema = DBICTest->init_schema(
45 # no_deploy=>1,
46 # no_populate=>1,
47 sqlite_use_file => 1,
48 );
49
50
51 my $admin = DBIx::Class::Admin->new(
52 schema_class=> "DBICTest::Schema",
53 connect_info => $schema->storage->connect_info(),
54 quiet => 1,
55 _confirm=>1,
56 );
57 isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
58
59 $admin->insert('Employee', { name => 'Matt' });
60 my $employees = $schema->resultset('Employee');
61 is ($employees->count(), 1, "insert okay" );
62
63 my $employee = $employees->find(1);
64 is($employee->name(), 'Matt', "insert valid" );
65
66 $admin->update('Employee', {name => 'Trout'}, {name => 'Matt'});
67
68 $employee = $employees->find(1);
69 is($employee->name(), 'Trout', "update Matt to Trout" );
70
71 $admin->insert('Employee', {name =>'Aran'});
72
73 my $expected_data = [
74 [$employee->result_source->columns() ],
75 [1,1,undef,undef,undef,'Trout'],
76 [2,2,undef,undef,undef,'Aran']
77 ];
78 my $data;
79 lives_ok { $data = $admin->select('Employee')} 'can retrive data from database';
80 cmp_deeply($data, $expected_data, 'DB matches whats expected');
81
82 $admin->delete('Employee', {name=>'Trout'});
83 my $del_rs = $employees->search({name => 'Trout'});
84 is($del_rs->count(), 0, "delete Trout" );
85 is ($employees->count(), 1, "left Aran" );
a1696195 86}
87
88
89
90done_testing;