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', () => { ...@@ -30,8 +30,9 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
const setSemester = async select => { const setSemester = async select => {
const resp = await fetch(`/sessions/update?semester_id=${select.value}`); const url = new URL(window.location.href);
location.reload(true); url.searchParams.set('semester_id', select.value);
window.open(url.toString(), '_self');
}; };
const initGlobalListeners = () => { const initGlobalListeners = () => {
......
...@@ -4,13 +4,8 @@ class ApplicationController < ActionController::Base ...@@ -4,13 +4,8 @@ class ApplicationController < ActionController::Base
before_action :set_semester, :set_cookies, :set_cart before_action :set_semester, :set_cookies, :set_cart
def set_semester def set_semester
@semester = if cookies.key?(:semester_id) redirect_to(url_for(params.permit(params.keys).merge(semester_id: Semester.first.id))) unless params.key?(:semester_id)
Semester.find_by(id: cookies[:semester_id]) @semester = Semester.find_by_id params[:semester_id]
else
sem = Semester.first
cookies[:semester_id] = sem.id
sem
end
end end
def set_cart def set_cart
......
# Contains logic regarding the +Course+ model. # Contains logic regarding the +Course+ model.
#
# TODO: Add more docs
class Course < ApplicationRecord class Course < ApplicationRecord
# Each course belongs to a +Semester+ # Each course belongs to a +Semester+
belongs_to :semester belongs_to :semester
......
...@@ -2,7 +2,7 @@ require 'test_helper' ...@@ -2,7 +2,7 @@ require 'test_helper'
class API::CourseListingsControllerTest < ActionDispatch::IntegrationTest class API::CourseListingsControllerTest < ActionDispatch::IntegrationTest
test 'should grab sections for course' do 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 assert_response :success
listing_returned = JSON.parse @response.body listing_returned = JSON.parse @response.body
......
...@@ -2,7 +2,7 @@ require 'test_helper' ...@@ -2,7 +2,7 @@ require 'test_helper'
class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
test 'should get index' do 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 assert_response :success
sections_returned = JSON.parse @response.body sections_returned = JSON.parse @response.body
...@@ -12,7 +12,7 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest ...@@ -12,7 +12,7 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
end end
test 'should filter by crn' do 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 assert_response :success
sections_returned = JSON.parse @response.body sections_returned = JSON.parse @response.body
...@@ -20,7 +20,7 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest ...@@ -20,7 +20,7 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
end end
test 'should filter by professor' do 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 assert_response :success
sections_returned = JSON.parse @response.body sections_returned = JSON.parse @response.body
......
...@@ -2,7 +2,7 @@ require 'test_helper' ...@@ -2,7 +2,7 @@ require 'test_helper'
class API::CoursesControllerTest < ActionDispatch::IntegrationTest class API::CoursesControllerTest < ActionDispatch::IntegrationTest
test '#index should return all courses' do test '#index should return all courses' do
get api_courses_url get api_courses_url semester_id: semesters(:fall2018).id
assert_response :success assert_response :success
courses_returned = JSON.parse @response.body courses_returned = JSON.parse @response.body
...@@ -11,7 +11,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest ...@@ -11,7 +11,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
end end
test '#index should return filtered by subject case insensitive' do 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 assert_response :success
courses_returned = JSON.parse @response.body courses_returned = JSON.parse @response.body
...@@ -21,7 +21,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest ...@@ -21,7 +21,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
end end
test '#index should return filtered by subject and course number' do 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 assert_response :success
courses_returned = JSON.parse @response.body courses_returned = JSON.parse @response.body
...@@ -33,7 +33,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest ...@@ -33,7 +33,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
test '#show should return course_sections for course' do test '#show should return course_sections for course' do
cs_112_id = courses(:cs112).id 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 assert_response :success
sections_returned = JSON.parse @response.body sections_returned = JSON.parse @response.body
......
...@@ -3,7 +3,7 @@ require 'test_helper' ...@@ -3,7 +3,7 @@ require 'test_helper'
class API::SchedulesControllerTest < ActionDispatch::IntegrationTest class API::SchedulesControllerTest < ActionDispatch::IntegrationTest
test "should generate schedule" do test "should generate schedule" do
ids = [course_sections(:cs112001).id, course_sections(:cs112002).id] 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. # DTSTAMP and UID lines uniquely identify events, so we can't test against them.
# so remove all the lines starting with 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