chore: fix failing legacy tests

This commit is contained in:
Nelson Jovel 2023-11-03 10:18:46 -07:00
parent 79bc91d39f
commit 054e5603b7
5 changed files with 24 additions and 30 deletions

View file

@ -1,14 +1,14 @@
module Legacy
class Category < ApplicationRecord
has_many :questions
belongs_to :parent_category, class_name: 'Legacy::Category', foreign_key: :parent_category_id
has_many :child_categories, class_name: 'Legacy::Category', foreign_key: :parent_category_id
belongs_to :parent_category, class_name: "Legacy::Category", foreign_key: :parent_category_id, optional: true
has_many :child_categories, class_name: "Legacy::Category", foreign_key: :parent_category_id
has_many :school_categories
validates :name, presence: true
scope :for_parent, ->(category = nil) { where(parent_category_id: category.try(:id)) }
scope :likert, -> { where('benchmark is null') }
scope :likert, -> { where("benchmark is null") }
include FriendlyId
friendly_id :name, use: [:slugged]
@ -21,7 +21,7 @@ module Legacy
end
def root_identifier
path.first.name.downcase.gsub(/\s/, '-')
path.first.name.downcase.gsub(/\s/, "-")
end
def root_index
@ -46,7 +46,7 @@ module Legacy
def custom_zones
return [] if zones.nil?
zones.split(',').map(&:to_f)
zones.split(",").map(&:to_f)
end
def zone_widths
@ -83,11 +83,11 @@ module Legacy
end
end
if valid_child_categories > 0
average_zones = total_zones.map { |zone| zone / valid_child_categories }
puts "TOTAL: #{name} | #{total_zones} | #{valid_child_categories} | #{average_zones} | #{zone_widths}"
update(zones: average_zones.join(','))
end
return unless valid_child_categories > 0
average_zones = total_zones.map { |zone| zone / valid_child_categories }
puts "TOTAL: #{name} | #{total_zones} | #{valid_child_categories} | #{average_zones} | #{zone_widths}"
update(zones: average_zones.join(","))
end
end
end

View file

@ -11,7 +11,7 @@ AggregatedResponses = Struct.new(
module Legacy
class Question < ApplicationRecord
belongs_to :category
belongs_to :category, optional: true
has_many :attempts
@ -28,7 +28,7 @@ module Legacy
enum target_group: %i[unknown for_students for_teachers for_parents]
def source
target_group.gsub('for_', '')
target_group.gsub("for_", "")
end
def options
@ -69,7 +69,7 @@ module Legacy
end
def normalized_text
text.gsub('[science/math/English/social studies]', '')
text.gsub("[science/math/English/social studies]", "")
end
end
end

View file

@ -2,7 +2,7 @@ module Legacy
class School < ApplicationRecord
has_many :schedules, dependent: :destroy
has_many :recipient_lists, dependent: :destroy
belongs_to :district
belongs_to :district, optional: true
has_many :recipients, dependent: :destroy
has_many :school_categories, dependent: :destroy
has_many :user_schools, dependent: :destroy