Skip to content

Commit

Permalink
fix exercise#duplicate when xml_id_path is set
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoehn committed Jan 7, 2025
1 parent ad90382 commit a2d98c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/exercises_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 9 additions & 0 deletions spec/controllers/exercises_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a2d98c9

Please sign in to comment.