Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / t / admin / 03data.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'admin';
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8 use Test::Exception;
9
10
11 use DBICTest;
12
13 use DBIx::Class::Admin;
14
15 { # test data maniplulation functions
16
17   # create a DBICTest so we can steal its connect info
18   my $schema = DBICTest->init_schema(
19     sqlite_use_file => 1,
20   );
21
22   my $storage = $schema->storage;
23   $storage = $storage->master
24     if $storage->isa('DBIx::Class::Storage::DBI::Replicated');
25
26   my $admin = DBIx::Class::Admin->new(
27     schema_class=> "DBICTest::Schema",
28     connect_info => $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() ],
50     [1,1,undef,undef,undef,'Trout',undef],
51     [2,2,undef,undef,undef,'Aran',undef]
52   ];
53   my $data;
54   lives_ok { $data = $admin->select('Employee', undef, { order_by => 'employee_id' })} 'can retrive data from database';
55   is_deeply($data, $expected_data, 'DB matches whats expected');
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" );
61 }
62
63 done_testing;