Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing NoMethodError: undefined method `+' for nil:NilClass #26677

Merged
merged 4 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion dashboard/app/models/school_stats_by_year.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,20 @@ def has_k8_grades?
end

def urm_percent
percent_of_students(student_am_count + student_hi_count + student_bl_count + student_hp_count)
total_urm_students = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest
[student_am_count, student_hi_count, student_bl_count, student_hp_count].compact.reduce(:+) instead for compactness

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh yeah that is much nicer!

if student_am_count.present?
total_urm_students += student_am_count
end
if student_hi_count.present?
total_urm_students += student_hi_count
end
if student_bl_count.present?
total_urm_students += student_bl_count
end
if student_hp_count.present?
total_urm_students += student_hp_count
end
percent_of_students(total_urm_students)
end

# returns what percent "count" is of the total student enrollment
Expand Down
13 changes: 13 additions & 0 deletions dashboard/test/models/school_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ class SchoolTest < ActiveSupport::TestCase
assert_equal(true, school.high_needs?)
end

test 'urm school stats missing counts' do
school = create :school
stats_by_year =
school.school_stats_by_year << SchoolStatsByYear.new(
school_id: school.id,
school_year: '1998-1999',
students_total: 4,
student_bl_count: 2
)
school.save!
assert_equal(50.0, stats_by_year.first.urm_percent)
end

test 'normalize_school_id works for short ids without leading zeros' do
normalized_id = School.normalize_school_id("123456")
assert_equal "123456", normalized_id
Expand Down