exit 0 if ! check_recurse($GOAT, $name, @actions);
## Make sure this table exists!
- ## XXXJWT probably check database as well, not just name
- #my @tables = find_goat_by_item($name, @nouns);
- my $table = $GOAT->{by_fullname}{$name} or die qq{Could not find a table named "$name"\n}
- . "Use 'list tables' to see all available.\n";
+ my @tables = find_goat_by_item($name, \@nouns);
+ if (!@tables) {
+ die qq{Didn't find any matching tables\n};
+ }
## If this is an array, then see how many matches we have
- if (ref $table eq 'ARRAY') {
- my $matches = @$table;
- if ($matches > 1) {
- die qq{More than one matching table: please use a schema\n};
- }
- $table = $table->[0];
+ if ($#tables > 0) {
+ die qq{More than one matching table: please use a schema\n};
}
+ my $table = $tables[0];
## Store the id so we work with that alone whenever possible
my $id = $table->{id};
- ## Everything is a name=value setting after this point
+ ## Everything is a name=value setting after this point, except stuff that
+ ## matches /^db=/
## We will ignore and allow noise word "set"
- for my $arg (@actions) {
+ for my $arg (grep { ! /^db=/ } @actions) {
next if $arg =~ /set/i;
next if $arg =~ /\w+=\w+/o;
usage_exit($doc_section);
}
## Change the arguments into a hash
- my $args = process_args(join ' ' => @actions);
+ my $args = process_args(join ' ' => ( grep { ! /^db=/ } @actions));
## Track what changes we made
my %change;
use Data::Dumper;
use lib 't','.';
use DBD::Pg;
-use Test::More tests => 38;
+use Test::More tests => 43;
use vars qw/$t $res $expected $command $dbhX $dbhA $dbhB $SQL/;
$res = $bct->ctl('bucardo list tables -vv public.bucardo_test1');
like ($res, qr/ghost\s+= 0/ , $t);
-### Tests of 'update table' usage
-#$t = q{Update table works}
-#$res = $bct->ctl('bucardo update table public.bucardo_test1 autokick=t');
+## Tests of 'update table' usage
+$t = q{Update table changes a value properly};
+$bct->ctl('bucardo update table public.bucardo_test1 ghost=1');
+$res = $bct->ctl('bucardo list tables -vv public.bucardo_test1');
+like ($res, qr/ghost\s+= 1/, $t);
+
+$t = q{Update table returns correctly when the value doesn't need changing};
+$res = $bct->ctl('bucardo update table public.bucardo_test1 ghost=1');
+like ($res, qr/No change needed for ghost/, $t);
+
+$t = q{Update table doesn't try to set "db=" actions};
+$res = $bct->ctl('bucardo update table public.bucardo_test1 db=A ghost=1');
+unlike ($res, qr/No change needed for db/, $t);
+
+$t = q{Update table correctly filters by db when table exists};
+$res = $bct->ctl('bucardo update table public.bucardo_test1 db=A ghost=1');
+like ($res, qr/No change needed for ghost/, $t);
+$t = q{Update table correctly filters by db when table doesn't exist};
+$res = $bct->ctl('bucardo update table public.bucardo_test1 db=B ghost=1');
+like ($res, qr/Didn't find any matching tables/, $t);
END {
$bct->stop_bucardo($dbhX);