Skip to content

Commit 95537d2

Browse files
committed
fix importing assignments with no name
test plan: * import a course package containing a nameless assignment, and choose to remove dates from the imported course. You can find such a package here: https://hilary.instructure.com/courses/332573/content_migrations (download the .imscc linked to on that page) Note that you can't easily create a new nameless assignment, because CNVS-12938 adds a validator to prevent this (the linked course package predates that fix) * the nameless assignment should have a generic name ("untitled assignment") * go to the syllabus page in the new course * there should be no due dates there fixes CNVS-16624 Change-Id: Ib51773024ccaac2241619cd8b1a5a8b54b99f3ce Reviewed-on: https://gerrit.instructure.com/43791 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: James Williams <jamesw@instructure.com> QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com>
1 parent c434405 commit 95537d2

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

app/models/importers/assignment_importer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def self.import_from_migration(hash, context, migration=nil, item=nil, quiz=nil)
3333
item ||= Assignment.where(context_type: context.class.to_s, context_id: context, migration_id: hash[:migration_id]).first if hash[:migration_id]
3434
item ||= context.assignments.new #new(:context => context)
3535
item.title = hash[:title]
36+
item.title = I18n.t('untitled assignment') if item.title.blank?
3637
item.migration_id = hash[:migration_id]
3738
item.workflow_state = (hash[:workflow_state] || 'published') if item.new_record? || item.deleted?
3839
if hash[:instructions_in_html] == false

app/models/importers/course_content_importer.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,23 @@ def self.import_content(course, data, params, migration)
166166
event.lock_at = shift_date(event.lock_at, shift_options)
167167
event.unlock_at = shift_date(event.unlock_at, shift_options)
168168
event.peer_reviews_due_at = shift_date(event.peer_reviews_due_at, shift_options)
169-
event.save_without_broadcasting!
169+
event.save_without_broadcasting
170170
end
171171

172172
migration.imported_migration_items_by_class(Announcement).each do |event|
173173
event.delayed_post_at = shift_date(event.delayed_post_at, shift_options)
174-
event.save_without_broadcasting!
174+
event.save_without_broadcasting
175175
end
176176

177177
migration.imported_migration_items_by_class(DiscussionTopic).each do |event|
178178
event.delayed_post_at = shift_date(event.delayed_post_at, shift_options)
179-
event.save_without_broadcasting!
179+
event.save_without_broadcasting
180180
end
181181

182182
migration.imported_migration_items_by_class(CalendarEvent).each do |event|
183183
event.start_at = shift_date(event.start_at, shift_options)
184184
event.end_at = shift_date(event.end_at, shift_options)
185-
event.save_without_broadcasting!
185+
event.save_without_broadcasting
186186
end
187187

188188
migration.imported_migration_items_by_class(Quizzes::Quiz).each do |event|
@@ -192,14 +192,14 @@ def self.import_content(course, data, params, migration)
192192
event.show_correct_answers_at = shift_date(event.show_correct_answers_at, shift_options)
193193
event.hide_correct_answers_at = shift_date(event.hide_correct_answers_at, shift_options)
194194
event.saved_by = :migration
195-
event.save!
195+
event.save
196196
end
197197

198198
migration.imported_migration_items_by_class(ContextModule).each do |event|
199199
event.unlock_at = shift_date(event.unlock_at, shift_options)
200200
event.start_at = shift_date(event.start_at, shift_options)
201201
event.end_at = shift_date(event.end_at, shift_options)
202-
event.save!
202+
event.save
203203
end
204204

205205
course.set_course_dates_if_blank(shift_options)

spec/models/importers/assignment_importer_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,31 @@
6262
a = Assignment.where(migration_id: assignment_hash[:migration_id]).first
6363
expect(a.points_possible).to eq rubric.points_possible
6464
end
65+
66+
it "should infer the default name when importing a nameless assignment" do
67+
course_model
68+
nameless_assignment_hash = {
69+
"migration_id" => "ib4834d160d180e2e91572e8b9e3b1bc6",
70+
"assignment_group_migration_id" => "i2bc4b8ea8fac88f1899e5e95d76f3004",
71+
"grading_standard_migration_id" => nil,
72+
"rubric_migration_id" => nil,
73+
"rubric_id" => nil,
74+
"quiz_migration_id" => nil,
75+
"workflow_state" => "published",
76+
"title" => "",
77+
"grading_type" => "points",
78+
"submission_types" => "none",
79+
"peer_reviews" => false,
80+
"automatic_peer_reviews" => false,
81+
"muted" => false,
82+
"due_at" => 1401947999000,
83+
"peer_reviews_due_at" => 1401947999000,
84+
"position" => 6,
85+
"peer_review_count" => 0
86+
}
87+
Importers::AssignmentImporter.import_from_migration(nameless_assignment_hash, @course)
88+
assignment = @course.assignments.where(migration_id: 'ib4834d160d180e2e91572e8b9e3b1bc6').first
89+
expect(assignment.title).to eq 'untitled assignment'
90+
end
6591

6692
end

0 commit comments

Comments
 (0)