From 431d624c0db37315e27125ccbadfa48d66ec5135 Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Wed, 8 Sep 2021 12:17:24 +0100 Subject: [PATCH] Fix creation issue with Exercises (#1829) * Fix creation issue with Exercises * Force syncing for new concepts/concept exercises/practice exercises Co-authored-by: Erik Schierboom --- app/commands/git/sync_track.rb | 6 ++-- test/commands/git/sync_track_test.rb | 54 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/app/commands/git/sync_track.rb b/app/commands/git/sync_track.rb index a2167fb23d..ee68c39825 100644 --- a/app/commands/git/sync_track.rb +++ b/app/commands/git/sync_track.rb @@ -78,7 +78,7 @@ def sync_concepts! blurb: git_concept.blurb, synced_to_git_sha: head_git_track.commit.oid ).tap do |concept| - Git::SyncConcept.(concept, force_sync: force_sync) + Git::SyncConcept.(concept, force_sync: force_sync || concept.id_previously_changed?) end end end @@ -102,7 +102,7 @@ def sync_concept_exercises! prerequisites: exercise_concepts(exercise_config[:prerequisites]), has_test_runner: git_exercise.has_test_runner? ) - Git::SyncConceptExercise.(exercise, force_sync: force_sync) + Git::SyncConceptExercise.(exercise, force_sync: force_sync || exercise.id_previously_changed?) end end @@ -126,7 +126,7 @@ def sync_practice_exercises! practiced_concepts: exercise_concepts(exercise_config[:practices]), has_test_runner: git_exercise.has_test_runner? ) - Git::SyncPracticeExercise.(exercise, force_sync: force_sync) + Git::SyncPracticeExercise.(exercise, force_sync: force_sync || exercise.id_previously_changed?) end end diff --git a/test/commands/git/sync_track_test.rb b/test/commands/git/sync_track_test.rb index 204b4ef92f..5121d12e59 100644 --- a/test/commands/git/sync_track_test.rb +++ b/test/commands/git/sync_track_test.rb @@ -470,4 +470,58 @@ class Git::SyncTrackTest < ActiveSupport::TestCase assert track.course? end + + test "new concept syncs with force_sync even when track is not force synced" do + track = create :track, synced_to_git_sha: "HEAD" + + Git::SyncConcept.expects(:call).with(anything, force_sync: true).at_least_once + + Git::SyncTrack.(track) + end + + test "new concept exercise syncs with force_sync even when track is not force synced" do + track = create :track, synced_to_git_sha: "HEAD" + + Git::SyncConceptExercise.expects(:call).with(anything, force_sync: true).at_least_once + + Git::SyncTrack.(track) + end + + test "new practice exercise syncs with force_sync even when track is not force synced" do + track = create :track, synced_to_git_sha: "HEAD" + + Git::SyncPracticeExercise.expects(:call).with(anything, force_sync: true).at_least_once + + Git::SyncTrack.(track) + end + + test "existing concept does not sync with force_sync" do + track = create :track, synced_to_git_sha: "HEAD" + Git::SyncTrack.(track) + + Git::SyncConcept.expects(:call).with(anything, force_sync: true).never + Git::SyncConcept.expects(:call).with(anything, force_sync: false).at_least_once + + Git::SyncTrack.(track) + end + + test "existing concept exercise does not sync with force_sync" do + track = create :track, synced_to_git_sha: "HEAD" + Git::SyncTrack.(track) + + Git::SyncConceptExercise.expects(:call).with(anything, force_sync: true).never + Git::SyncConceptExercise.expects(:call).with(anything, force_sync: false).at_least_once + + Git::SyncTrack.(track) + end + + test "existing practice exercise does not sync with force_sync" do + track = create :track, synced_to_git_sha: "HEAD" + Git::SyncTrack.(track) + + Git::SyncPracticeExercise.expects(:call).with(anything, force_sync: true).never + Git::SyncPracticeExercise.expects(:call).with(anything, force_sync: false).at_least_once + + Git::SyncTrack.(track) + end end