Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
fd72c0f4
Commit
fd72c0f4
authored
Jan 09, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle presenters in BasePolicy
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
b4f67cc2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
app/policies/base_policy.rb
app/policies/base_policy.rb
+4
-0
spec/policies/base_policy_spec.rb
spec/policies/base_policy_spec.rb
+17
-0
No files found.
app/policies/base_policy.rb
View file @
fd72c0f4
...
...
@@ -53,6 +53,10 @@ class BasePolicy
def
self
.
class_for
(
subject
)
return
GlobalPolicy
if
subject
.
nil?
if
subject
.
class
.
ancestors
.
include?
(
Gitlab
::
View
::
Presenter
::
Base
)
subject
=
subject
.
subject
end
subject
.
class
.
ancestors
.
each
do
|
klass
|
next
unless
klass
.
name
...
...
spec/policies/base_policy_spec.rb
0 → 100644
View file @
fd72c0f4
require
'spec_helper'
describe
BasePolicy
,
models:
true
do
let
(
:build
)
{
create
(
:ci_build
)
}
describe
'.class_for'
do
it
'detects policy class based on the subject ancestors'
do
expect
(
described_class
.
class_for
(
build
)).
to
eq
(
Ci
::
BuildPolicy
)
end
it
'detects policy class for a presented subject'
do
presentee
=
Ci
::
Build
::
Presenter
.
new
(
build
)
expect
(
described_class
.
class_for
(
presentee
)).
to
eq
(
Ci
::
BuildPolicy
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment