Commit c73ed161 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor merge_request_widget_entity.rb and fix mr specs

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 62263946
......@@ -41,28 +41,45 @@ module EE
end
end
expose_artifact(:sast, Ci::Build::SAST_FILE)
expose_artifact(:sast_container, Ci::Build::SAST_CONTAINER_FILE)
expose_artifact(:dast, Ci::Build::DAST_FILE)
expose :sast, if: -> (mr, _) { mr.expose_sast_data? } do
expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.head_sast_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.head_sast_artifact,
path: Ci::Build::SAST_FILE)
end
class_methods do
def expose_artifact(name, file)
expose name, if: -> (mr, _) { mr.send(:"expose_#{name}_data?") } do
base_artifact_method = :"base_#{name}_artifact"
head_artifact_method = :"head_#{name}_artifact"
expose :base_path, if: -> (mr, _) { mr.base_has_sast_data? && can?(current_user, :read_build, mr.base_sast_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.target_project,
merge_request.base_sast_artifact,
path: Ci::Build::SAST_FILE)
end
end
expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.send(head_artifact_method)) } do |merge_request|
expose :sast_container, if: -> (mr, _) { mr.expose_sast_container_data? } do
expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.head_sast_container_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.send(head_artifact_method),
path: file)
merge_request.head_sast_container_artifact,
path: Ci::Build::SAST_CONTAINER_FILE)
end
expose :base_path, if: -> (mr, _) { mr.send(:"base_has_#{name}_data?") && can?(current_user, :read_build, mr.send(base_artifact_method)) } do |merge_request|
expose :base_path, if: -> (mr, _) { mr.base_has_sast_container_data? && can?(current_user, :read_build, mr.base_sast_container_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.target_project,
merge_request.send(base_artifact_method),
path: file)
merge_request.base_sast_container_artifact,
path: Ci::Build::SAST_CONTAINER_FILE)
end
end
expose :dast, if: -> (mr, _) { mr.expose_dast_data? } do
expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.head_dast_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.head_dast_artifact,
path: Ci::Build::DAST_FILE)
end
expose :base_path, if: -> (mr, _) { mr.base_has_dast_data? && can?(current_user, :read_build, mr.base_dast_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.target_project,
merge_request.base_dast_artifact,
path: Ci::Build::DAST_FILE)
end
end
end
......
......@@ -164,30 +164,11 @@ describe MergeRequest do
end
end
describe '#head_sast_artifact' do
it { is_expected.to delegate_method(:sast_artifact).to(:head_pipeline).with_prefix(:head) }
end
describe '#base_sast_artifact' do
it { is_expected.to delegate_method(:sast_artifact).to(:base_pipeline).with_prefix(:base) }
end
describe '#sast_container_artifact' do
it { is_expected.to delegate_method(:sast_container_artifact).to(:head_pipeline) }
end
describe '#dast_artifact' do
it { is_expected.to delegate_method(:dast_artifact).to(:head_pipeline) }
end
describe '#base_has_sast_data?' do
it { is_expected.to delegate_method(:has_sast_data?).to(:base_pipeline).with_prefix(:base) }
end
%w(sast dast sast_container).each do |type|
method = "expose_#{type}_data?"
it { is_expected.to delegate_method(method.to_sym).to(:head_pipeline) }
it { is_expected.to delegate_method(:"expose_#{type}_data?").to(:head_pipeline) }
it { is_expected.to delegate_method(:"has_#{type}_data?").to(:base_pipeline).with_prefix(:base) }
it { is_expected.to delegate_method(:"#{type}_artifact").to(:head_pipeline).with_prefix(:head) }
it { is_expected.to delegate_method(:"#{type}_artifact").to(:base_pipeline).with_prefix(:base) }
end
describe '#expose_codeclimate_data?' do
......
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