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
f53112de
Commit
f53112de
authored
Jul 18, 2019
by
Ash McKenzie
Committed by
Ash McKenzie
Jul 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New GroupMember.of_ldap_type scope
parent
d00d60a6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
14 deletions
+28
-14
app/models/members/group_member.rb
app/models/members/group_member.rb
+1
-1
spec/factories/group_members.rb
spec/factories/group_members.rb
+4
-0
spec/models/members/group_member_spec.rb
spec/models/members/group_member_spec.rb
+23
-13
No files found.
app/models/members/group_member.rb
View file @
f53112de
...
...
@@ -13,8 +13,8 @@ class GroupMember < Member
default_scope
{
where
(
source_type:
SOURCE_TYPE
)
}
scope
:of_groups
,
->
(
groups
)
{
where
(
source_id:
groups
.
select
(
:id
))
}
scope
:count_users_by_group_id
,
->
{
joins
(
:user
).
group
(
:source_id
).
count
}
scope
:of_ldap_type
,
->
{
where
(
ldap:
true
)
}
after_create
:update_two_factor_requirement
,
unless: :invite?
after_destroy
:update_two_factor_requirement
,
unless: :invite?
...
...
spec/factories/group_members.rb
View file @
f53112de
...
...
@@ -16,5 +16,9 @@ FactoryBot.define do
invite_token
'xxx'
invite_email
'email@email.com'
end
trait
(
:ldap
)
do
ldap
true
end
end
end
spec/models/members/group_member_spec.rb
View file @
f53112de
...
...
@@ -3,19 +3,29 @@
require
'spec_helper'
describe
GroupMember
do
describe
'.count_users_by_group_id'
do
it
'counts users by group ID'
do
user_1
=
create
(
:user
)
user_2
=
create
(
:user
)
group_1
=
create
(
:group
)
group_2
=
create
(
:group
)
group_1
.
add_owner
(
user_1
)
group_1
.
add_owner
(
user_2
)
group_2
.
add_owner
(
user_1
)
expect
(
described_class
.
count_users_by_group_id
).
to
eq
(
group_1
.
id
=>
2
,
group_2
.
id
=>
1
)
context
'scopes'
do
describe
'.count_users_by_group_id'
do
it
'counts users by group ID'
do
user_1
=
create
(
:user
)
user_2
=
create
(
:user
)
group_1
=
create
(
:group
)
group_2
=
create
(
:group
)
group_1
.
add_owner
(
user_1
)
group_1
.
add_owner
(
user_2
)
group_2
.
add_owner
(
user_1
)
expect
(
described_class
.
count_users_by_group_id
).
to
eq
(
group_1
.
id
=>
2
,
group_2
.
id
=>
1
)
end
end
describe
'.of_ldap_type'
do
it
'returns ldap type users'
do
group_member
=
create
(
:group_member
,
:ldap
)
expect
(
described_class
.
of_ldap_type
).
to
eq
([
group_member
])
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