Sha256: c00735fd3c796362d807c36dbabce17fb938187de6e3fabe363163731f5f4343

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

require "test_helper"

class PasswordResetsControllerTest < ActionDispatch::IntegrationTest
  setup do
    @<%= singular_table_name %> = <%= table_name %>(:lazaro_nixon)
    @sid = @<%= singular_table_name %>.signed_id(purpose: :password_reset, expires_in: 20.minutes)
    @sid_exp = @<%= singular_table_name %>.signed_id(purpose: :password_reset, expires_in: 0.minutes)
  end

  test "should send a password reset email" do
    assert_enqueued_email_with PasswordMailer, :reset, args: { <%= singular_table_name %>: @<%= singular_table_name %> } do
      post password_resets_url, params: { email: @<%= singular_table_name %>.email }
    end

    assert_response :no_content
  end

  test "should not send a password reset email to a nonexistent email" do
    assert_no_enqueued_emails do
      post password_resets_url, params: { email: "invalid_email@hey.com" }
    end

    assert_response :not_found
    assert_equal "Sorry, we didn't recognize that email address", response.parsed_body["error"]
  end

  test "should update password" do
    patch password_resets_url, params: { token: @sid, password: "new_password", password_confirmation: "new_password" }
    assert_response :success
  end

  test "should not update password with expired token" do
    patch password_resets_url, params: { token: @sid_exp, password: "new_password", password_confirmation: "new_password" }

    assert_response :bad_request
    assert_equal "Your token has expired, please request a new one", response.parsed_body["error"]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
authentication-zero-2.1.0 lib/generators/authentication/templates/test_unit/controllers/api/password_resets_controller_test.rb.tt
authentication-zero-2.0.0 lib/generators/authentication/templates/test_unit/controllers/api/password_resets_controller_test.rb.tt