import course grading scheme when selecting course settings

test plan:
 - set a grading scheme for a course in course settings
 - export the course to a common cartridge
 - import into a new course, selecting course settings
   (not importing everything)
 - the new course should have a copy of the grading standard
   which should be set in course settings

fixes CNVS-20471

Change-Id: I70748e1cb16930179c3c2e40e8ae280920dd18da
Reviewed-on: https://gerrit.instructure.com/54490
Tested-by: Jenkins
Reviewed-by: James Williams  <jamesw@instructure.com>
QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com>
Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
Jeremy Stanley 2015-05-18 11:35:18 -06:00
parent 72415e8460
commit 46c83d39a5
4 changed files with 32 additions and 1 deletions

View File

@ -387,7 +387,7 @@ class ContentMigration < ActiveRecord::Base
def import_everything?
return true unless migration_settings[:migration_ids_to_import] && migration_settings[:migration_ids_to_import][:copy] && migration_settings[:migration_ids_to_import][:copy].length > 0
return true if is_set?(to_import(:everything))
return true if copy_options && copy_options[:everything]
return true if copy_options && is_set?(copy_options[:everything])
false
end

View File

@ -84,6 +84,7 @@ module Importers
if !migration.for_course_copy?
Importers::ContextModuleImporter.select_linked_module_items(data, migration)
Importers::GradingStandardImporter.select_course_grading_standard(data, migration)
# These only need to be processed once
Attachment.skip_media_object_creation do
self.process_migration_files(course, data, migration); migration.update_import_progress(18)

View File

@ -3,6 +3,13 @@ module Importers
self.item_class = GradingStandard
def self.select_course_grading_standard(data, migration)
return unless migration.import_object?('course_settings', '')
return unless data[:course] && data[:course][:grading_standard_enabled]
gs_id = data[:course][:grading_standard_identifier_ref]
migration.import_object!('grading_standards', gs_id) if gs_id
end
def self.process_migration(data, migration)
standards = data['grading_standards'] || []
standards.each do |standard|

View File

@ -384,6 +384,29 @@ describe ContentMigration do
expect(@copy_to.grading_standard.title).to eql gs.title
end
it "should not copy grading standards if nothing is selected (export/import)" do
gs = make_grading_standard(@copy_from, title: 'What')
@copy_from.update_attribute(:grading_standard, gs)
@cm.copy_options = { 'everything' => '0' }
@cm.migration_ids_to_import = { 'copy' => { 'everything' => '0' } }
@cm.save!
run_export_and_import
expect(@cm.warnings).to be_empty
expect(@copy_to.grading_standards).to be_empty
end
it "should copy the course's grading standard (once) if course_settings are selected (export/import)" do
gs = make_grading_standard(@copy_from, title: 'What')
@copy_from.update_attribute(:grading_standard, gs)
@cm.copy_options = { 'everything' => '0', 'all_course_settings' => '1' }
@cm.migration_ids_to_import = { 'copy' => { 'all_course_settings' => '1' } }
@cm.save!
run_export_and_import
expect(@cm.warnings).to be_empty
expect(@copy_to.grading_standards.count).to eql 1 # no dupes
expect(@copy_to.grading_standard.title).to eql gs.title
end
it "should copy grading standards referenced by exported assignments" do
gs1, gs2 = make_grading_standard(@copy_from, title: 'One'), make_grading_standard(@copy_from, title: 'Two')
assign = @copy_from.assignments.build