diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2019-02-12 18:30:23 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2019-02-14 10:52:17 +0300 |
commit | 564b86a3145cd5f7eae8071ef244dc684bcd5031 (patch) | |
tree | 15c4a5db6bf9f9ed8018b4c6f989a8095616c1eb /spec/lib/gitlab/graphql/authorize | |
parent | 7be1f0842f281305f2c36e2b6066842d8e87875c (diff) |
Allow authorize on array of objects for GraphQL
And add tests
Diffstat (limited to 'spec/lib/gitlab/graphql/authorize')
-rw-r--r-- | spec/lib/gitlab/graphql/authorize/instrumentation_spec.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/lib/gitlab/graphql/authorize/instrumentation_spec.rb b/spec/lib/gitlab/graphql/authorize/instrumentation_spec.rb new file mode 100644 index 00000000000..69f53fce715 --- /dev/null +++ b/spec/lib/gitlab/graphql/authorize/instrumentation_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Graphql::Authorize::Instrumentation do + describe '#build_checker' do + let(:current_user) { double(:current_user) } + let(:abilities) { [double(:first_ability), double(:last_ability)] } + + let(:checker) do + described_class.new.__send__(:build_checker, current_user, abilities) + end + + it 'returns a checker which checks for a single object' do + object = double(:object) + + abilities.each do |ability| + spy_ability_check_for(ability, object) + end + + expect(checker.call(object)).to eq(object) + end + + it 'returns a checker which checks for all objects' do + objects = [double(:first), double(:last)] + + abilities.each do |ability| + objects.each do |object| + spy_ability_check_for(ability, object) + end + end + + expect(checker.call(objects)).to eq(objects) + end + + def spy_ability_check_for(ability, object) + expect(Ability) + .to receive(:allowed?) + .with(current_user, ability, object) + .and_return(true) + end + end +end |