Commit 00970606 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Extract abilities checking module from ability model

parent 24dd70d3
class Ability class Ability
module Allowable
def can?(user, action, subject)
Ability.allowed?(user, action, subject)
end
end
class << self class << self
# Given a list of users and a project this method returns the users that can # Given a list of users and a project this method returns the users that can
# read the given project. # read the given project.
......
module Gitlab
module Allowable
def can?(user, action, subject)
Ability.allowed?(user, action, subject)
end
end
end
...@@ -5,7 +5,7 @@ module Gitlab ...@@ -5,7 +5,7 @@ module Gitlab
# #
class Core class Core
include Gitlab::Routing.url_helpers include Gitlab::Routing.url_helpers
include Ability::Allowable include Gitlab::Allowable
attr_reader :subject, :user attr_reader :subject, :user
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment