Commit | Line | Data |
cb551b07 |
1 | use DBIx::Class::Optional::Dependencies -skip_all_without => 'admin'; |
2 | |
a1696195 |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
a1696195 |
7 | use Test::Exception; |
a1696195 |
8 | |
4bea1fe7 |
9 | use lib 't/lib'; |
10 | use DBICTest; |
11 | |
cb551b07 |
12 | use DBIx::Class::Admin; |
751a68cc |
13 | { |
14 | # no questions |
15 | no warnings 'redefine'; |
16 | *DBIx::Class::Admin::_confirm = sub { 1 }; |
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, |
1edd4ca6 |
30 | ); |
31 | isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object'); |
32 | |
33 | $admin->insert('Employee', { name => 'Matt' }); |
34 | my $employees = $schema->resultset('Employee'); |
35 | is ($employees->count(), 1, "insert okay" ); |
36 | |
37 | my $employee = $employees->find(1); |
38 | is($employee->name(), 'Matt', "insert valid" ); |
39 | |
40 | $admin->update('Employee', {name => 'Trout'}, {name => 'Matt'}); |
41 | |
42 | $employee = $employees->find(1); |
43 | is($employee->name(), 'Trout', "update Matt to Trout" ); |
44 | |
45 | $admin->insert('Employee', {name =>'Aran'}); |
46 | |
8273e845 |
47 | my $expected_data = [ |
1edd4ca6 |
48 | [$employee->result_source->columns() ], |
68888c09 |
49 | [1,1,undef,undef,undef,'Trout',undef], |
50 | [2,2,undef,undef,undef,'Aran',undef] |
1edd4ca6 |
51 | ]; |
52 | my $data; |
fb88ca2c |
53 | lives_ok { $data = $admin->select('Employee', undef, { order_by => 'employee_id' })} 'can retrive data from database'; |
26831042 |
54 | is_deeply($data, $expected_data, 'DB matches whats expected'); |
1edd4ca6 |
55 | |
56 | $admin->delete('Employee', {name=>'Trout'}); |
57 | my $del_rs = $employees->search({name => 'Trout'}); |
58 | is($del_rs->count(), 0, "delete Trout" ); |
59 | is ($employees->count(), 1, "left Aran" ); |
a1696195 |
60 | } |
61 | |
a1696195 |
62 | done_testing; |