Merge 'trunk' into 'replication_dedux'
[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::Any';
12 plan skip_all => 'Install JSON::Any 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 # the script supports double quotes round the arguments and single-quote within
23 # to make sure it runs on windows as well, but only if JSON::Any picks the right module
24
25
26
27 my $employees = $schema->resultset('Employee');
28 my @cmd = ($^X, qw|script/dbicadmin --quiet --schema=DBICTest::Schema --class=Employee --tlibs|, q|--connect=["dbi:SQLite:dbname=t/var/DBIxClass.db","","",{"AutoCommit":1}]|, qw|--force --tlibs|);
29
30 system(@cmd, qw|--op=insert --set={"name":"Matt"}|);
31 ok( ($employees->count()==1), 'insert count' );
32
33 my $employee = $employees->find(1);
34 ok( ($employee->name() eq 'Matt'), 'insert valid' );
35
36 system(@cmd, qw|--op=update --set={"name":"Trout"}|);
37 $employee = $employees->find(1);
38 ok( ($employee->name() eq 'Trout'), 'update' );
39
40 system(@cmd, qw|--op=insert --set={"name":"Aran"}|);
41
42 open(my $fh, "-|", @cmd, qw|--op=select --attrs={"order_by":"name"}|) or die $!;
43 my $data = do { local $/; <$fh> };
44 close($fh);
45 ok( ($data=~/Aran.*Trout/s), 'select with attrs' );
46
47 system(@cmd, qw|--op=delete --where={"name":"Trout"}|);
48 ok( ($employees->count()==1), 'delete' );
49