Merge 'trunk' into 'DBIx-Class-current'
[dbsrgits/DBIx-Class.git] / t / 89dbicadmin.t
1 # vim: filetype=perl
2 use strict;
3 use warnings;  
4
5 use Test::More;
6 use lib qw(t/lib);
7 use DBICTest;
8
9 my $schema = DBICTest->init_schema();
10
11 eval 'require JSON';
12 plan skip_all => 'Install JSON to run this test' if ($@);
13
14 eval 'require Text::CSV_XS';
15 if ($@) {
16     eval 'require Text::CSV_PP';
17     plan skip_all => 'Install Text::CSV_XS or Text::CSV_PP to run this test' if ($@);
18 }
19
20 plan tests => 5;
21
22 # double quotes round the arguments and single-quote within to make sure the
23 # tests run on windows as well
24
25 my $employees = $schema->resultset('Employee');
26 my $cmd = qq|$^X script/dbicadmin --schema=DBICTest::Schema --class=Employee --tlibs --connect="['dbi:SQLite:dbname=t/var/DBIxClass.db','','',{AutoCommit:1}]" --force --tlibs|;
27
28 `$cmd --op=insert --set="{name:'Matt'}"`;
29 ok( ($employees->count()==1), 'insert count' );
30
31 my $employee = $employees->find(1);
32 ok( ($employee->name() eq 'Matt'), 'insert valid' );
33
34 `$cmd --op=update --set="{name:'Trout'}"`;
35 $employee = $employees->find(1);
36 ok( ($employee->name() eq 'Trout'), 'update' );
37
38 `$cmd --op=insert --set="{name:'Aran'}"`;
39 my $data = `$cmd --op=select --attrs="{order_by:'name'}"`;
40 ok( ($data=~/Aran.*Trout/s), 'select with attrs' );
41
42 `$cmd --op=delete --where="{name:'Trout'}"`;
43 ok( ($employees->count()==1), 'delete' );
44