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