add TODO on constraint check
[dbsrgits/DBIx-Class.git] / t / 89dbicadmin.t
CommitLineData
d8d6276a 1# vim: filetype=perl
70350518 2use strict;
3use warnings;
d8d6276a 4
70350518 5use Test::More;
6use lib qw(t/lib);
7use DBICTest;
d8d6276a 8
a47e1233 9my $schema = DBICTest->init_schema();
d8d6276a 10
e4c66bc8 11eval 'require JSON::Any';
12plan skip_all => 'Install JSON::Any to run this test' if ($@);
d8d6276a 13
70350518 14eval 'require Text::CSV_XS';
15if ($@) {
16 eval 'require Text::CSV_PP';
17 plan skip_all => 'Install Text::CSV_XS or Text::CSV_PP to run this test' if ($@);
18}
d8d6276a 19
70350518 20plan tests => 5;
d8d6276a 21
1405206e 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
0ffbc9ec 26
70350518 27my $employees = $schema->resultset('Employee');
1405206e 28my @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|);
d8d6276a 29
1405206e 30system(@cmd, qw|--op=insert --set={"name":"Matt"}|);
70350518 31ok( ($employees->count()==1), 'insert count' );
d8d6276a 32
70350518 33my $employee = $employees->find(1);
34ok( ($employee->name() eq 'Matt'), 'insert valid' );
d8d6276a 35
1405206e 36system(@cmd, qw|--op=update --set={"name":"Trout"}|);
70350518 37$employee = $employees->find(1);
38ok( ($employee->name() eq 'Trout'), 'update' );
d8d6276a 39
1405206e 40system(@cmd, qw|--op=insert --set={"name":"Aran"}|);
41
42open(my $fh, "-|", @cmd, qw|--op=select --attrs={"order_by":"name"}|) or die $!;
43my $data = do { local $/; <$fh> };
44close($fh);
70350518 45ok( ($data=~/Aran.*Trout/s), 'select with attrs' );
46
1405206e 47system(@cmd, qw|--op=delete --where={"name":"Trout"}|);
70350518 48ok( ($employees->count()==1), 'delete' );
d8d6276a 49