Skip to content

Commit

Permalink
Merge pull request #17500 from code-dot-org/fix-studio-redirect
Browse files Browse the repository at this point in the history
studio.code.org: redirect to /home if signed in, otherwise /courses
  • Loading branch information
breville committed Sep 5, 2017
2 parents a58088f + 2b645c3 commit 1c539b6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 33 deletions.
11 changes: 2 additions & 9 deletions dashboard/app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,11 @@ def health_check

GALLERY_PER_PAGE = 5

# Signed in student with assigned course: redirect to current_lesson
# Signed in, not student with assigned course: redirect to /home
# Signed in: redirect to /home
# Signed out: redirect to /courses
def index
if current_user
# We skip the redirect if the user does not have an age set, because we
# pop up the age interstitial on /home
if current_user.student? && current_user.primary_script && current_user.age.present?
redirect_to script_next_path(current_user.primary_script)
else
redirect_to '/home'
end
redirect_to '/home'
else
redirect_to '/courses'
end
Expand Down
25 changes: 1 addition & 24 deletions dashboard/test/controllers/home_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,14 @@ class HomeControllerTest < ActionController::TestCase
Properties.stubs(:get).returns nil
end

test "redirect to /home when signed in and not a student with course progress" do
test "redirect index when signed in" do
user = create(:user)
sign_in user
get :index

assert_redirected_to '/home'
end

test "student with course progress is redirected to next lesson" do
student = create :student
script = create :script
sign_in student
User.any_instance.expects(:primary_script).returns(script).twice
get :index

assert_redirected_to script_next_path(script)
end

test "student with course progress and no age is not redirected to next lesson" do
student = create :student
student.birthday = nil
student.age = nil
student.save(validate: false)
script = create :script
sign_in student
User.any_instance.expects(:primary_script).returns(script)
get :index

assert_redirected_to '/home'
end

test "redirect index when signed out" do
get :index

Expand Down

0 comments on commit 1c539b6

Please sign in to comment.