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