refactor(turbo): password complexity check use turbo

This commit is contained in:
Paul Chavard 2022-05-04 12:41:39 +02:00
parent 2db892d876
commit f8e3397f82
4 changed files with 10 additions and 7 deletions

View file

@ -1,4 +1,4 @@
= form.password_field :password, autofocus: true, autocomplete: 'off', placeholder: 'Mot de passe', data: { remote: test_complexity, url: show_password_complexity_path }
= form.password_field :password, autofocus: true, autocomplete: 'off', placeholder: 'Mot de passe', data: { controller: test_complexity ? 'turbo-input' : false, turbo_input_url_value: show_password_complexity_path }
- if test_complexity
#complexity-bar.password-complexity

View file

@ -1,3 +0,0 @@
<%= render_to_element('#complexity-label', partial: 'label', outer: true) %>
<%= render_to_element('#complexity-bar', partial: 'bar', outer: true) %>
<%= raw("document.querySelector('#submit-password').disabled = #{@score < @min_complexity || @length < @min_length};") %>

View file

@ -0,0 +1,6 @@
= turbo_stream.replace 'complexity-label', partial: 'label'
= turbo_stream.replace 'complexity-bar', partial: 'bar'
- if @score < @min_complexity || @length < @min_length
= turbo_stream.disable 'submit-password'
- else
= turbo_stream.enable 'submit-password'

View file

@ -4,7 +4,7 @@ describe PasswordComplexityController, type: :controller do
{ user: { password: 'moderately complex password' } }
end
subject { get :show, format: :js, params: params, xhr: true }
subject { get :show, format: :turbo_stream, params: params }
it 'computes a password score' do
subject
@ -27,8 +27,8 @@ describe PasswordComplexityController, type: :controller do
it 'renders Javascript that updates the password complexity meter' do
subject
expect(response.body).to include('#complexity-label')
expect(response.body).to include('#complexity-bar')
expect(response.body).to include('complexity-label')
expect(response.body).to include('complexity-bar')
end
end
end