Skip to content

Commit 264a14e

Browse files
committed
copy rubrics associated with assignment even when not selected
Previously rubrics used by an assignment wouldn't copy unless the rubric was selected. This makes it so that an assignment will always bring its rubric when copied. This also copies the two rubric properties you can select when adding a rubric to an assignment. Test Plan: * Create an assignment with a rubric. Mark the rubric to be used for grading * Copy the course and don't select the rubric to be copied * In the new course the rubric should be there, and should be used for grading closes #8474 #8475 Change-Id: I3c117c10c159fed2d8a3d6c083f8251e8a97bee6 Reviewed-on: https://gerrit.instructure.com/10606 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
1 parent 65db1c0 commit 264a14e

6 files changed

Lines changed: 53 additions & 13 deletions

File tree

app/models/assignment.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,12 @@ def self.import_from_migration(hash, context, item=nil)
15691569
new_record = item.new_record?
15701570
if hash[:rubric_migration_id]
15711571
rubric = context.rubrics.find_by_migration_id(hash[:rubric_migration_id])
1572-
rubric.associate_with(item, context, :purpose => 'grading') if rubric
1572+
if rubric
1573+
assoc = rubric.associate_with(item, context, :purpose => 'grading')
1574+
assoc.use_for_grading = !!hash[:rubric_use_for_grading] if hash.has_key?(:rubric_use_for_grading)
1575+
assoc.hide_score_total = !!hash[:rubric_hide_score_total] if hash.has_key?(:rubric_hide_score_total)
1576+
assoc.save
1577+
end
15731578
end
15741579
if hash[:grading_standard_migration_id]
15751580
gs = context.grading_standards.find_by_migration_id(hash[:grading_standard_migration_id])

lib/cc/assignment_resources.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ def self.create_assignment(node, assignment)
8080
node.peer_reviews_due_at CCHelper::ims_datetime(assignment.peer_reviews_due_at) if assignment.peer_reviews_due_at
8181
node.assignment_group_identifierref CCHelper.create_key(assignment.assignment_group)
8282
node.grading_standard_identifierref CCHelper.create_key(assignment.grading_standard) if assignment.grading_standard
83-
node.rubric_identifierref CCHelper.create_key(assignment.rubric) if assignment.rubric
83+
if assignment.rubric
84+
assoc = assignment.rubric_association
85+
node.rubric_identifierref CCHelper.create_key(assignment.rubric)
86+
node.rubric_use_for_grading assoc.use_for_grading
87+
node.rubric_hide_score_total assoc.hide_score_total
88+
end
8489
node.quiz_identifierref CCHelper.create_key(assignment.quiz) if assignment.quiz
8590
node.allowed_extensions assignment.allowed_extensions.join(',') unless assignment.allowed_extensions.blank?
8691
atts = [:points_possible, :min_score, :max_score, :mastery_score, :grading_type,

lib/cc/importer/canvas/assignment_converter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def convert_assignment(meta_doc, html_doc=nil)
5757
end
5858
["all_day", "turnitin_enabled", "peer_reviews_assigned", "peer_reviews",
5959
"automatic_peer_reviews", "anonymous_peer_reviews", "freeze_on_copy",
60-
"grade_group_students_individually", "external_tool_new_tab"].each do |bool_val|
60+
"grade_group_students_individually", "external_tool_new_tab",
61+
"rubric_use_for_grading", "rubric_hide_score_total"].each do |bool_val|
6162
val = get_bool_val(meta_doc, bool_val)
6263
assignment[bool_val] = val unless val.nil?
6364
end

lib/cc/rubrics.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ def create_rubrics(document=nil)
4040
) do |rubrics_node|
4141
@course.rubric_associations.each do |assoc|
4242
rubric = assoc.rubric
43-
next if rubric.nil? || !rubric.active? || !export_object?(rubric) || imported_rubrics[rubric.id]
43+
next if rubric.nil? || !rubric.active? || imported_rubrics[rubric.id]
44+
if !export_object?(rubric)
45+
if assoc.association_type != "Assignment" || !export_object?(assoc.association)
46+
next
47+
end
48+
end
4449
imported_rubrics[rubric.id] = true
4550

4651
migration_id = CCHelper.create_key(rubric)

lib/cc/xsd/cccv1p0.xsd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
<xs:element name="assignment_group_identifierref" type="xs:string" minOccurs="0"/>
7878
<xs:element name="grading_standard_identifierref" type="xs:string" minOccurs="0"/>
7979
<xs:element name="rubric_identifierref" type="xs:string" minOccurs="0"/>
80+
<xs:element name="rubric_use_for_grading" type="xs:boolean" minOccurs="0"/>
81+
<xs:element name="rubric_hide_score_total" type="xs:boolean" minOccurs="0"/>
8082
<xs:element name="quiz_identifierref" type="xs:string" minOccurs="0"/>
8183
<xs:element name="allowed_extensions" type="xs:string" minOccurs="0"/>
8284
<xs:element name="points_possible" type="xs:float" minOccurs="0"/>

spec/models/content_migration_spec.rb

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,20 +438,42 @@ def mig_id(obj)
438438
@copy_to.discussion_topics.find_by_migration_id(mig_id(topic)).should_not be_nil
439439
end
440440

441-
it "should still associate rubrics and assignments" do
442-
rubric = @copy_from.rubrics.new
443-
rubric.title = "Rubric"
444-
rubric.data = [{:ratings=>[{:criterion_id=>"309_6312", :points=>5, :description=>"Full Marks", :id=>"blank", :long_description=>""}, {:criterion_id=>"309_6312", :points=>0, :description=>"No Marks", :id=>"blank_2", :long_description=>""}], :points=>5, :description=>"Description of criterion", :id=>"309_6312", :long_description=>""}]
445-
rubric.save!
441+
def create_rubric_asmnt
442+
@rubric = @copy_from.rubrics.new
443+
@rubric.title = "Rubric"
444+
@rubric.data = [{:ratings=>[{:criterion_id=>"309_6312", :points=>5, :description=>"Full Marks", :id=>"blank", :long_description=>""}, {:criterion_id=>"309_6312", :points=>0, :description=>"No Marks", :id=>"blank_2", :long_description=>""}], :points=>5, :description=>"Description of criterion", :id=>"309_6312", :long_description=>""}]
445+
@rubric.save!
446446

447-
assignment = @copy_from.assignments.create!(:title => "some assignment", :assignment_group => @group, :points_possible => 12)
448-
rubric.associate_with(assignment, @copy_from, :purpose => 'grading', :use_for_grading => true)
447+
@assignment = @copy_from.assignments.create!(:title => "some assignment", :points_possible => 12)
448+
assoc = @rubric.associate_with(@assignment, @copy_from, :purpose => 'grading', :use_for_grading => true)
449+
assoc.hide_score_total = true
450+
assoc.use_for_grading = true
451+
assoc.save!
452+
end
453+
454+
it "should still associate rubrics and assignments and copy rubric association properties" do
455+
create_rubric_asmnt
456+
run_course_copy
457+
458+
rub = @copy_to.rubrics.find_by_migration_id(mig_id(@rubric))
459+
rub.should_not be_nil
460+
asmnt2 = @copy_to.assignments.find_by_migration_id(mig_id(@assignment))
461+
asmnt2.rubric.id.should == rub.id
462+
asmnt2.rubric_association.use_for_grading.should == true
463+
asmnt2.rubric_association.hide_score_total.should == true
464+
end
449465

466+
it "should copy rubrics associated with assignments when rubric isn't selected" do
467+
create_rubric_asmnt
468+
@cm.copy_options = {
469+
:assignments => {mig_id(@assignment) => "1"},
470+
}
471+
@cm.save!
450472
run_course_copy
451473

452-
rub = @copy_to.rubrics.find_by_migration_id(mig_id(rubric))
474+
rub = @copy_to.rubrics.find_by_migration_id(mig_id(@rubric))
453475
rub.should_not be_nil
454-
asmnt2 = @copy_to.assignments.find_by_migration_id(mig_id(assignment))
476+
asmnt2 = @copy_to.assignments.find_by_migration_id(mig_id(@assignment))
455477
asmnt2.rubric.id.should == rub.id
456478
end
457479

0 commit comments

Comments
 (0)