Commit faac2f85 authored by Stan Hu's avatar Stan Hu

Merge branch '292798-rework-project-security-settings-tests' into 'master'

Rework ProjectSecuritySetting with test table

See merge request gitlab-org/gitlab!50447
parents e495f2d8 1b52f3b6
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ProjectSecuritySetting do RSpec.describe ProjectSecuritySetting do
using RSpec::Parameterized::TableSyntax
describe 'associations' do describe 'associations' do
subject { create(:project).security_setting } subject { create(:project).security_setting }
...@@ -12,55 +14,29 @@ RSpec.describe ProjectSecuritySetting do ...@@ -12,55 +14,29 @@ RSpec.describe ProjectSecuritySetting do
describe '#auto_fix_enabled?' do describe '#auto_fix_enabled?' do
subject { setting.auto_fix_enabled? } subject { setting.auto_fix_enabled? }
let_it_be(:setting) { build(:project_security_setting) } let(:setting) { build(:project_security_setting) }
context 'when licensed feature is enabled' do where(:license, :feature_flag, :auto_fix_container_scanning, :auto_fix_dependency_scanning, :auto_fix_sast, :auto_fix_enabled?) do
before do true | true | true | true | true | true
stub_licensed_features(vulnerability_auto_fix: true) false | true | true | true | true | false
true | false | true | true | true | false
true | true | false | true | true | true
true | true | true | false | true | true
true | true | false | false | true | false
true | true | true | true | false | true
end end
context 'when auto fix is enabled for available feature' do with_them do
before do before do
setting.auto_fix_container_scanning = false stub_licensed_features(vulnerability_auto_fix: license)
setting.auto_fix_dependency_scanning = true stub_feature_flags(security_auto_fix: feature_flag)
end
it 'marks auto_fix as enabled' do setting.auto_fix_container_scanning = auto_fix_container_scanning
is_expected.to be_truthy setting.auto_fix_dependency_scanning = auto_fix_dependency_scanning
end setting.auto_fix_sast = auto_fix_sast
end end
context 'when a auto_fix setting is disabled for available features' do it { is_expected.to eq(auto_fix_enabled?) }
before do
setting.auto_fix_container_scanning = false
setting.auto_fix_dependency_scanning = false
setting.auto_fix_sast = false
end
it 'marks auto_fix as disabled' do
is_expected.to be_falsey
end
end
context 'when feature is disabled' do
before do
stub_feature_flags(security_auto_fix: false)
end
it 'marks auto_fix as disabled' do
is_expected.to be_falsey
end
end
end
context 'when license feature is disabled' do
before do
stub_licensed_features(vulnerability_auto_fix: false)
end
it 'marks auto_fix as disabled' do
is_expected.to be_falsey
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment