Commit | Line | Data |
a705b175 |
1 | # |
a1696195 |
2 | #=============================================================================== |
3 | # |
4 | # FILE: 03sql.t |
5 | # |
6 | # DESCRIPTION: test sql manipulation funtions |
7 | # |
8 | # FILES: --- |
9 | # BUGS: --- |
10 | # NOTES: --- |
6bceaca3 |
11 | # AUTHOR: Gordon Irving (), <goraxe@cpan.org> |
a1696195 |
12 | # VERSION: 1.0 |
13 | # CREATED: 12/12/09 12:44:57 GMT |
14 | # REVISION: --- |
15 | #=============================================================================== |
16 | |
17 | use strict; |
18 | use warnings; |
19 | |
20 | use Test::More; |
21 | |
22 | use Test::Exception; |
23 | use Test::Deep; |
24 | |
6bceaca3 |
25 | BEGIN { |
26 | eval "use DBIx::Class::Admin"; |
27 | plan skip_all => "Deps not installed: $@" if $@; |
28 | } |
29 | |
72cfa3b3 |
30 | use lib 't/lib'; |
31 | use DBICTest; |
a1696195 |
32 | |
33 | use ok 'DBIx::Class::Admin'; |
34 | |
a1696195 |
35 | |
36 | { # test data maniplulation functions |
37 | |
1edd4ca6 |
38 | # create a DBICTest so we can steal its connect info |
39 | my $schema = DBICTest->init_schema( |
1edd4ca6 |
40 | sqlite_use_file => 1, |
72cfa3b3 |
41 | ); |
1edd4ca6 |
42 | |
43 | my $admin = DBIx::Class::Admin->new( |
44 | schema_class=> "DBICTest::Schema", |
45 | connect_info => $schema->storage->connect_info(), |
46 | quiet => 1, |
47 | _confirm=>1, |
48 | ); |
49 | isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object'); |
50 | |
51 | $admin->insert('Employee', { name => 'Matt' }); |
52 | my $employees = $schema->resultset('Employee'); |
53 | is ($employees->count(), 1, "insert okay" ); |
54 | |
55 | my $employee = $employees->find(1); |
56 | is($employee->name(), 'Matt', "insert valid" ); |
57 | |
58 | $admin->update('Employee', {name => 'Trout'}, {name => 'Matt'}); |
59 | |
60 | $employee = $employees->find(1); |
61 | is($employee->name(), 'Trout', "update Matt to Trout" ); |
62 | |
63 | $admin->insert('Employee', {name =>'Aran'}); |
64 | |
65 | my $expected_data = [ |
66 | [$employee->result_source->columns() ], |
67 | [1,1,undef,undef,undef,'Trout'], |
68 | [2,2,undef,undef,undef,'Aran'] |
69 | ]; |
70 | my $data; |
71 | lives_ok { $data = $admin->select('Employee')} 'can retrive data from database'; |
72 | cmp_deeply($data, $expected_data, 'DB matches whats expected'); |
73 | |
74 | $admin->delete('Employee', {name=>'Trout'}); |
75 | my $del_rs = $employees->search({name => 'Trout'}); |
76 | is($del_rs->count(), 0, "delete Trout" ); |
77 | is ($employees->count(), 1, "left Aran" ); |
a1696195 |
78 | } |
79 | |
a1696195 |
80 | done_testing; |