Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorJames Lopez <james@gitlab.com>2019-02-15 11:47:10 +0300
committerJames Lopez <james@gitlab.com>2019-02-15 11:47:10 +0300
commit0328d4faeec093db7744ae5a018174ea4f558a42 (patch)
tree6d325974f2c6ef94a0bc783f8064a84a71c66bef /spec/lib
parentb95cf314eddf18cd50ad02fb944909ed31c87881 (diff)
parentf80f6bbcdc7f18d9154604602f3750abb0292020 (diff)
Merge branch '56485-implement-graphql-mergerequestsresolver' into 'master'
Resolve "Implement GraphQL MergeRequestsResolver" Closes #56485 See merge request gitlab-org/gitlab-ce!24805
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/graphql/authorize/instrumentation_spec.rb67
1 files changed, 67 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..cf3a8bcc8b4
--- /dev/null
+++ b/spec/lib/gitlab/graphql/authorize/instrumentation_spec.rb
@@ -0,0 +1,67 @@
+# 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, passed: true)
+ 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, passed: true)
+ end
+ end
+
+ expect(checker.call(objects)).to eq(objects)
+ end
+
+ context 'when some objects would not pass the check' do
+ it 'returns nil when it is single object' do
+ disallowed = double(:object)
+
+ spy_ability_check_for(abilities.first, disallowed, passed: false)
+
+ expect(checker.call(disallowed)).to be_nil
+ end
+
+ it 'returns only objects which passed when there are more than one' do
+ allowed = double(:allowed)
+ disallowed = double(:disallowed)
+
+ spy_ability_check_for(abilities.first, disallowed, passed: false)
+
+ abilities.each do |ability|
+ spy_ability_check_for(ability, allowed, passed: true)
+ end
+
+ expect(checker.call([disallowed, allowed]))
+ .to contain_exactly(allowed)
+ end
+ end
+
+ def spy_ability_check_for(ability, object, passed: true)
+ expect(Ability)
+ .to receive(:allowed?)
+ .with(current_user, ability, object)
+ .and_return(passed)
+ end
+ end
+end