More detabification
[dbsrgits/DBIx-Class.git] / t / admin / 03data.t
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 (), <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
27     use FindBin qw($Bin);
28     use File::Spec::Functions qw(catdir);
29     use lib catdir($Bin,'..', '..','lib');
30     use lib catdir($Bin,'..', 'lib');
31     eval "use DBIx::Class::Admin";
32     plan skip_all => "Deps not installed: $@" if $@;
33 }
34
35 use Path::Class;
36
37 use ok 'DBIx::Class::Admin';
38
39 use DBICTest;
40
41 { # test data maniplulation functions
42
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" );
86 }
87
88
89
90 done_testing;