2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::CrossProjectAccess::ClassMethods do
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:dummy_class) do
|
|
|
|
Class.new do
|
|
|
|
extend Gitlab::CrossProjectAccess::ClassMethods
|
|
|
|
end
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:dummy_proc) { lambda { false } }
|
|
|
|
|
|
|
|
describe '#requires_cross_project_access' do
|
|
|
|
it 'creates a correct check when a hash is passed' do
|
|
|
|
expect(Gitlab::CrossProjectAccess)
|
|
|
|
.to receive(:add_check).with(dummy_class,
|
|
|
|
actions: { hello: true, world: false },
|
|
|
|
positive_condition: dummy_proc,
|
|
|
|
negative_condition: dummy_proc)
|
|
|
|
|
|
|
|
dummy_class.requires_cross_project_access(
|
|
|
|
hello: true, world: false, if: dummy_proc, unless: dummy_proc
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a correct check when an array is passed' do
|
|
|
|
expect(Gitlab::CrossProjectAccess)
|
|
|
|
.to receive(:add_check).with(dummy_class,
|
|
|
|
actions: { hello: true, world: true },
|
|
|
|
positive_condition: nil,
|
|
|
|
negative_condition: nil)
|
|
|
|
|
|
|
|
dummy_class.requires_cross_project_access(:hello, :world)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a correct check when an array and a hash is passed' do
|
|
|
|
expect(Gitlab::CrossProjectAccess)
|
|
|
|
.to receive(:add_check).with(dummy_class,
|
|
|
|
actions: { hello: true, world: true },
|
|
|
|
positive_condition: dummy_proc,
|
|
|
|
negative_condition: dummy_proc)
|
|
|
|
|
|
|
|
dummy_class.requires_cross_project_access(
|
|
|
|
:hello, :world, if: dummy_proc, unless: dummy_proc
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|