Skip to content

Commit

Permalink
Corrige l'erreur undefined method upcase dans connexion_espace_jeu
Browse files Browse the repository at this point in the history
rollbar : https://app.rollbar.com/a/eva-betagouv/fix/item/eva/1002

```
NoMethodError: undefined method `upcase' for ["94102"]:Array

        code = params[:code].upcase
```
  • Loading branch information
etienneCharignon committed Sep 14, 2024
1 parent d2fa8d6 commit 62a90de
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/controllers/eva/devise/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def create
end

def connexion_espace_jeu
code = params[:code].upcase
campagne = Campagne.par_code(code)
code = params[:code]&.upcase
campagne = code.present? && Campagne.par_code(code)
if campagne.present?
params_url = { code: code }
url = "#{URL_CLIENT}?#{params_url.to_query}"
redirect_to url
redirect_to url, allow_other_host: true
else
code_erreur = t('active_admin.devise.login.evaluations.code_invalide')
redirect_to new_compte_session_path(code: code, code_erreur: code_erreur)
Expand Down
46 changes: 46 additions & 0 deletions spec/controllers/eva/devise/session_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

require 'rails_helper'

describe Eva::Devise::SessionsController, type: :controller do
let!(:compte) { create :compte_admin }
let!(:campagne) { create :campagne, compte: compte, code: 'CODECAMPAGNE' }
describe 'POST connexion_espace_jeu' do
context 'quand on passe un code campagne valide' do
it "redirige vers l'espace jeu" do
params = {
code: 'codecampagne'
}

@request.env['devise.mapping'] = Devise.mappings[:compte]
post :connexion_espace_jeu, params: params
expect(response).to redirect_to('http://localhost:7700/jeu?code=CODECAMPAGNE')
end
end

context 'retourne vers la pae de login' do
it 'quand on ne passe pas de code campagne' do
@request.env['devise.mapping'] = Devise.mappings[:compte]
post :connexion_espace_jeu, params: {}
expect(response).to redirect_to(
new_compte_session_path(
code_erreur: I18n.t('active_admin.devise.login.evaluations.code_invalide')
)
)
end

it 'quand on passe un code campagne vide' do
@request.env['devise.mapping'] = Devise.mappings[:compte]
post :connexion_espace_jeu, params: {
code: ''
}
expect(response).to redirect_to(
new_compte_session_path(
code: '',
code_erreur: I18n.t('active_admin.devise.login.evaluations.code_invalide')
)
)
end
end
end
end

0 comments on commit 62a90de

Please sign in to comment.