From 0236d3a37da94e06e9e6208f50f6c0b9388feb7c Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 May 2019 13:31:57 +0100 Subject: Prevent creation of two templates with same title. --- t/app/controller/admin/templates.t | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 't/app/controller/admin') diff --git a/t/app/controller/admin/templates.t b/t/app/controller/admin/templates.t index 0d4430cad..6944f4b04 100644 --- a/t/app/controller/admin/templates.t +++ b/t/app/controller/admin/templates.t @@ -66,6 +66,30 @@ subtest "response templates can be added" => sub { is $oxfordshire->response_templates->count, 1, "Response template was added"; }; +subtest "but not another with the same title" => sub { + my $fields = { + title => "Report acknowledgement", + text => "Another report acknowledgement.", + auto_response => undef, + "contacts[".$oxfordshirecontact->id."]" => 1, + }; + my $list_url = "/admin/templates/" . $oxfordshire->id; + $mech->get_ok( "$list_url/new" ); + $mech->submit_form_ok( { with_fields => $fields } ); + is $mech->uri->path, "$list_url/new", 'not redirected'; + $mech->content_contains( 'Please correct the errors below' ); + $mech->content_contains( 'There is already a template with that title.' ); + + my @ts = $oxfordshire->response_templates->all; + is @ts, 1, "No new response template was added"; + + my $url = "$list_url/" . $ts[0]->id; + $mech->get_ok($url); + $mech->submit_form_ok( { with_fields => $fields } ); + is $mech->uri->path, $list_url, 'redirected'; + is $oxfordshire->response_templates->count, 1, "No new response template was added"; +}; + subtest "response templates are included on page" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'oxfordshire' ], -- cgit v1.2.3