Commit 542bb6da authored by charlie ablett's avatar charlie ablett

Merge branch 'kerrizor/extract-delgated-predicate-methods' into 'master'

Replace delegated predicate methods with boolean-returning methods

See merge request gitlab-org/gitlab!56420
parents 30148d63 b3cf3d5a
......@@ -197,10 +197,6 @@ module EE
delegate :ci_minutes_quota, to: :shared_runners_limit_namespace
delegate :last_update_succeeded?, :last_update_failed?,
:ever_updated_successfully?, :hard_failed?,
to: :import_state, prefix: :mirror, allow_nil: true
delegate :merge_pipelines_enabled, :merge_pipelines_enabled=, :merge_pipelines_enabled?, :merge_pipelines_were_disabled?, to: :ci_cd_settings
delegate :merge_trains_enabled, :merge_trains_enabled=, :merge_trains_enabled?, to: :ci_cd_settings
......@@ -256,6 +252,22 @@ module EE
end
end
def mirror_last_update_succeeded?
!!import_state&.last_update_succeeded?
end
def mirror_last_update_failed?
!!import_state&.last_update_failed?
end
def mirror_ever_updated_successfully?
!!import_state&.ever_updated_successfully?
end
def mirror_hard_failed?
!!import_state&.hard_failed?
end
class_methods do
extend ::Gitlab::Utils::Override
......
......@@ -125,6 +125,46 @@ RSpec.describe Project do
end
end
context 'import_state dependant predicate method' do
shared_examples 'returns expected values' do
context 'when project lacks a import_state relation' do
it 'returns false' do
expect(project.send("mirror_#{method}")).to be_falsey
end
end
context 'when project has a import_state relation' do
before do
create(:import_state, project: project)
end
it 'accesses the value from the import_state' do
expect(project.import_state).to receive(method)
project.send("mirror_#{method}")
end
end
end
describe '#mirror_last_update_succeeded?' do
it_behaves_like 'returns expected values' do
let(:method) { "last_update_succeeded?" }
end
end
describe '#mirror_last_update_failed?' do
it_behaves_like 'returns expected values' do
let(:method) { "last_update_failed?" }
end
end
describe '#mirror_ever_updated_successfully?' do
it_behaves_like 'returns expected values' do
let(:method) { "ever_updated_successfully?" }
end
end
end
describe 'approval_rules association' do
let_it_be(:rule, reload: true) { create(:approval_project_rule) }
let(:project) { rule.project }
......
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