Skip to content

Commit

Permalink
Merge pull request #43710 from code-dot-org/remove-blank-objectives
Browse files Browse the repository at this point in the history
Remove blank objectives
  • Loading branch information
davidsbailey committed Nov 19, 2021
2 parents ff388e0 + c0f3e32 commit 7109192
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
3 changes: 2 additions & 1 deletion dashboard/app/models/lesson.rb
Expand Up @@ -713,11 +713,12 @@ def update_objectives(objectives)
return unless objectives

self.objectives = objectives.map do |objective|
next nil unless objective['description'].present?
persisted_objective = objective['id'].blank? ? Objective.new(key: SecureRandom.uuid) : Objective.find(objective['id'])
persisted_objective.description = objective['description']
persisted_objective.save!
persisted_objective
end
end.compact
end

# Used for seeding from JSON. Returns the full set of information needed to
Expand Down
9 changes: 0 additions & 9 deletions dashboard/config/scripts_json/coursef-2021.script_json
Expand Up @@ -10031,15 +10031,6 @@
"objective.key": "68c038c1-990a-4009-ad61-619ba6ea71af"
}
},
{
"key": "7a69d6de-1a75-41da-a511-9cb735e02a5c",
"properties": {
},
"seeding_key": {
"lesson.key": "lesson-2",
"objective.key": "7a69d6de-1a75-41da-a511-9cb735e02a5c"
}
},
{
"key": "7a7f6249-ea7c-40df-a0a6-e4a3f5c61d9f",
"properties": {
Expand Down
19 changes: 19 additions & 0 deletions dashboard/test/controllers/lessons_controller_test.rb
Expand Up @@ -1008,6 +1008,25 @@ class LessonsControllerTest < ActionController::TestCase
assert_equal 'edited description', objective.description
end

test 'objectives with empty description are removed' do
sign_in @levelbuilder
objective_to_keep = create :objective, description: 'to keep', lesson: @lesson
objective_to_remove = create :objective, description: 'to remove', lesson: @lesson
assert_equal 2, @lesson.objectives.count

objectives_data = @lesson.summarize_for_lesson_edit[:objectives]
objectives_data[1][:description] = ''
objectives_data.push(id: nil, description: '')

new_update_params = @update_params.merge({objectives: [objective_to_keep.summarize_for_edit].to_json})
put :update, params: new_update_params
@lesson.reload

assert_equal 1, @lesson.objectives.count
assert_nil Objective.find_by_id(objective_to_remove.id)
assert_not_nil objective_to_keep.reload
end

test 'add script level via lesson update' do
sign_in @levelbuilder
activity = create :lesson_activity, lesson: @lesson
Expand Down

0 comments on commit 7109192

Please sign in to comment.