don't allow nil rubric titles
also fixup current rubrics with nil titles test plan: * should not be able to create a rubric with a nil title closes #OUT-8 Change-Id: Ic58b0c6f513ad54e11fed1b95342be16f6fd6e3f Reviewed-on: https://gerrit.instructure.com/88496 Tested-by: Jenkins Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Product-Review: James Williams <jamesw@instructure.com> QA-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
parent
d1091db3d8
commit
5f2090172d
|
@ -42,6 +42,7 @@ module Importers
|
|||
item.migration_id = hash[:migration_id]
|
||||
item.workflow_state = 'active' if item.deleted?
|
||||
item.title = hash[:title]
|
||||
item.populate_rubric_title # just in case
|
||||
item.description = hash[:description]
|
||||
item.points_possible = hash[:points_possible].to_f
|
||||
item.read_only = hash[:read_only] unless hash[:read_only].nil?
|
||||
|
|
|
@ -28,7 +28,7 @@ class Rubric < ActiveRecord::Base
|
|||
|
||||
validates_presence_of :context_id, :context_type, :workflow_state
|
||||
validates_length_of :description, :maximum => maximum_text_length, :allow_nil => true, :allow_blank => true
|
||||
validates_length_of :title, :maximum => maximum_string_length, :allow_nil => true, :allow_blank => true
|
||||
validates_length_of :title, :maximum => maximum_string_length, :allow_nil => false, :allow_blank => false
|
||||
|
||||
before_validation :default_values
|
||||
after_save :update_alignments
|
||||
|
@ -75,13 +75,19 @@ class Rubric < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def default_values
|
||||
original_title = self.title
|
||||
if Rails.env.test?
|
||||
populate_rubric_title # there are too many specs to change and i'm too lazy
|
||||
end
|
||||
|
||||
cnt = 0
|
||||
siblings = Rubric.where(context_id: self.context_id, context_type: self.context_type).where("workflow_state<>'deleted'")
|
||||
siblings = siblings.where("id<>?", self.id) unless new_record?
|
||||
while siblings.where(title: self.title).exists?
|
||||
cnt += 1
|
||||
self.title = "#{original_title} (#{cnt})"
|
||||
if self.title.present?
|
||||
original_title = self.title
|
||||
while siblings.where(title: self.title).exists?
|
||||
cnt += 1
|
||||
self.title = "#{original_title} (#{cnt})"
|
||||
end
|
||||
end
|
||||
self.context_code = "#{self.context_type.underscore}_#{self.context_id}" rescue nil
|
||||
end
|
||||
|
@ -211,6 +217,10 @@ class Rubric < ActiveRecord::Base
|
|||
false
|
||||
end
|
||||
|
||||
def populate_rubric_title
|
||||
self.title ||= t('context_name_rubric', "%{course_name} Rubric", :course_name => context.name)
|
||||
end
|
||||
|
||||
CriteriaData = Struct.new(:criteria, :points_possible, :title)
|
||||
def generate_criteria(params)
|
||||
@used_ids = {}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class FixNullRubricTitles < ActiveRecord::Migration
|
||||
tag :postdeploy
|
||||
|
||||
def up
|
||||
DataFixup::FixNullRubricTitles.send_later_if_production_enqueue_args(
|
||||
:run, :priority => Delayed::LOW_PRIORITY, :max_attempts => 1)
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
module DataFixup
|
||||
module FixNullRubricTitles
|
||||
def self.run
|
||||
Rubric.find_ids_in_ranges(:batch_size => 10_000) do |min_id, max_id|
|
||||
Rubric.where(:id => min_id..max_id).where(:title => nil).each do |rubric|
|
||||
rubric.populate_rubric_title
|
||||
rubric.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue