Commit 2d45d1b3 authored by Zac Wood's avatar Zac Wood

Keep track of semester by query param instead of cookie

parent 45df0731
......@@ -30,8 +30,9 @@ document.addEventListener('DOMContentLoaded', () => {
});
const setSemester = async select => {
const resp = await fetch(`/sessions/update?semester_id=${select.value}`);
location.reload(true);
const url = new URL(window.location.href);
url.searchParams.set('semester_id', select.value);
window.open(url.toString(), '_self');
};
const initGlobalListeners = () => {
......
......@@ -4,13 +4,8 @@ class ApplicationController < ActionController::Base
before_action :set_semester, :set_cookies, :set_cart
def set_semester
@semester = if cookies.key?(:semester_id)
Semester.find_by(id: cookies[:semester_id])
else
sem = Semester.first
cookies[:semester_id] = sem.id
sem
end
redirect_to(url_for(params.permit(params.keys).merge(semester_id: Semester.first.id))) unless params.key?(:semester_id)
@semester = Semester.find_by_id params[:semester_id]
end
def set_cart
......
# Contains logic regarding the +Course+ model.
#
# TODO: Add more docs
class Course < ApplicationRecord
# Each course belongs to a +Semester+
belongs_to :semester
......
......@@ -2,7 +2,7 @@ require 'test_helper'
class API::CourseListingsControllerTest < ActionDispatch::IntegrationTest
test 'should grab sections for course' do
get course_listings_url course_id: courses(:cs112).id
get course_listings_url course_id: courses(:cs112).id, semester_id: semesters(:fall2018).id
assert_response :success
listing_returned = JSON.parse @response.body
......
......@@ -2,7 +2,7 @@ require 'test_helper'
class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
test 'should get index' do
get api_course_sections_url course_id: courses(:cs112).id
get api_course_sections_url course_id: courses(:cs112).id, semester_id: semesters(:fall2018).id
assert_response :success
sections_returned = JSON.parse @response.body
......@@ -12,7 +12,7 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
end
test 'should filter by crn' do
get api_course_sections_url crn: course_sections(:cs112001).crn
get api_course_sections_url crn: course_sections(:cs112001).crn, semester_id: semesters(:fall2018).id
assert_response :success
sections_returned = JSON.parse @response.body
......@@ -20,7 +20,7 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
end
test 'should filter by professor' do
get api_course_sections_url instructor: "king"
get api_course_sections_url instructor: "king", semester_id: semesters(:fall2018).id
assert_response :success
sections_returned = JSON.parse @response.body
......
......@@ -2,7 +2,7 @@ require 'test_helper'
class API::CoursesControllerTest < ActionDispatch::IntegrationTest
test '#index should return all courses' do
get api_courses_url
get api_courses_url semester_id: semesters(:fall2018).id
assert_response :success
courses_returned = JSON.parse @response.body
......@@ -11,7 +11,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
end
test '#index should return filtered by subject case insensitive' do
get api_courses_url subject: "Cs"
get api_courses_url subject: "Cs", semester_id: semesters(:fall2018).id
assert_response :success
courses_returned = JSON.parse @response.body
......@@ -21,7 +21,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
end
test '#index should return filtered by subject and course number' do
get api_courses_url subject: "CS", course_number: "112"
get api_courses_url subject: "CS", course_number: "112", semester_id: semesters(:fall2018).id
assert_response :success
courses_returned = JSON.parse @response.body
......@@ -33,7 +33,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
test '#show should return course_sections for course' do
cs_112_id = courses(:cs112).id
get api_course_url id: cs_112_id
get api_course_url id: cs_112_id, semester_id: semesters(:fall2018).id
assert_response :success
sections_returned = JSON.parse @response.body
......
......@@ -3,7 +3,7 @@ require 'test_helper'
class API::SchedulesControllerTest < ActionDispatch::IntegrationTest
test "should generate schedule" do
ids = [course_sections(:cs112001).id, course_sections(:cs112002).id]
get "/api/schedules?section_ids=#{ids.join(',')}"
get "/api/schedules?section_ids=#{ids.join(',')}&semester_id=#{semesters(:fall2018).id}"
# DTSTAMP and UID lines uniquely identify events, so we can't test against them.
# so remove all the lines starting with them.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment