Commit | Line | Data |
d8d6276a |
1 | # vim: filetype=perl |
70350518 |
2 | use strict; |
3 | use warnings; |
d8d6276a |
4 | |
70350518 |
5 | use Test::More; |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
d8d6276a |
8 | |
a47e1233 |
9 | my $schema = DBICTest->init_schema(); |
d8d6276a |
10 | |
e4c66bc8 |
11 | eval 'require JSON::Any'; |
12 | plan skip_all => 'Install JSON::Any to run this test' if ($@); |
d8d6276a |
13 | |
70350518 |
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 | } |
d8d6276a |
19 | |
70350518 |
20 | plan 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 |
27 | my $employees = $schema->resultset('Employee'); |
1405206e |
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|); |
d8d6276a |
29 | |
1405206e |
30 | system(@cmd, qw|--op=insert --set={"name":"Matt"}|); |
70350518 |
31 | ok( ($employees->count()==1), 'insert count' ); |
d8d6276a |
32 | |
70350518 |
33 | my $employee = $employees->find(1); |
34 | ok( ($employee->name() eq 'Matt'), 'insert valid' ); |
d8d6276a |
35 | |
1405206e |
36 | system(@cmd, qw|--op=update --set={"name":"Trout"}|); |
70350518 |
37 | $employee = $employees->find(1); |
38 | ok( ($employee->name() eq 'Trout'), 'update' ); |
d8d6276a |
39 | |
1405206e |
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); |
70350518 |
45 | ok( ($data=~/Aran.*Trout/s), 'select with attrs' ); |
46 | |
1405206e |
47 | system(@cmd, qw|--op=delete --where={"name":"Trout"}|); |
70350518 |
48 | ok( ($employees->count()==1), 'delete' ); |
d8d6276a |
49 | |