9 my $schema = DBICTest->init_schema();
11 eval 'require JSON::Any';
12 plan skip_all => 'Install JSON::Any to run this test' if ($@);
14 eval 'require Text::CSV_XS';
16 eval 'require Text::CSV_PP';
17 plan skip_all => 'Install Text::CSV_XS or Text::CSV_PP to run this test' if ($@);
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
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|);
30 system(@cmd, qw|--op=insert --set={"name":"Matt"}|);
31 ok( ($employees->count()==1), 'insert count' );
33 my $employee = $employees->find(1);
34 ok( ($employee->name() eq 'Matt'), 'insert valid' );
36 system(@cmd, qw|--op=update --set={"name":"Trout"}|);
37 $employee = $employees->find(1);
38 ok( ($employee->name() eq 'Trout'), 'update' );
40 system(@cmd, qw|--op=insert --set={"name":"Aran"}|);
42 open(my $fh, "-|", @cmd, qw|--op=select --attrs={"order_by":"name"}|) or die $!;
43 my $data = do { local $/; <$fh> };
45 ok( ($data=~/Aran.*Trout/s), 'select with attrs' );
47 system(@cmd, qw|--op=delete --where={"name":"Trout"}|);
48 ok( ($employees->count()==1), 'delete' );