Sha256: 5a0fad487e0606bcdc90c6fd2dc024ba37968ae21e00551e493f5875a5641a53

Contents?: true

Size: 1.96 KB

Versions: 4

Compression:

Stored size: 1.96 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
<% if options.lockable? %>
  teardown { Kredis.clear_all }
<% end -%>

  test "should send a password reset email" do
    assert_enqueued_email_with IdentityMailer, :password_reset_provision, args: { <%= singular_table_name %>: @<%= singular_table_name %> } do
      post password_reset_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_reset_url, params: { email: "invalid_email@hey.com" }
    end

    assert_response :not_found
    assert_equal "You can't reset your password until you verify your email", response.parsed_body["error"]
  end

  test "should not send a password reset email to a unverified email" do
    @<%= singular_table_name %>.update! verified: false

    assert_no_enqueued_emails do
      post password_reset_url, params: { email: @<%= singular_table_name %>.email }
    end

    assert_response :not_found
    assert_equal "You can't reset your password until you verify your email", response.parsed_body["error"]
  end

  test "should update password" do
    patch password_reset_url, params: { token: @sid, password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" }
    assert_response :success
  end

  test "should not update password with expired token" do
    patch password_reset_url, params: { token: @sid_exp, password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" }

    assert_response :bad_request
    assert_equal "That password reset link is invalid", response.parsed_body["error"]
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
authentication-zero-2.7.0 lib/generators/authentication/templates/test_unit/controllers/api/password_resets_controller_test.rb.tt
authentication-zero-2.6.0 lib/generators/authentication/templates/test_unit/controllers/api/password_resets_controller_test.rb.tt
authentication-zero-2.5.1 lib/generators/authentication/templates/test_unit/controllers/api/password_resets_controller_test.rb.tt
authentication-zero-2.5.0 lib/generators/authentication/templates/test_unit/controllers/api/password_resets_controller_test.rb.tt