Skip to content
Snippets Groups Projects
Commit 00970606 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Extract abilities checking module from ability model

parent 24dd70d3
No related branches found
No related tags found
No related merge requests found
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.
Loading
Loading
module Gitlab
module Allowable
def can?(user, action, subject)
Ability.allowed?(user, action, subject)
end
end
end
Loading
Loading
@@ -5,7 +5,7 @@ module Gitlab
#
class Core
include Gitlab::Routing.url_helpers
include Ability::Allowable
include Gitlab::Allowable
 
attr_reader :subject, :user
 
Loading
Loading
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment