require "test_helper" class PasswordsControllerTest < ActionDispatch::IntegrationTest setup do @<%= singular_table_name %>, @token = sign_in_as(<%= table_name %>(:lazaro_nixon)) end test "should update password" do assert_enqueued_email_with PasswordMailer, :changed, args: { <%= singular_table_name %>: @<%= singular_table_name %> } do patch passwords_url, params: { current_password: "secret123", password: "new_password", password_confirmation: "new_password" }, headers: { "Authorization" => "Bearer #{@token}" } end assert_response :success end test "should not update password with wrong current password" do assert_no_enqueued_emails do patch passwords_url, params: { current_password: "wrong_password", password: "new_password", password_confirmation: "new_password" }, headers: { "Authorization" => "Bearer #{@token}" } end assert_response :bad_request assert_equal "The current password you entered is incorrect", response.parsed_body["error"] end def sign_in_as(<%= singular_table_name %>) post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" }) [<%= singular_table_name %>, response.headers["X-Session-Token"]] end end