From e9a5d60713192062d6b1055c9a77d3d1c93dd561 Mon Sep 17 00:00:00 2001 From: Cynthia Anyaeriuba Date: Tue, 16 Jan 2024 17:54:07 +0000 Subject: [PATCH] Fix exception case when a user tries to claim 2i whilst an edition is scheduled for publishing --- app/controllers/editions_controller.rb | 2 +- test/functional/editions_controller_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/editions_controller.rb b/app/controllers/editions_controller.rb index 72321bef3..4b29844c8 100644 --- a/app/controllers/editions_controller.rb +++ b/app/controllers/editions_controller.rb @@ -176,7 +176,7 @@ def review end resource.reviewer = params[:edition][:reviewer] - if resource.save! + if resource.save flash[:success] = "You are the reviewer of this #{description(resource).downcase}." else flash[:danger] = "Something went wrong when attempting to claim 2i." diff --git a/test/functional/editions_controller_test.rb b/test/functional/editions_controller_test.rb index db0143092..2ef9cc044 100644 --- a/test/functional/editions_controller_test.rb +++ b/test/functional/editions_controller_test.rb @@ -877,6 +877,20 @@ class EditionsControllerTest < ActionController::TestCase assert_equal bob.name, @guide.reviewer end + should "not be able to update the reviewer when edition is scheduled for publishing" do + bob = FactoryBot.create(:user, name: "bob") + edition = FactoryBot.create(:edition, :scheduled_for_publishing) + + put :review, + params: { + id: edition.id, + edition: { reviewer: bob.name }, + } + + assert_response(302) + assert_equal "Something went wrong when attempting to claim 2i.", flash[:danger] + end + context "Welsh editors" do setup do @welsh_guide = FactoryBot.create(:guide_edition, :welsh, :in_review)