require 'rails_helper'
RSpec.feature '<%= human_name %> resets a password' do
scenario '<%= singular_name %> enters a valid email' do
<% if fixture_replacement == :factory_bot -%>
<%= singular_name %> = create :<%= singular_name %>
<% elsif fixture_replacement == :fabrication -%>
<%= singular_name %> = Fabricate :<%= singular_name %>
<% end -%>
visit new_<%= singular_name %>_password_path fill_in 'Email', with: <%= singular_name %>.email click_button 'Send me reset password instructions' expect(page).to have_text 'You will receive an email with instructions' expect(page).to have_current_path new_<%= singular_name %>_session_path end scenario '<%= singular_name %> enters an invalid email' do visit new_<%= singular_name %>_password_path fill_in 'Email', with: 'username@example.com' click_button 'Send me reset password instructions' expect(page).to have_text 'Email not found' end scenario '<%= singular_name %> changes password' do
<% if fixture_replacement == :factory_bot -%>
token = create(:<%= singular_name %>).send_reset_password_instructions
<% elsif fixture_replacement == :fabrication -%>
token = Fabricate(:<%= singular_name %>).send_reset_password_instructions
<% end -%>
visit edit_<%= singular_name %>_password_path(reset_password_token: token) fill_in 'New password', with: 'p4ssw0rd' fill_in 'Confirm new password', with: 'p4ssw0rd' click_button 'Change my password' expect(page).to have_text 'Your password has been changed successfully.' expect(page).to have_current_path root_path end scenario 'password reset token is invalid' do visit edit_<%= singular_name %>_password_path(reset_password_token: 'token') fill_in 'New password', with: 'p4ssw0rd' fill_in 'Confirm new password', with: 'p4ssw0rd' click_button 'Change my password' expect(page).to have_text 'Reset password token is invalid' end
end