diff options
author | Dave Arter <davea@mysociety.org> | 2020-01-06 11:01:59 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2020-01-06 11:03:13 +0000 |
commit | 64944ca56e310f256536b94065542141f1341a8b (patch) | |
tree | fffd07196d27c5f06ecd9c649874b4de087c27db /t/app/controller/admin | |
parent | 9d876bf9829ec3b00240707ff4ba04b1a1265317 (diff) |
Clear any categories from user when unsetting from_body
This was most likely the cause of #2815.
Diffstat (limited to 't/app/controller/admin')
-rw-r--r-- | t/app/controller/admin/users.t | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/t/app/controller/admin/users.t b/t/app/controller/admin/users.t index e732f0edd..2e3ad9e5a 100644 --- a/t/app/controller/admin/users.t +++ b/t/app/controller/admin/users.t @@ -162,6 +162,30 @@ subtest 'user_edit redirects appropriately' => sub { }; }; +subtest 'user categories are cleared when from_body is unset' => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'oxfordshire' ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $mech->log_in_ok( $user3->email ); + + my $cat1 = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Traffic lights', email => 'lights@example.com' ); + my $cat2 = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Potholes', email => 'potholes@example.com' ); + $user2->set_extra_metadata('categories', [ $cat1->id, $cat2->id ]); + $user2->from_body($oxfordshire->id); + $user2->update; + + $mech->get_ok('/admin/users/' . $user2->id); + $mech->submit_form_ok( { with_fields => { + body => undef + } } ); + + $user2->discard_changes; + is $user2->from_body, undef, "from_body unset"; + is $user2->get_extra_metadata('categories'), undef, "categories unset"; + }; +}; + $mech->log_in_ok( $superuser->email ); for my $test ( |