summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/database/grant_spec.rb
diff options
context:
space:
mode:
authorLuke "Jared" Bennett <lbennett@gitlab.com>2017-08-31 09:17:23 +0100
committerLuke "Jared" Bennett <lbennett@gitlab.com>2017-08-31 09:17:23 +0100
commitf884a4bbd7ccaf448e0d998711d20497cef6ac71 (patch)
tree65c9b70b58dea175d188114ce066cd17baf12888 /spec/lib/gitlab/database/grant_spec.rb
parent32a68328d719327d26e82684cdf354ed25598416 (diff)
parent3e092caa91853afeab3bb01be10869e45c39de5d (diff)
downloadgitlab-ce-repo-bugs.tar.gz
Merge remote-tracking branch 'origin/master' into repo-bugsrepo-bugs
Diffstat (limited to 'spec/lib/gitlab/database/grant_spec.rb')
-rw-r--r--spec/lib/gitlab/database/grant_spec.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database/grant_spec.rb b/spec/lib/gitlab/database/grant_spec.rb
new file mode 100644
index 00000000000..651da3e8476
--- /dev/null
+++ b/spec/lib/gitlab/database/grant_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe Gitlab::Database::Grant do
+ describe '.scope_to_current_user' do
+ it 'scopes the relation to the current user' do
+ user = Gitlab::Database.username
+ column = Gitlab::Database.postgresql? ? :grantee : :User
+ names = described_class.scope_to_current_user.pluck(column).uniq
+
+ expect(names).to eq([user])
+ end
+ end
+
+ describe '.create_and_execute_trigger' do
+ it 'returns true when the user can create and execute a trigger' do
+ # We assume the DB/user is set up correctly so that triggers can be
+ # created, which is necessary anyway for other tests to work.
+ expect(described_class.create_and_execute_trigger?('users')).to eq(true)
+ end
+
+ it 'returns false when the user can not create and/or execute a trigger' do
+ allow(described_class).to receive(:scope_to_current_user)
+ .and_return(described_class.none)
+
+ result = described_class.create_and_execute_trigger?('kittens')
+
+ expect(result).to eq(false)
+ end
+ end
+end