Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update stage -> lesson redirects to avoid server errors #46576

Merged
merged 1 commit into from May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions dashboard/config/routes.rb
Expand Up @@ -392,9 +392,11 @@
get '/s/:script_name/stage/:position/extras', to: redirect(path: '/s/%{script_name}/lessons/%{position}/extras')

# Redirects from old /stage/x/puzzle url to new /lessons/x/levels url
get '/s/:script_name/stage/:position/puzzle', to: redirect(path: '/s/%{script_name}/lessons/%{position}/levels')
get '/s/:script_name/stage/:position/puzzle/(*all)', to: redirect(path: '/s/%{script_name}/lessons/%{position}/levels/%{all}')

# Redirects from old /lockable/x/puzzle url to new /lockable/x/levels url
get '/s/:script_name/lockable/:position/puzzle', to: redirect(path: '/s/%{script_name}/lockable/%{position}/levels')
get '/s/:script_name/lockable/:position/puzzle/(*all)', to: redirect(path: '/s/%{script_name}/lockable/%{position}/levels/%{all}')

resources :scripts, path: '/s/' do
Expand Down
18 changes: 18 additions & 0 deletions dashboard/test/integration/redirects_test.rb
Expand Up @@ -65,6 +65,15 @@ class RedirectsTest < ActionDispatch::IntegrationTest

get '/s/allthethings/stage/33/puzzle/1/page/1'
assert_redirected_to '/s/allthethings/lessons/33/levels/1/page/1'

# ideally we would just return a 404, but it is easier to implement a
# redirect to a url which 404s.
get '/s/allthethings/stage/1/puzzle'
assert_redirected_to '/s/allthethings/lessons/1/levels'
e = assert_raises(ActionController::RoutingError) do
follow_redirect!
end
assert_includes e.message, 'No route matches'
end

test 'redirects urls with stage for lesson extras' do
Expand Down Expand Up @@ -98,6 +107,15 @@ class RedirectsTest < ActionDispatch::IntegrationTest

get '/s/test-script/lockable/1/puzzle/1/page/1'
assert_redirected_to '/s/test-script/lockable/1/levels/1/page/1'

# ideally we would just return a 404, but it is easier to implement a
# redirect to a url which 404s.
get '/s/test-script/lockable/1/puzzle'
assert_redirected_to '/s/test-script/lockable/1/levels'
e = assert_raises(ActionController::RoutingError) do
follow_redirect!
end
assert_includes e.message, 'No route matches'
end

test 'old script id paths redirect to named paths' do
Expand Down