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