Skip to content

Commit

Permalink
Merge pull request #1528 from Nexmo/APIDOC-295_fix_sidenav_tutorials
Browse files Browse the repository at this point in the history
APIDOC-295: Guard clause for tutorial product and params[product]
  • Loading branch information
marcoranieri authored Jul 22, 2022
2 parents 919f982 + 05a879a commit ab3d1db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/nexmo_developer/app/controllers/tutorial_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def set_navigation
end

def set_sidenav
@sidenav_product = params[:product] || @tutorial.yaml['products'].first
@sidenav_product = params[:product]

if @tutorial
@sidenav_product ||= @tutorial.yaml['products'].first
end

@sidenav = Sidenav.new(
namespace: params[:namespace],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

RSpec.describe TutorialController, type: :controller do
it 'renders' do
get :list, params: { product: 'messaging/sms' }
get :list

expect(response.status).to eq(200)
end

describe 'when a locale is present' do
it 'redirects to the canonical url if locale is :en' do
get :list, params: { locale: 'en', product: '' }
get :list, params: { locale: 'en' }

expect(response).to redirect_to('/tutorials')
end

it 'renders when locale is different from :en' do
get :list, params: { locale: 'cn', product: 'messaging/sms' }
get :list, params: { locale: 'cn' }

expect(response.status).to eq(200)
end
Expand Down

0 comments on commit ab3d1db

Please sign in to comment.