From e9ce372987d64b82bcbd2217b54594bc63f859f7 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Wed, 1 Sep 2021 13:54:16 +0200 Subject: [PATCH] Don't create site updates for wip exercises --- app/commands/concept_exercise/create.rb | 10 ++++++---- app/commands/practice_exercise/create.rb | 10 ++++++---- test/commands/concept_exercise/create_test.rb | 10 ++++++++++ test/commands/practice_exercise/create_test.rb | 10 ++++++++++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/app/commands/concept_exercise/create.rb b/app/commands/concept_exercise/create.rb index ea359ec7c6..155d8da614 100644 --- a/app/commands/concept_exercise/create.rb +++ b/app/commands/concept_exercise/create.rb @@ -10,10 +10,12 @@ def call track: track, **attributes ).tap do |exercise| - SiteUpdates::NewExerciseUpdate.create!( - exercise: exercise, - track: track - ) + unless exercise.wip? + SiteUpdates::NewExerciseUpdate.create!( + exercise: exercise, + track: track + ) + end end rescue ActiveRecord::RecordNotUnique ConceptExercise.find_by!(uuid: uuid, track: track) diff --git a/app/commands/practice_exercise/create.rb b/app/commands/practice_exercise/create.rb index 73fdc92605..fb236340e9 100644 --- a/app/commands/practice_exercise/create.rb +++ b/app/commands/practice_exercise/create.rb @@ -10,10 +10,12 @@ def call track: track, **attributes ).tap do |exercise| - SiteUpdates::NewExerciseUpdate.create!( - exercise: exercise, - track: track - ) + unless exercise.wip? + SiteUpdates::NewExerciseUpdate.create!( + exercise: exercise, + track: track + ) + end end rescue ActiveRecord::RecordNotUnique PracticeExercise.find_by!(uuid: uuid, track: track) diff --git a/test/commands/concept_exercise/create_test.rb b/test/commands/concept_exercise/create_test.rb index abbba5c141..a8ae5edc22 100644 --- a/test/commands/concept_exercise/create_test.rb +++ b/test/commands/concept_exercise/create_test.rb @@ -77,4 +77,14 @@ class ConceptExercise::CreateTest < ActiveSupport::TestCase assert_equal exercise, update.exercise assert_equal track, update.track end + + test "does not create site_update for wip exercise" do + ConceptExercise::Create.( + SecureRandom.uuid, + create(:track), + build(:concept_exercise).attributes.symbolize_keys.merge(status: :wip) + ) + + assert_equal 0, SiteUpdate.count + end end diff --git a/test/commands/practice_exercise/create_test.rb b/test/commands/practice_exercise/create_test.rb index 1f5195525b..dd5edabdd3 100644 --- a/test/commands/practice_exercise/create_test.rb +++ b/test/commands/practice_exercise/create_test.rb @@ -72,4 +72,14 @@ class PracticeExercise::CreateTest < ActiveSupport::TestCase assert_equal exercise, update.exercise assert_equal track, update.track end + + test "does not create site_update for wip exercise" do + PracticeExercise::Create.( + SecureRandom.uuid, + create(:track), + build(:practice_exercise).attributes.symbolize_keys.merge(status: :wip) + ) + + assert_equal 0, SiteUpdate.count + end end