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
5c0b3a27
Commit
5c0b3a27
authored
Dec 24, 2019
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add with_hosted_plan scope to filter by plan
Refactor spec to cache created plan records
parent
94974e2c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
12 deletions
+28
-12
ee/app/models/gitlab_subscription.rb
ee/app/models/gitlab_subscription.rb
+5
-1
ee/spec/models/gitlab_subscription_spec.rb
ee/spec/models/gitlab_subscription_spec.rb
+23
-11
No files found.
ee/app/models/gitlab_subscription.rb
View file @
5c0b3a27
...
...
@@ -13,8 +13,12 @@ class GitlabSubscription < ApplicationRecord
delegate
:name
,
:title
,
to: :hosted_plan
,
prefix: :plan
,
allow_nil:
true
scope
:with_hosted_plan
,
->
(
plan_name
)
do
joins
(
:hosted_plan
).
where
(
trial:
false
,
'plans.name'
=>
plan_name
)
end
scope
:with_a_paid_hosted_plan
,
->
do
joins
(
:hosted_plan
).
where
(
trial:
false
,
'plans.name'
=>
Plan
::
PAID_HOSTED_PLANS
)
with_hosted_plan
(
Plan
::
PAID_HOSTED_PLANS
)
end
def
seats_in_use
...
...
ee/spec/models/gitlab_subscription_spec.rb
View file @
5c0b3a27
...
...
@@ -3,6 +3,10 @@
require
'spec_helper'
describe
GitlabSubscription
do
%i[free_plan bronze_plan silver_plan gold_plan early_adopter_plan]
.
each
do
|
plan
|
let_it_be
(
plan
)
{
create
(
plan
)
}
end
describe
'default values'
do
it
do
Timecop
.
freeze
(
Date
.
today
+
30
)
do
...
...
@@ -26,6 +30,23 @@ describe GitlabSubscription do
it
{
is_expected
.
to
belong_to
(
:hosted_plan
)
}
end
describe
'scopes'
do
describe
'.with_hosted_plan'
do
let!
(
:gold_subscription
)
{
create
(
:gitlab_subscription
,
hosted_plan:
gold_plan
)
}
let!
(
:silver_subscription
)
{
create
(
:gitlab_subscription
,
hosted_plan:
silver_plan
)
}
let!
(
:early_adopter_subscription
)
{
create
(
:gitlab_subscription
,
hosted_plan:
early_adopter_plan
)
}
let!
(
:trial_subscription
)
{
create
(
:gitlab_subscription
,
hosted_plan:
gold_plan
,
trial:
true
)
}
it
'scopes to the plan'
do
expect
(
described_class
.
with_hosted_plan
(
'gold'
)).
to
contain_exactly
(
gold_subscription
)
expect
(
described_class
.
with_hosted_plan
(
'silver'
)).
to
contain_exactly
(
silver_subscription
)
expect
(
described_class
.
with_hosted_plan
(
'early_adopter'
)).
to
contain_exactly
(
early_adopter_subscription
)
expect
(
described_class
.
with_hosted_plan
(
'bronze'
)).
to
be_empty
end
end
end
describe
'#seats_in_use'
do
let!
(
:user_1
)
{
create
(
:user
)
}
let!
(
:user_2
)
{
create
(
:user
)
}
...
...
@@ -38,12 +59,6 @@ describe GitlabSubscription do
let!
(
:subgroup_2
)
{
create
(
:group
,
parent:
group
)
}
let!
(
:gitlab_subscription
)
{
create
(
:gitlab_subscription
,
namespace:
group
)
}
before
do
%i[free_plan bronze_plan silver_plan gold_plan]
.
each
do
|
plan
|
create
(
plan
)
end
end
it
'returns count of members'
do
group
.
add_developer
(
user_1
)
...
...
@@ -116,8 +131,6 @@ describe GitlabSubscription do
end
describe
'#seats_owed'
do
let!
(
:bronze_plan
)
{
create
(
:bronze_plan
)
}
let!
(
:early_adopter_plan
)
{
create
(
:early_adopter_plan
)
}
let!
(
:gitlab_subscription
)
{
create
(
:gitlab_subscription
,
subscription_attrs
)
}
before
do
...
...
@@ -262,8 +275,7 @@ describe GitlabSubscription do
context
'after_destroy_commit'
do
it
'logs previous state to gitlab subscription history'
do
group
=
create
(
:group
)
plan
=
create
(
:bronze_plan
)
subject
.
update!
max_seats_used:
37
,
seats:
11
,
namespace:
group
,
hosted_plan:
plan
subject
.
update!
max_seats_used:
37
,
seats:
11
,
namespace:
group
,
hosted_plan:
bronze_plan
db_created_at
=
described_class
.
last
.
created_at
subject
.
destroy!
...
...
@@ -275,7 +287,7 @@ describe GitlabSubscription do
'max_seats_used'
=>
37
,
'seats'
=>
11
,
'namespace_id'
=>
group
.
id
,
'hosted_plan_id'
=>
plan
.
id
,
'hosted_plan_id'
=>
bronze_
plan
.
id
,
'gitlab_subscription_created_at'
=>
db_created_at
)
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