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