-
-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update site updates when exercises change and add wip guard #2009
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module SiteUpdates | ||
class ProcessNewExerciseUpdate | ||
include Mandate | ||
|
||
initialize_with :exercise | ||
|
||
def call | ||
if exercise.wip? | ||
destroy! | ||
else | ||
begin | ||
create! | ||
rescue ActiveRecord::RecordNotUnique | ||
update! | ||
end | ||
end | ||
end | ||
|
||
def destroy! | ||
SiteUpdates::NewExerciseUpdate.where( | ||
exercise: exercise, | ||
track: exercise.track | ||
).destroy_all | ||
end | ||
|
||
def create! | ||
SiteUpdates::NewExerciseUpdate.create!( | ||
exercise: exercise, | ||
track: exercise.track | ||
) | ||
end | ||
|
||
def update! | ||
SiteUpdates::NewExerciseUpdate.find_by!( | ||
exercise: exercise, | ||
track: exercise.track | ||
).regenerate_rendering_data! | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddIndexToUniquenessKeyOnSiteUpdates < ActiveRecord::Migration[6.1] | ||
def change | ||
add_index :site_updates, :uniqueness_key, unique: true | ||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||
require "test_helper" | ||||||
|
||||||
class ConceptExercise::CreateTest < ActiveSupport::TestCase | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I reckon loads of flakey tests happen because of this bug. |
||||||
test "no-op if wip and not present" do | ||||||
exercise = create :concept_exercise, status: :wip | ||||||
|
||||||
SiteUpdates::ProcessNewExerciseUpdate.(exercise) | ||||||
|
||||||
refute SiteUpdate.exists? | ||||||
end | ||||||
|
||||||
test "deletes if wip and was present" do | ||||||
exercise = create :concept_exercise, status: :wip | ||||||
|
||||||
create :new_exercise_site_update, exercise: exercise | ||||||
|
||||||
SiteUpdates::ProcessNewExerciseUpdate.(exercise) | ||||||
|
||||||
refute SiteUpdate.exists? | ||||||
end | ||||||
|
||||||
test "creates if not wip" do | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could consider adding explicit tests for |
||||||
exercise = create :concept_exercise | ||||||
|
||||||
SiteUpdates::ProcessNewExerciseUpdate.(exercise) | ||||||
|
||||||
assert SiteUpdate.where(exercise: exercise).exists? | ||||||
end | ||||||
|
||||||
test "updates if not wip and exists" do | ||||||
exercise = create :concept_exercise | ||||||
update = create :new_exercise_site_update, exercise: exercise | ||||||
update.update_column(:rendering_data_cache, { "foo" => "bar" }) | ||||||
assert_equal({ "foo" => "bar" }, update.rendering_data_cache) # Sanity | ||||||
|
||||||
SiteUpdates::ProcessNewExerciseUpdate.(exercise) | ||||||
|
||||||
assert_equal JSON.parse(update.cacheable_rendering_data.to_json), update.reload.rendering_data_cache | ||||||
end | ||||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens in the unlikely case that a new exercise is created with the
deprecated
status?