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: --- |
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 | |
a1696195 |
30 | use Path::Class; |
31 | use FindBin qw($Bin); |
32 | |
33 | use lib dir($Bin,'..', '..','lib')->stringify; |
34 | use lib dir($Bin,'..', 'lib')->stringify; |
35 | |
36 | use ok 'DBIx::Class::Admin'; |
37 | |
38 | use DBICTest; |
39 | |
40 | { # test data maniplulation functions |
41 | |
42 | # create a DBICTest so we can steal its connect info |
43 | my $schema = DBICTest->init_schema( |
44 | # no_deploy=>1, |
45 | # no_populate=>1, |
46 | sqlite_use_file => 1, |
47 | ); |
48 | |
49 | |
50 | my $admin = DBIx::Class::Admin->new( |
51 | schema_class=> "DBICTest::Schema", |
52 | connect_info => $schema->storage->connect_info(), |
53 | quiet => 1, |
54 | _confirm=>1, |
55 | ); |
56 | isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object'); |
57 | |
6bceaca3 |
58 | $admin->insert('Employee', { name => 'Matt' }); |
a1696195 |
59 | my $employees = $schema->resultset('Employee'); |
60 | is ($employees->count(), 1, "insert okay" ); |
61 | |
62 | my $employee = $employees->find(1); |
63 | is($employee->name(), 'Matt', "insert valid" ); |
64 | |
6bceaca3 |
65 | $admin->update('Employee', {name => 'Trout'}, {name => 'Matt'}); |
a1696195 |
66 | |
67 | $employee = $employees->find(1); |
68 | is($employee->name(), 'Trout', "update Matt to Trout" ); |
69 | |
6bceaca3 |
70 | $admin->insert('Employee', {name =>'Aran'}); |
a1696195 |
71 | |
72 | my $expected_data = [ |
73 | [$employee->result_source->columns() ], |
74 | [1,1,undef,undef,undef,'Trout'], |
75 | [2,2,undef,undef,undef,'Aran'] |
76 | ]; |
77 | my $data; |
6bceaca3 |
78 | lives_ok { $data = $admin->select('Employee')} 'can retrive data from database'; |
a1696195 |
79 | cmp_deeply($data, $expected_data, 'DB matches whats expected'); |
80 | |
6bceaca3 |
81 | $admin->delete('Employee', {name=>'Trout'}); |
a1696195 |
82 | my $del_rs = $employees->search({name => 'Trout'}); |
83 | is($del_rs->count(), 0, "delete Trout" ); |
84 | is ($employees->count(), 1, "left Aran" ); |
85 | } |
86 | |
87 | |
88 | |
89 | done_testing; |