fix old improperly serialized rubric assessment yaml
closes #CNVS-28412 Change-Id: If903f173a9ef8408b5b99a0f9ea6502d13f67c24 Reviewed-on: https://gerrit.instructure.com/76442 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins Product-Review: James Williams <jamesw@instructure.com> QA-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
parent
c3386397ef
commit
ec3dc5f199
|
@ -0,0 +1,10 @@
|
|||
class FixRubricAssessmentYaml < ActiveRecord::Migration
|
||||
tag :postdeploy
|
||||
|
||||
def up
|
||||
DataFixup::FixRubricAssessmentYAML.send_later_if_production(:run)
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
module DataFixup
|
||||
module FixRubricAssessmentYAML
|
||||
def self.run
|
||||
# TODO: can remove when Syckness is removed
|
||||
RubricAssessment.find_ids_in_ranges(:batch_size => 10000) do |min_id, max_id|
|
||||
RubricAssessment.where(:id => min_id..max_id).
|
||||
where("data LIKE ? AND data LIKE ?", "%#{Syckness::TAG}", "%comments_html:%").
|
||||
pluck("id", "data as d1").each do |id, yaml|
|
||||
|
||||
new_yaml = yaml.gsub(/\:comments_html\:\s*([^!\s])/) do
|
||||
":comments_html: !str #{$1}"
|
||||
end
|
||||
if new_yaml != yaml
|
||||
RubricAssessment.where(:id => id).update_all(:data => CANVAS_RAILS4_0 ? new_yaml : YAML.load(new_yaml))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe DataFixup::FixRubricAssessmentYAML do
|
||||
it 'should fix-up comments_html strings that were improperly serialized' do
|
||||
assignment_model
|
||||
@teacher = user(:active_all => true)
|
||||
@course.enroll_teacher(@teacher).accept
|
||||
@student = user(:active_all => true)
|
||||
@course.enroll_student(@student).accept
|
||||
rubric_model
|
||||
@association = @rubric.associate_with(@assignment, @course, :purpose => 'grading', :use_for_grading => true)
|
||||
@assessment = @association.assess({
|
||||
:user => @student,
|
||||
:assessor => @teacher,
|
||||
:artifact => @assignment.find_or_create_submission(@student),
|
||||
:assessment => {
|
||||
:assessment_type => 'grading',
|
||||
:criterion_crit1 => {
|
||||
:points => 5,
|
||||
:comments => "yes",
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
old_data = @assessment.data
|
||||
|
||||
bad_yaml = RubricAssessment.where(:id => @assessment).pluck("data as d").first.gsub(":comments_html: !str", ":comments_html:")
|
||||
bad_data = YAML.load(bad_yaml)
|
||||
expect(bad_data.first[:comments_html]).to_not eq "yes" # it's reading it as a boolean
|
||||
RubricAssessment.where(:id => @assessment).update_all(:data => CANVAS_RAILS4_0 ? bad_yaml : bad_data)
|
||||
|
||||
DataFixup::FixRubricAssessmentYAML.run
|
||||
|
||||
@assessment.reload
|
||||
expect(@assessment.data.first[:comments_html]).to eq "yes" # should be fixed now
|
||||
expect(@assessment.data).to eq old_data
|
||||
|
||||
DataFixup::FixRubricAssessmentYAML.run # running again won't change anything
|
||||
|
||||
@assessment.reload
|
||||
expect(@assessment.data).to eq old_data
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue