Commit fd8bdf62 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'tancnle/fix-unset-all-compliance-frameworks' into 'master'

Fix unchecking all compliance frameworks on MR approvals settings

See merge request gitlab-org/gitlab!40070
parents 9572a314 7e7e3d11
......@@ -306,7 +306,7 @@ module EE
end
def compliance_frameworks=(values)
cleaned = Array.wrap(values).sort.uniq
cleaned = Array.wrap(values).reject(&:blank?).sort.uniq
write_attribute(:compliance_frameworks, cleaned)
end
......
......@@ -27,7 +27,7 @@
.form-text.text-muted.mb-2
= _('The above settings apply to all projects with the selected compliance framework(s).')
= f.collection_check_boxes(:compliance_frameworks, compliance_framework_checkboxes, :first, :last, include_hidden: false) do |b|
= f.collection_check_boxes(:compliance_frameworks, compliance_framework_checkboxes, :first, :last) do |b|
.form-check
= b.check_box(class: "form-check-input")
= b.label(class: "form-check-label")
......
---
title: Fix unchecking all compliance frameworks for MR approvals settings
merge_request: 40070
author:
type: fixed
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Admin interacts with merge requests approvals settings' do
include StubENV
let_it_be(:hippa) { ComplianceManagement::ComplianceFramework::FRAMEWORKS[:hipaa] }
let_it_be(:application_settings) { create(:application_setting, compliance_frameworks: [hippa]) }
let_it_be(:user) { create(:admin) }
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
allow(License).to receive(:feature_available?).and_return(true)
sign_in(user)
visit(admin_push_rule_path)
end
it 'updates compliance frameworks' do
page.within('.merge-request-approval-settings') do
check 'SOC 2'
click_button('Save changes')
end
visit(admin_push_rule_path)
expect(page.find_field('SOC 2')).to be_checked
end
it 'unsets all compliance frameworks' do
checkbox_selector = 'input[name="application_setting[compliance_frameworks][]"]'
page.within('.merge-request-approval-settings') do
page.all(checkbox_selector).each { |checkbox| checkbox.set(false) }
click_button('Save changes')
end
visit(admin_push_rule_path)
expect(page.all(checkbox_selector).map(&:checked?)).to all(be_falsey)
end
end
......@@ -696,5 +696,11 @@ RSpec.describe ApplicationSetting do
expect(setting.compliance_frameworks).to eq([1, 2, 3])
end
it 'sets empty values' do
setting.compliance_frameworks = [""]
expect(setting.compliance_frameworks).to eq([])
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