debian-mirror-gitlab/spec/helpers/sessions_helper_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
2.8 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe SessionsHelper do
2021-09-30 23:02:18 +05:30
describe '#recently_confirmed_com?' do
subject { helper.recently_confirmed_com? }
context 'when on .com' do
before do
2022-05-07 20:08:51 +05:30
allow(Gitlab).to receive(:com?).and_return(true)
2021-09-30 23:02:18 +05:30
end
it 'when flash notice is empty it is false' do
flash[:notice] = nil
expect(subject).to be false
end
it 'when flash notice is anything it is false' do
flash[:notice] = 'hooray!'
expect(subject).to be false
end
it 'when flash notice is devise confirmed message it is true' do
flash[:notice] = t(:confirmed, scope: [:devise, :confirmations])
expect(subject).to be true
end
end
context 'when not on .com' do
before do
2022-05-07 20:08:51 +05:30
allow(Gitlab).to receive(:com?).and_return(false)
2021-09-30 23:02:18 +05:30
end
it 'when flash notice is devise confirmed message it is false' do
flash[:notice] = t(:confirmed, scope: [:devise, :confirmations])
expect(subject).to be false
end
end
end
2019-10-12 21:52:04 +05:30
describe '#unconfirmed_email?' do
it 'returns true when the flash alert contains a devise failure unconfirmed message' do
flash[:alert] = t(:unconfirmed, scope: [:devise, :failure])
expect(helper.unconfirmed_email?).to be_truthy
end
it 'returns false when the flash alert does not contain a devise failure unconfirmed message' do
flash[:alert] = 'something else'
expect(helper.unconfirmed_email?).to be_falsey
end
end
2022-08-13 15:12:31 +05:30
describe '#send_rate_limited?' do
2023-07-09 08:55:56 +05:30
let(:user) { build_stubbed(:user) }
2022-08-13 15:12:31 +05:30
subject { helper.send_rate_limited?(user) }
before do
allow(::Gitlab::ApplicationRateLimiter)
.to receive(:peek)
.with(:email_verification_code_send, scope: user)
.and_return(rate_limited)
end
context 'when rate limited' do
let(:rate_limited) { true }
it { is_expected.to eq(true) }
end
context 'when not rate limited' do
let(:rate_limited) { false }
it { is_expected.to eq(false) }
end
end
describe '#obfuscated_email' do
2023-07-09 08:55:56 +05:30
let(:email) { 'mail@example.com' }
2022-08-13 15:12:31 +05:30
subject { helper.obfuscated_email(email) }
2023-07-09 08:55:56 +05:30
it 'delegates to Gitlab::Utils::Email.obfuscated_email' do
expect(Gitlab::Utils::Email).to receive(:obfuscated_email).with(email).and_call_original
2022-08-13 15:12:31 +05:30
2023-07-09 08:55:56 +05:30
expect(subject).to eq('ma**@e******.com')
2022-08-13 15:12:31 +05:30
end
2023-07-09 08:55:56 +05:30
end
2022-08-13 15:12:31 +05:30
2023-07-09 08:55:56 +05:30
describe '#remember_me_enabled?' do
subject { helper.remember_me_enabled? }
2022-08-13 15:12:31 +05:30
2023-07-09 08:55:56 +05:30
context 'when application setting is enabled' do
before do
stub_application_setting(remember_me_enabled: true)
end
2022-11-25 23:54:43 +05:30
2023-07-09 08:55:56 +05:30
it { is_expected.to be true }
2022-11-25 23:54:43 +05:30
end
2023-07-09 08:55:56 +05:30
context 'when application setting is disabled' do
before do
stub_application_setting(remember_me_enabled: false)
end
2022-08-13 15:12:31 +05:30
2023-07-09 08:55:56 +05:30
it { is_expected.to be false }
2022-08-13 15:12:31 +05:30
end
end
2019-10-12 21:52:04 +05:30
end