Add import-time-skip support to OptDeps, switch most tests over to that
[dbsrgits/DBIx-Class.git] / t / admin / 03data.t
1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'admin';
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8
9 use lib 't/lib';
10 use DBICTest;
11
12 use DBIx::Class::Admin;
13
14 { # test data maniplulation functions
15
16   # create a DBICTest so we can steal its connect info
17   my $schema = DBICTest->init_schema(
18     sqlite_use_file => 1,
19   );
20
21   my $admin = DBIx::Class::Admin->new(
22     schema_class=> "DBICTest::Schema",
23     connect_info => $schema->storage->connect_info(),
24     quiet  => 1,
25     _confirm=>1,
26   );
27   isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
28
29   $admin->insert('Employee', { name => 'Matt' });
30   my $employees = $schema->resultset('Employee');
31   is ($employees->count(), 1, "insert okay" );
32
33   my $employee = $employees->find(1);
34   is($employee->name(),  'Matt', "insert valid" );
35
36   $admin->update('Employee', {name => 'Trout'}, {name => 'Matt'});
37
38   $employee = $employees->find(1);
39   is($employee->name(),  'Trout', "update Matt to Trout" );
40
41   $admin->insert('Employee', {name =>'Aran'});
42
43   my $expected_data = [
44     [$employee->result_source->columns() ],
45     [1,1,undef,undef,undef,'Trout',undef],
46     [2,2,undef,undef,undef,'Aran',undef]
47   ];
48   my $data;
49   lives_ok { $data = $admin->select('Employee', undef, { order_by => 'employee_id' })} 'can retrive data from database';
50   is_deeply($data, $expected_data, 'DB matches whats expected');
51
52   $admin->delete('Employee', {name=>'Trout'});
53   my $del_rs  = $employees->search({name => 'Trout'});
54   is($del_rs->count(), 0, "delete Trout" );
55   is ($employees->count(), 1, "left Aran" );
56 }
57
58 done_testing;