Commit 38916cff authored by Mark Chao's avatar Mark Chao

Stop syncing approvals_required once feature enabled

as it is no longer needed.
parent 3b9d4255
......@@ -47,6 +47,7 @@ module EE
# TODO remove after #1979 is closed
def sync_approval_rules(merge_request)
return if ::Feature.enabled?(:approval_rules, merge_request.target_project)
return if merge_request.merged?
return unless merge_request.previous_changes.include?(:approvals_before_merge)
......
......@@ -77,6 +77,7 @@ module EE
# TODO remove after #1979 is closed
def sync_approval_rules
return if ::Feature.enabled?(:approval_rules, project)
return unless project.previous_changes.include?(:approvals_before_merge)
project.approval_rules.update_all(approvals_required: project.approvals_before_merge)
......
......@@ -60,22 +60,49 @@ describe MergeRequests::UpdateService, :mailer do
context 'when approvals_before_merge changes' do
using RSpec::Parameterized::TableSyntax
where(:project_value, :mr_before_value, :mr_after_value, :result) do
3 | 4 | 5 | 5
3 | 4 | nil | 3
3 | nil | 5 | 5
context 'when approval_rules is disabled' do
before do
stub_feature_flags(approval_rules: false)
end
where(:project_value, :mr_before_value, :mr_after_value, :result) do
3 | 4 | 5 | 5
3 | 4 | nil | 3
3 | nil | 5 | 5
end
with_them do
let(:project) { create(:project, :repository, approvals_before_merge: project_value) }
it "updates approval_rules' approvals_required" do
merge_request.update(approvals_before_merge: mr_before_value)
rule = create(:approval_merge_request_rule, merge_request: merge_request)
update_merge_request(approvals_before_merge: mr_after_value)
expect(rule.reload.approvals_required).to eq(result)
end
end
end
with_them do
let(:project) { create(:project, :repository, approvals_before_merge: project_value) }
context 'when approval_rules is enabled' do
where(:project_value, :mr_before_value, :mr_after_value, :result) do
3 | 4 | 5 | 5
3 | 4 | nil | 3
3 | nil | 5 | 5
end
with_them do
let(:project) { create(:project, :repository, approvals_before_merge: project_value) }
it "updates approval_rules' approvals_required" do
merge_request.update(approvals_before_merge: mr_before_value)
rule = create(:approval_merge_request_rule, merge_request: merge_request)
it "does not update" do
merge_request.update(approvals_before_merge: mr_before_value)
rule = create(:approval_merge_request_rule, merge_request: merge_request)
update_merge_request(approvals_before_merge: mr_after_value)
update_merge_request(approvals_before_merge: mr_after_value)
expect(rule.reload.approvals_required).to eq(result)
expect(rule.reload.approvals_required).to eq(0)
end
end
end
end
......
......@@ -230,14 +230,26 @@ describe Projects::UpdateService, '#execute' do
end
context 'with approval_rules' do
it "updates approval_rules' approvals_required" do
stub_feature_flags(approval_rules: false)
context 'when approval_rules is disabled' do
it "updates approval_rules' approvals_required" do
stub_feature_flags(approval_rules: false)
rule = create(:approval_project_rule, project: project)
rule = create(:approval_project_rule, project: project)
update_project(project, user, approvals_before_merge: 42)
update_project(project, user, approvals_before_merge: 42)
expect(rule.reload.approvals_required).to eq(42)
expect(rule.reload.approvals_required).to eq(42)
end
end
context 'when approval_rules is enabled' do
it 'does not update' do
rule = create(:approval_project_rule, project: project)
update_project(project, user, approvals_before_merge: 42)
expect(rule.reload.approvals_required).to eq(0)
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