Skip to content

Commit

Permalink
Add level filters for all graduate and all undergraduate.
Browse files Browse the repository at this point in the history
  • Loading branch information
CraigJZ committed Nov 16, 2023
1 parent b6c3679 commit 13a0978
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
11 changes: 10 additions & 1 deletion app/controllers/sections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ def filter

unless params[:section][:level].blank?
@section_level = params[:section][:level] if Section.level_code_list.include?(params[:section][:level])
@sections = @sections.in_level(@section_level) if @section_level.present?
if @section_level.present?
logger.debug("#{@section_level}")
if @section_level == 'uuall'
@sections = @sections.all_undergraduate
elsif @section_level == 'ugall'
@sections = @sections.all_graduate
else
@sections = @sections.in_level(@section_level)
end
end
end

unless params[:section][:modality].blank?
Expand Down
4 changes: 3 additions & 1 deletion app/models/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Section < ApplicationRecord
scope :undergraduate_under_enrolled, -> { undergraduate_level.not_canceled.where('actual_enrollment < ? and cross_list_enrollment < ?', undergraduate_enrollment_threshold, undergraduate_enrollment_threshold) }
scope :graduate_level, -> { where("lower(level) like 'ug%'") }
scope :undergraduate_level, -> { where("lower(level) like 'uu%'") }
scope :all_graduate, -> { where(level: ['UGF', 'UGA']) }
scope :all_undergraduate, -> { where(level: ['UUL', 'UUU']) }
scope :with_status, -> { where("status is not null and status <> ' '") }
scope :in_level, ->(level) { where("lower(level) = ?", level.downcase) }

Expand Down Expand Up @@ -110,7 +112,7 @@ def self.modality_list
end

def self.level_list
[['Undergraduate - Lower Division','uul'],['Undergraduate - Upper Division','uuu'],['Graduate - First','ugf'],['Graduate - Advanced','uga']]
[['Undergraduate - Lower Division','uul'],['Undergraduate - Upper Division','uuu'],['Undergraduate - All', 'uuall'],['Graduate - First','ugf'],['Graduate - Advanced','uga'],['Graduate - All', 'ugall']]
end

def self.level_name_list
Expand Down
12 changes: 10 additions & 2 deletions test/models/section_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class SectionTest < ActiveSupport::TestCase
end

test 'should create a list of level names available for selection' do
assert_equal @sections.level_name_list, ["Undergraduate - Lower Division", "Undergraduate - Upper Division", "Graduate - First", "Graduate - Advanced"]
assert_equal @sections.level_name_list, ["Undergraduate - Lower Division", "Undergraduate - Upper Division", "Undergraduate - All", "Graduate - First", "Graduate - Advanced", "Graduate - All"]
end

test 'should create a list of level codes available for selection' do
assert_equal @sections.level_code_list, %w[uul uuu ugf uga]
assert_equal @sections.level_code_list, %w[uul uuu uuall ugf uga ugall]
end

test 'should create a list of enrollment statuses' do
Expand Down Expand Up @@ -109,6 +109,14 @@ class SectionTest < ActiveSupport::TestCase
assert_equal @sections.uul, [@section]
end

test 'all_graduate scope should properly filter sections by level' do
assert_equal @sections.all_graduate, [@section_two, @section_three, @section_five]
end

test 'all_undergraduate scope should properly filter sections by level' do
assert_equal @sections.all_undergraduate, [@section, @section_four]
end

test 'graduate_under_enrolled and graduate_level scopes should return graduate sections where actual enrollment and cross list enrollment is less than the enrollment threshold' do
@section_three.update(actual_enrollment: 7)
@section_three.update(cross_list_enrollment: 2)
Expand Down
20 changes: 20 additions & 0 deletions test/system/sections_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ class SectionsTest < ApplicationSystemTestCase
assert_selector 'table tbody tr td', text: 'SINT'
assert_selector 'table tbody tr td', text: 'Experiential Learning'
assert_selector 'table tbody tr td', text: 'Graduate - Advanced'
select('Graduate - All')
sleep 2
click_link('filter-submit')
assert_selector 'table tbody tr', count: 2
assert_selector 'table tbody tr td', text: 'CRIM'
assert_selector 'table tbody tr td', text: 'Criminal Justice'
assert_selector 'table tbody tr td', text: 'Graduate - First'
assert_selector 'table tbody tr td', text: 'SINT'
assert_selector 'table tbody tr td', text: 'Experiential Learning'
assert_selector 'table tbody tr td', text: 'Graduate - Advanced'
end

test 'filtering by undergraduate level' do
Expand All @@ -97,6 +107,16 @@ class SectionsTest < ApplicationSystemTestCase
assert_selector 'table tbody tr td', text: 'ENGL'
assert_selector 'table tbody tr td', text: 'MyString'
assert_selector 'table tbody tr td', text: 'Undergraduate - Upper Division'
select('Undergraduate - All', from: 'section_level')
sleep 2
click_link('filter-submit')
assert_selector 'table tbody tr', count: 2
assert_selector 'table tbody tr td', text: 'ENGL'
assert_selector 'table tbody tr td', text: 'MyString'
assert_selector 'table tbody tr td', text: 'Undergraduate - Upper Division'
assert_selector 'table tbody tr td', text: 'BIS'
assert_selector 'table tbody tr td', text: 'MyString'
assert_selector 'table tbody tr td', text: 'Undergraduate - Lower Division'
end

test 'filtering by flagged as' do
Expand Down

0 comments on commit 13a0978

Please sign in to comment.