diff options
Diffstat (limited to 'spec/services/users/email_verification/generate_token_service_spec.rb')
-rw-r--r-- | spec/services/users/email_verification/generate_token_service_spec.rb | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/spec/services/users/email_verification/generate_token_service_spec.rb b/spec/services/users/email_verification/generate_token_service_spec.rb index e7aa1bf8306..8b2b57cbf62 100644 --- a/spec/services/users/email_verification/generate_token_service_spec.rb +++ b/spec/services/users/email_verification/generate_token_service_spec.rb @@ -2,12 +2,13 @@ require 'spec_helper' -RSpec.describe Users::EmailVerification::GenerateTokenService do +RSpec.describe Users::EmailVerification::GenerateTokenService, feature_category: :system_access do using RSpec::Parameterized::TableSyntax - let(:service) { described_class.new(attr: attr) } + let(:user) { build_stubbed(:user) } + let(:service) { described_class.new(attr: attr, user: user) } let(:token) { 'token' } - let(:digest) { Devise.token_generator.digest(User, attr, token) } + let(:digest) { service.send(:digest) } describe '#execute' do context 'with a valid attribute' do @@ -33,5 +34,21 @@ RSpec.describe Users::EmailVerification::GenerateTokenService do expect { service.execute }.to raise_error(ArgumentError, 'Invalid attribute') end end + + context 'when similar tokens are generated' do + let(:attr) { :confirmation_token } + + before do + allow_next_instance_of(described_class) do |service| + allow(service).to receive(:generate_token).and_return(token) + end + end + + it 'generates a unique digest' do + second_service = described_class.new(attr: attr, user: build_stubbed(:user)) + + expect(service.execute[1]).not_to eq(second_service.execute[1]) + end + end end end |