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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
6f5c1e7c
Commit
6f5c1e7c
authored
May 27, 2021
by
Pedro Pombeiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow custom relations in Limitable
parent
a316a76b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
app/models/concerns/limitable.rb
app/models/concerns/limitable.rb
+2
-1
spec/models/concerns/limitable_spec.rb
spec/models/concerns/limitable_spec.rb
+24
-1
No files found.
app/models/concerns/limitable.rb
View file @
6f5c1e7c
...
...
@@ -6,6 +6,7 @@ module Limitable
included
do
class_attribute
:limit_scope
class_attribute
:limit_relation
class_attribute
:limit_name
class_attribute
:limit_feature_flag
self
.
limit_name
=
self
.
name
.
demodulize
.
tableize
...
...
@@ -28,7 +29,7 @@ module Limitable
return
unless
scope_relation
return
if
limit_feature_flag
&&
::
Feature
.
disabled?
(
limit_feature_flag
,
scope_relation
,
default_enabled: :yaml
)
relation
=
self
.
class
.
where
(
limit_scope
=>
scope_relation
)
relation
=
limit_relation
?
self
.
public_send
(
limit_relation
)
:
self
.
class
.
where
(
limit_scope
=>
scope_relation
)
# rubocop:disable GitlabSecurity/PublicSend
limits
=
scope_relation
.
actual_limits
check_plan_limit_not_exceeded
(
limits
,
relation
)
...
...
spec/models/concerns/limitable_spec.rb
View file @
6f5c1e7c
# frozen_string_literal: true
require
'spec_helper'
require
'fast_spec_helper'
require
'active_model'
RSpec
.
describe
Limitable
do
let
(
:minimal_test_class
)
do
...
...
@@ -35,6 +36,28 @@ RSpec.describe Limitable do
instance
.
valid?
(
:create
)
end
context
'with custom relation'
do
before
do
MinimalTestClass
.
limit_relation
=
:custom_relation
end
it
'triggers custom limit_relation'
do
instance
=
MinimalTestClass
.
new
def
instance
.
project
@project
||=
Object
.
new
end
limits
=
Object
.
new
custom_relation
=
Object
.
new
expect
(
instance
).
to
receive
(
:custom_relation
).
and_return
(
custom_relation
)
expect
(
instance
.
project
).
to
receive
(
:actual_limits
).
and_return
(
limits
)
expect
(
limits
).
to
receive
(
:exceeded?
).
with
(
instance
.
class
.
name
.
demodulize
.
tableize
,
custom_relation
).
and_return
(
false
)
instance
.
valid?
(
:create
)
end
end
end
context
'with global limit'
do
...
...
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