Commit | Line | Data |
c0329273 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
cb551b07 |
2 | use DBIx::Class::Optional::Dependencies -skip_all_without => 'admin'; |
3 | |
a1696195 |
4 | use strict; |
5 | use warnings; |
6 | |
7 | use Test::More; |
a1696195 |
8 | use Test::Exception; |
a1696195 |
9 | |
c0329273 |
10 | |
4bea1fe7 |
11 | use DBICTest; |
12 | |
cb551b07 |
13 | use DBIx::Class::Admin; |
a1696195 |
14 | |
15 | { # test data maniplulation functions |
16 | |
1edd4ca6 |
17 | # create a DBICTest so we can steal its connect info |
18 | my $schema = DBICTest->init_schema( |
1edd4ca6 |
19 | sqlite_use_file => 1, |
72cfa3b3 |
20 | ); |
1edd4ca6 |
21 | |
22 | my $admin = DBIx::Class::Admin->new( |
23 | schema_class=> "DBICTest::Schema", |
24 | connect_info => $schema->storage->connect_info(), |
25 | quiet => 1, |
26 | _confirm=>1, |
27 | ); |
28 | isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object'); |
29 | |
30 | $admin->insert('Employee', { name => 'Matt' }); |
31 | my $employees = $schema->resultset('Employee'); |
32 | is ($employees->count(), 1, "insert okay" ); |
33 | |
34 | my $employee = $employees->find(1); |
35 | is($employee->name(), 'Matt', "insert valid" ); |
36 | |
37 | $admin->update('Employee', {name => 'Trout'}, {name => 'Matt'}); |
38 | |
39 | $employee = $employees->find(1); |
40 | is($employee->name(), 'Trout', "update Matt to Trout" ); |
41 | |
42 | $admin->insert('Employee', {name =>'Aran'}); |
43 | |
8273e845 |
44 | my $expected_data = [ |
1edd4ca6 |
45 | [$employee->result_source->columns() ], |
68888c09 |
46 | [1,1,undef,undef,undef,'Trout',undef], |
47 | [2,2,undef,undef,undef,'Aran',undef] |
1edd4ca6 |
48 | ]; |
49 | my $data; |
fb88ca2c |
50 | lives_ok { $data = $admin->select('Employee', undef, { order_by => 'employee_id' })} 'can retrive data from database'; |
26831042 |
51 | is_deeply($data, $expected_data, 'DB matches whats expected'); |
1edd4ca6 |
52 | |
53 | $admin->delete('Employee', {name=>'Trout'}); |
54 | my $del_rs = $employees->search({name => 'Trout'}); |
55 | is($del_rs->count(), 0, "delete Trout" ); |
56 | is ($employees->count(), 1, "left Aran" ); |
a1696195 |
57 | } |
58 | |
a1696195 |
59 | done_testing; |