From a2d98c93c5bdc0da479a3f4724044cccf4ebb70d Mon Sep 17 00:00:00 2001 From: Karol Date: Wed, 4 Dec 2024 20:05:46 +0100 Subject: [PATCH] fix exercise#duplicate when xml_id_path is set --- app/controllers/exercises_controller.rb | 2 +- spec/controllers/exercises_controller_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index be19c1ebf..10078e882 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -56,7 +56,7 @@ def batch_update end def clone - exercise = @exercise.duplicate(public: false, token: nil, user: current_user) + exercise = @exercise.duplicate(public: false, token: nil, user: current_user, uuid: nil) exercise.send(:generate_token) if exercise.save redirect_to(exercise_path(exercise), notice: t('shared.object_cloned', model: Exercise.model_name.human)) diff --git a/spec/controllers/exercises_controller_spec.rb b/spec/controllers/exercises_controller_spec.rb index af82c3717..af2eaa9c9 100644 --- a/spec/controllers/exercises_controller_spec.rb +++ b/spec/controllers/exercises_controller_spec.rb @@ -49,6 +49,15 @@ expect_redirect(Exercise.last) end + context 'when exercise has uuid' do + let(:exercise) { create(:dummy, uuid: SecureRandom.hex) } + + it 'clones the exercise' do + expect_any_instance_of(Exercise).to receive(:duplicate).with(hash_including(public: false, user:)).and_call_original + expect { perform_request.call }.to change(Exercise, :count).by(1) + end + end + context 'when saving fails' do before do allow_any_instance_of(Exercise).to receive(:save).and_return(false)