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