summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/ability.rb6
-rw-r--r--lib/gitlab/allowable.rb8
-rw-r--r--lib/gitlab/ci/status/core.rb2
-rw-r--r--spec/lib/gitlab/allowable_spec.rb27
4 files changed, 36 insertions, 7 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb
index ce461caf686..fa8f8bc3a5f 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -1,10 +1,4 @@
class Ability
- module Allowable
- def can?(user, action, subject)
- Ability.allowed?(user, action, subject)
- end
- end
-
class << self
# Given a list of users and a project this method returns the users that can
# read the given project.
diff --git a/lib/gitlab/allowable.rb b/lib/gitlab/allowable.rb
new file mode 100644
index 00000000000..3cc218f9db4
--- /dev/null
+++ b/lib/gitlab/allowable.rb
@@ -0,0 +1,8 @@
+module Gitlab
+ module Allowable
+ def can?(user, action, subject)
+ Ability.allowed?(user, action, subject)
+ end
+ end
+end
+
diff --git a/lib/gitlab/ci/status/core.rb b/lib/gitlab/ci/status/core.rb
index dd3a824e486..12c0ca1d6d5 100644
--- a/lib/gitlab/ci/status/core.rb
+++ b/lib/gitlab/ci/status/core.rb
@@ -5,7 +5,7 @@ module Gitlab
#
class Core
include Gitlab::Routing.url_helpers
- include Ability::Allowable
+ include Gitlab::Allowable
attr_reader :subject, :user
diff --git a/spec/lib/gitlab/allowable_spec.rb b/spec/lib/gitlab/allowable_spec.rb
new file mode 100644
index 00000000000..87733d53e92
--- /dev/null
+++ b/spec/lib/gitlab/allowable_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe Gitlab::Allowable do
+ subject do
+ Class.new.include(described_class).new
+ end
+
+ describe '#can?' do
+ let(:user) { create(:user) }
+
+ context 'when user is allowed to do something' do
+ let(:project) { create(:empty_project, :public) }
+
+ it 'reports correct ability to perform action' do
+ expect(subject.can?(user, :read_project, project)).to be true
+ end
+ end
+
+ context 'when user is not allowed to do something' do
+ let(:project) { create(:empty_project, :private) }
+
+ it 'reports correct ability to perform action' do
+ expect(subject.can?(user, :read_project, project)).to be false
+ end
+ end
+ end
+end