2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::GonHelper do
|
2018-12-13 13:39:08 +05:30
|
|
|
let(:helper) do
|
|
|
|
Class.new do
|
|
|
|
include Gitlab::GonHelper
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
def current_user
|
|
|
|
nil
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end.new
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
describe '#add_gon_variables' do
|
|
|
|
let(:gon) { double('gon').as_null_object }
|
|
|
|
let(:https) { true }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:gon).and_return(gon)
|
|
|
|
stub_config_setting(https: https)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when HTTPS is enabled' do
|
|
|
|
it 'sets the secure flag to true' do
|
|
|
|
expect(gon).to receive(:secure=).with(true)
|
|
|
|
|
|
|
|
helper.add_gon_variables
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when HTTP is enabled' do
|
|
|
|
let(:https) { false }
|
|
|
|
|
|
|
|
it 'sets the secure flag to false' do
|
|
|
|
expect(gon).to receive(:secure=).with(false)
|
|
|
|
|
|
|
|
helper.add_gon_variables
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe '#push_frontend_feature_flag' do
|
2021-01-03 14:25:43 +05:30
|
|
|
before do
|
|
|
|
skip_feature_flags_yaml_validation
|
2022-07-16 23:28:13 +05:30
|
|
|
skip_default_enabled_yaml_check
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it 'pushes a feature flag to the frontend' do
|
2022-01-26 12:08:38 +05:30
|
|
|
gon = class_double('Gon')
|
2020-06-23 00:09:42 +05:30
|
|
|
thing = stub_feature_flag_gate('thing')
|
|
|
|
|
|
|
|
stub_feature_flags(my_feature_flag: thing)
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
allow(helper)
|
|
|
|
.to receive(:gon)
|
|
|
|
.and_return(gon)
|
|
|
|
|
|
|
|
expect(gon)
|
|
|
|
.to receive(:push)
|
|
|
|
.with({ features: { 'myFeatureFlag' => true } }, true)
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
helper.push_frontend_feature_flag(:my_feature_flag, thing)
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
describe '#push_force_frontend_feature_flag' do
|
|
|
|
let(:gon) { class_double('Gon') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
skip_feature_flags_yaml_validation
|
|
|
|
|
|
|
|
allow(helper)
|
|
|
|
.to receive(:gon)
|
|
|
|
.and_return(gon)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'pushes a feature flag to the frontend with the provided value' do
|
|
|
|
expect(gon)
|
|
|
|
.to receive(:push)
|
|
|
|
.with({ features: { 'myFeatureFlag' => true } }, true)
|
|
|
|
|
|
|
|
helper.push_force_frontend_feature_flag(:my_feature_flag, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'pushes a disabled feature flag if provided value is nil' do
|
|
|
|
expect(gon)
|
|
|
|
.to receive(:push)
|
|
|
|
.with({ features: { 'myFeatureFlag' => false } }, true)
|
|
|
|
|
|
|
|
helper.push_force_frontend_feature_flag(:my_feature_flag, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
describe '#default_avatar_url' do
|
|
|
|
it 'returns an absolute URL' do
|
|
|
|
url = helper.default_avatar_url
|
|
|
|
|
|
|
|
expect(url).to match(/^http/)
|
|
|
|
expect(url).to match(/no_avatar.*png$/)
|
|
|
|
end
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|