From 6945a916930e186f1f2c34c30f4ccba12c7f8cd2 Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Tue, 14 Jan 2025 12:57:20 +0000 Subject: [PATCH] Fix completion bug --- app/commands/bootcamp/solution/complete.rb | 6 +++++- app/commands/bootcamp/user_project/create.rb | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/commands/bootcamp/solution/complete.rb b/app/commands/bootcamp/solution/complete.rb index 7560ab12c3..5986048150 100644 --- a/app/commands/bootcamp/solution/complete.rb +++ b/app/commands/bootcamp/solution/complete.rb @@ -17,7 +17,11 @@ def schedule_deferred_jobs! Bootcamp::UpdateUserLevel.defer(user) end - def user_project = Bootcamp::UserProject.for!(user, project) + def user_project + Bootcamp::UserProject.for!(user, project) + rescue ActiveRecord::RecordNotFound + Bootcamp::UserProject::Create.(user, project) + end delegate :user, :project, to: :solution end diff --git a/app/commands/bootcamp/user_project/create.rb b/app/commands/bootcamp/user_project/create.rb index 87704db48e..df6a5d6107 100644 --- a/app/commands/bootcamp/user_project/create.rb +++ b/app/commands/bootcamp/user_project/create.rb @@ -4,12 +4,12 @@ class Bootcamp::UserProject::Create initialize_with :user, :project def call - find_or_create.tap do |up| + create_or_find.tap do |up| Bootcamp::UserProject::UpdateStatus.(up) end end - def find_or_create + def create_or_find Bootcamp::UserProject.create!(user:, project:) rescue StandardError Bootcamp::UserProject.find_by!(user:, project:)