Skip to content
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

Remove blank objectives #43710

Merged
merged 2 commits into from Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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