Sha256: fd531107941c524747eebc4d4784f5aa6fbe425856c34ef8a2d30711170a3707

Contents?: true

Size: 1.17 KB

Versions: 9

Compression:

Stored size: 1.17 KB

Contents

require 'test_helper'

class EmailVerificationTest < ActionDispatch::IntegrationTest
  if User.include?(MustVerifyEmail)
    test 'email verification screen can be rendered' do
      user = FactoryBot.create(:user, :unverified)

      acting_as(user).get verification_notice_path

      assert_response :success
    end

    test 'email can be verified' do
      user = FactoryBot.create(:user, :unverified)

      acting_as(user).get verification_url(id: user.id, hash: Digest::SHA1.hexdigest(user.email))

      assert user.reload.has_verified_email?
      assert_redirected_to dashboard_path(verified: '1')
    end

    test 'email is not verified with invalid hash' do
      user = FactoryBot.create(:user, :unverified)

      acting_as(user).get verification_url(id: user.id, hash: Digest::SHA1.hexdigest('wrong-email'))

      assert_not user.reload.has_verified_email?
    end
  end

  private

  def verification_url(params)
    verifier = ActiveSupport::MessageVerifier.new(ENV.fetch('RAILS_MASTER_KEY', ''))

    signature = verifier.generate(verification_verify_url(params), expires_in: 60.minutes.from_now.to_i)

    verification_verify_url(params.merge(signature: signature))
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kaze-0.17.0 stubs/default/test/integration/auth/email_verification_test.rb
kaze-0.16.0 stubs/default/test/integration/auth/email_verification_test.rb
kaze-0.15.0 stubs/default/test/integration/auth/email_verification_test.rb
kaze-0.14.0 stubs/default/test/integration/auth/email_verification_test.rb
kaze-0.13.0 stubs/default/test/integration/auth/email_verification_test.rb
kaze-0.12.0 stubs/default/test/integration/auth/email_verification_test.rb
kaze-0.11.0 stubs/default/test/integration/auth/email_verification_test.rb
kaze-0.10.0 stubs/default/test/integration/auth/email_verification_test.rb
kaze-0.9.0 stubs/default/test/integration/auth/email_verification_test.rb