-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rspec has Line Coverage: 92.96 (251 / 270)
- Loading branch information
1 parent
760f787
commit e3edf2b
Showing
3 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe CoursesController, type: :controller do | ||
render_views | ||
let(:schedule) { Schedule.create!(schedule_name: 'Fall Semester', semester_name: '2024') } | ||
|
||
describe 'GET #index' do | ||
before do | ||
@user = User.create!(uid: '12345', provider: 'google_oauth2', email: '[email protected]', first_name: 'John', | ||
last_name: 'Doe') | ||
allow(controller).to receive(:logged_in?).and_return(true) | ||
controller.instance_variable_set(:@current_user, @user) | ||
end | ||
|
||
it 'incorrect schedule id' do | ||
get :index, params: { schedule_id: (schedule.id + 1) } | ||
expect(flash[:alert]).to eq('Schedule not found.') | ||
end | ||
|
||
context 'without added courses ' do | ||
before do | ||
get :index, params: { schedule_id: schedule.id } | ||
end | ||
|
||
it 'try seeing the courses' do | ||
expect(assigns(:courses)).to be_empty | ||
end | ||
|
||
it 'displays a message saying no courses added to this schedule' do | ||
expect(response.body).to include('No courses added to this schedule!') | ||
end | ||
end | ||
context 'with added courses ' do | ||
let!(:course1) do | ||
create(:course, course_number: '120', max_seats: 90, lecture_type: 'Hybrid', num_labs: 3, schedule_id: schedule.id) | ||
end | ||
let!(:section11) do | ||
create(:section, section_number: '500', seats_alloted: 30, course_id: course1.id) | ||
end | ||
let!(:section12) do | ||
create(:section, section_number: '501', seats_alloted: 30, course_id: course1.id) | ||
end | ||
let!(:section13) do | ||
create(:section, section_number: '502', seats_alloted: 30, course_id: course1.id) | ||
end | ||
let!(:course2) do | ||
create(:course, course_number: '320', max_seats: 120, lecture_type: 'Online', num_labs: 2, schedule_id: schedule.id) | ||
end | ||
let!(:section21) do | ||
create(:section, section_number: '500', seats_alloted: 60, course_id: course2.id) | ||
end | ||
let!(:section22) do | ||
create(:section, section_number: '501', seats_alloted: 60, course_id: course2.id) | ||
end | ||
let!(:course3) do | ||
create(:course, course_number: '400', max_seats: 150, lecture_type: 'F2F', num_labs: 1, schedule_id: schedule.id) | ||
end | ||
let!(:section31) do | ||
create(:section, section_number: '500', seats_alloted: 150, course_id: course3.id) | ||
end | ||
|
||
|
||
context 'without any sorting' do | ||
it 'assigns all courses to @courses' do | ||
get :index, params: { schedule_id: schedule.id } | ||
expect(assigns(:courses)).to match_array([course1, course2, course3]) | ||
end | ||
end | ||
|
||
|
||
context 'with sorting by course_number' do | ||
it 'assigns courses sorted by course_number ascending to @courses' do | ||
get :index, params: { schedule_id: schedule.id, sort: 'course_number', direction: 'asc' } | ||
expect(assigns(:courses)).to eq([course1, course2, course3]) | ||
end | ||
it 'assigns courses sorted by course_number descending to @courses' do | ||
get :index, params: { schedule_id: schedule.id, sort: 'course_number', direction: 'desc' } | ||
expect(assigns(:courses)).to eq([course3, course2, course1]) | ||
end | ||
end | ||
|
||
context 'with sorting by max_seats' do | ||
it 'assigns courses sorted by max_seats ascending to @courses' do | ||
get :index, params: { schedule_id: schedule.id, sort: 'max_seats', direction: 'asc' } | ||
expect(assigns(:courses)).to eq([course1, course2, course3]) | ||
end | ||
it 'assigns courses sorted by max_seats descending to @courses' do | ||
get :index, params: { schedule_id: schedule.id, sort: 'max_seats', direction: 'desc' } | ||
expect(assigns(:courses)).to eq([course3, course2, course1]) | ||
end | ||
end | ||
|
||
context 'with sorting by lecture_type' do | ||
it 'assigns courses sorted by lecture_type ascending to @courses' do | ||
get :index, params: { schedule_id: schedule.id, sort: 'lecture_type', direction: 'asc' } | ||
expect(assigns(:courses)).to eq([course3, course1, course2]) | ||
end | ||
it 'assigns courses sorted by lecture_type descending to @courses' do | ||
get :index, params: { schedule_id: schedule.id, sort: 'lecture_type', direction: 'desc' } | ||
expect(assigns(:courses)).to eq([course2, course1, course3]) | ||
end | ||
end | ||
|
||
context 'with sorting by num_labs' do | ||
it 'assigns courses sorted by num_labs ascending to @courses' do | ||
get :index, params: { schedule_id: schedule.id, sort: 'num_labs', direction: 'asc' } | ||
expect(assigns(:courses)).to eq([course3, course2, course1]) | ||
end | ||
it 'assigns courses sorted by num_labs descending to @courses' do | ||
get :index, params: { schedule_id: schedule.id, sort: 'num_labs', direction: 'desc' } | ||
expect(assigns(:courses)).to eq([course1, course2, course3]) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
110,96,F2F,4,"500,501,502,503","24,24,24,24",None,,, ,,, | ||
110,96,F2F,4,"504,505,506, 507","24,24,24,24",None,,,,,, | ||
111,96,F2F,4,"500,501,502,503","24,24,24,24",None,,,,,, | ||
111/708 (86/10),96,F2F,5,"504, 505, 506, 507","24, 24, 24, 24",None,,,,,, | ||
120,96,F2F,4,"500,501,502,503","24,24,24,24",None,,,,,, | ||
120,96,F2F,4,"504,505,506,507","24,24,24,24",None,,,,,, | ||
120,96,F2F,4,"508,509,510,511","24,24,24,24",None,,,,,, | ||
120,96,F2F,4,"512,513,545,515","24,24,24,24",None,,,,,, | ||
120,96,F2F,4,"516,517,518,519","24,24,24,24",None,,,,,, | ||
435/735/735D,135,F2F,2,"435-500, 735-600/700","95,40","CPSC, CECN, COMP, CEEN, CPEN",,,,,, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters