TT#8773 Remove readonly fields from resource in the API::validate_form to fix PATCH

Change-Id: I475553f7461aa5e67b35d5111883adedecf33642
(cherry picked from commit ae1a4f2ff7)
changes/53/10753/1
Irina Peshinskaya 9 years ago
parent 354e2ad621
commit 3d2d4bfa1f

@ -127,8 +127,19 @@ sub validate_form {
}
}
# remove unknown keys
my %fields = map { $_->name => $_ } $form->fields;
# remove unknown keys and prepare resource
my %fields;
foreach($form->fields){
if($_->readonly){
#Prepare resource for the PATCH considering readonly fields.
#PATCH is supposed to take full item content and so will get readonly fields into resource too. And apply patch.
#It leads to the situation when we may try to change some not existing fields in the DB
#All readonly fields are considered as representation only and should never be applied.
delete $resource->{$_->name};
next;
}
$fields{$_->name} = $_;
}
$self->validate_fields($c, $resource, \%fields, $run);
if($run) {

@ -56,6 +56,13 @@ SKIP:{
#todo: create_timestamp - strange, it is different to the value of the time zone
$test_machine->check_get2put({ignore_fields => [qw/modify_timestamp create_timestamp/]});
my $mod_customer;
($res,$mod_customer) = $test_machine->check_patch_correct( [ { op => 'replace', path => '/subscriber_email_template_id', value => undef } ] );
is($mod_customer->{subscriber_email_template_id}, undef, "check patched subscriber_email_template_id:".($mod_customer->{subscriber_email_template_id} // 'undef'));
($res,$mod_customer) = $test_machine->check_patch_correct( [ { op => 'replace', path => '/subscriber_email_template_id', value => $test_machine->DATA_ITEM->{subscriber_email_template_id} } ] );
is($mod_customer->{subscriber_email_template_id}, $test_machine->DATA_ITEM->{subscriber_email_template_id}, "check patched subscriber_email_template_id:".$mod_customer->{subscriber_email_template_id});
$test_machine->check_bundle();
}

Loading…
Cancel
Save