Commit | Line | Data |
a1696195 |
1 | # |
2 | #=============================================================================== |
3 | # |
4 | # FILE: 03sql.t |
5 | # |
6 | # DESCRIPTION: test sql manipulation funtions |
7 | # |
8 | # FILES: --- |
9 | # BUGS: --- |
10 | # NOTES: --- |
11 | # AUTHOR: Gordon Irving (), <Gordon.irving@sophos.com> |
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 | |
25 | use Path::Class; |
26 | use FindBin qw($Bin); |
27 | |
28 | use lib dir($Bin,'..', '..','lib')->stringify; |
29 | use lib dir($Bin,'..', 'lib')->stringify; |
30 | |
31 | use ok 'DBIx::Class::Admin'; |
32 | |
33 | use DBICTest; |
34 | |
35 | { # test data maniplulation functions |
36 | |
37 | # create a DBICTest so we can steal its connect info |
38 | my $schema = DBICTest->init_schema( |
39 | # no_deploy=>1, |
40 | # no_populate=>1, |
41 | sqlite_use_file => 1, |
42 | ); |
43 | |
44 | |
45 | my $admin = DBIx::Class::Admin->new( |
46 | schema_class=> "DBICTest::Schema", |
47 | connect_info => $schema->storage->connect_info(), |
48 | quiet => 1, |
49 | _confirm=>1, |
50 | ); |
51 | isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object'); |
52 | |
53 | $admin->insert_data('Employee', { name => 'Matt' }); |
54 | my $employees = $schema->resultset('Employee'); |
55 | is ($employees->count(), 1, "insert okay" ); |
56 | |
57 | my $employee = $employees->find(1); |
58 | is($employee->name(), 'Matt', "insert valid" ); |
59 | |
60 | $admin->update_data('Employee', {name => 'Trout'}, {name => 'Matt'}); |
61 | |
62 | $employee = $employees->find(1); |
63 | is($employee->name(), 'Trout', "update Matt to Trout" ); |
64 | |
65 | $admin->insert_data('Employee', {name =>'Aran'}); |
66 | |
67 | my $expected_data = [ |
68 | [$employee->result_source->columns() ], |
69 | [1,1,undef,undef,undef,'Trout'], |
70 | [2,2,undef,undef,undef,'Aran'] |
71 | ]; |
72 | my $data; |
73 | lives_ok { $data = $admin->select_data('Employee')} 'can retrive data from database'; |
74 | cmp_deeply($data, $expected_data, 'DB matches whats expected'); |
75 | |
76 | $admin->delete_data('Employee', {name=>'Trout'}); |
77 | my $del_rs = $employees->search({name => 'Trout'}); |
78 | is($del_rs->count(), 0, "delete Trout" ); |
79 | is ($employees->count(), 1, "left Aran" ); |
80 | } |
81 | |
82 | |
83 | |
84 | done_testing; |