Sha256: 0a6758de1995be1020d404d66a254aabffc87b219c0fb7bd79f16001d85e0940

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

require "test_helper"

class EmailVerificationsControllerTest < ActionDispatch::IntegrationTest
  setup do
    @<%= singular_table_name %>, @token = sign_in_as(<%= table_name %>(:lazaro_nixon))
    @sid = @<%= singular_table_name %>.signed_id(purpose: "verify_#{@<%= singular_table_name %>.email}", expires_in: 20.minutes)
    @sid_exp = @<%= singular_table_name %>.signed_id(purpose: "verify_#{@<%= 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 email_verification_url, headers: { "Authorization" => "Bearer #{@token}" }
    end

    assert_response :no_content
  end

  test "should verify email" do
    patch email_verification_url, params: { token: @sid, email: @<%= singular_table_name %>.email }, headers: { "Authorization" => "Bearer #{@token}" }
    assert_response :no_content
  end

  test "should not verify email with expired token" do
    patch email_verification_url, params: { token: @sid_exp, email: @<%= singular_table_name %>.email }, headers: { "Authorization" => "Bearer #{@token}" }

    assert_response :bad_request
    assert_equal "That email verification link is invalid", 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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
authentication-zero-2.2.4 lib/generators/authentication/templates/test_unit/controllers/api/email_verifications_controller_test.rb.tt
authentication-zero-2.2.3 lib/generators/authentication/templates/test_unit/controllers/api/email_verifications_controller_test.rb.tt
authentication-zero-2.2.2 lib/generators/authentication/templates/test_unit/controllers/api/email_verifications_controller_test.rb.tt
authentication-zero-2.2.1 lib/generators/authentication/templates/test_unit/controllers/api/email_verifications_controller_test.rb.tt