Sha256: d2ce63a582e2c54f2bce5a64d79551f776e84053dfde5974af5b635d1c299d8a

Contents?: true

Size: 1.76 KB

Versions: 3

Compression:

Stored size: 1.76 KB

Contents

require "test_helper"

class Identity::EmailVerificationsControllerTest < ActionDispatch::IntegrationTest
  setup do
    @<%= singular_table_name %> = sign_in_as(<%= table_name %>(:lazaro_nixon))
    @sid = @<%= singular_table_name %>.signed_id(purpose: @<%= singular_table_name %>.email, expires_in: 20.minutes)
    @sid_exp = @<%= singular_table_name %>.signed_id(purpose: @<%= singular_table_name %>.email, expires_in: 0.minutes)

    @<%= singular_table_name %>.update! verified: false
  end

  test "should send a verification email" do
    assert_enqueued_email_with IdentityMailer, :email_verify_confirmation, args: { <%= singular_table_name %>: @<%= singular_table_name %> } do
      post identity_email_verification_url
    end

    assert_redirected_to root_url
  end

  test "should verify email" do
    get edit_identity_email_verification_url(token: @sid, email: @<%= singular_table_name %>.email)
    assert_redirected_to root_url
  end

  test "should not verify email with expired token" do
    get edit_identity_email_verification_url(token: @sid_exp, email: @<%= singular_table_name %>.email)

    assert_redirected_to edit_identity_email_url
    assert_equal "That email verification link is invalid", flash[:alert]
  end

  test "should not verify email with previous token" do
    @<%= singular_table_name %>.update! email: "other_email@hey.com"

    get edit_identity_email_verification_url(token: @sid, email: @<%= singular_table_name %>.email_previously_was)

    assert_redirected_to edit_identity_email_url
    assert_equal "That email verification link is invalid", flash[:alert]
  end

  def sign_in_as(<%= singular_table_name %>)
    post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); <%= singular_table_name %>
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
authentication-zero-2.9.2 lib/generators/authentication/templates/test_unit/controllers/html/identity/email_verifications_controller_test.rb.tt
authentication-zero-2.9.1 lib/generators/authentication/templates/test_unit/controllers/html/identity/email_verifications_controller_test.rb.tt
authentication-zero-2.9.0 lib/generators/authentication/templates/test_unit/controllers/html/identity/email_verifications_controller_test.rb.tt