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
39a9fe28
Commit
39a9fe28
authored
May 10, 2021
by
peterhegman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move specs for private methods into specs for public methods
Per reviewer feedback
parent
443fb94f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
58 deletions
+38
-58
spec/helpers/groups/group_members_helper_spec.rb
spec/helpers/groups/group_members_helper_spec.rb
+30
-44
spec/helpers/projects/project_members_helper_spec.rb
spec/helpers/projects/project_members_helper_spec.rb
+8
-14
No files found.
spec/helpers/groups/group_members_helper_spec.rb
View file @
39a9fe28
...
...
@@ -23,76 +23,59 @@ RSpec.describe Groups::GroupMembersHelper do
end
end
describe
'#group_
group_links_serialized
'
do
include_context
'group_group_link'
describe
'#group_
members_list_data_json
'
do
let
(
:group_members
)
{
create_list
(
:group_member
,
2
,
group:
group
,
created_by:
current_user
)
}
it
'matches json schema'
do
json
=
helper
.
send
(
:group_group_links_serialized
,
shared_group
.
shared_with_group_links
).
to_json
let
(
:pagination
)
{
{}
}
let
(
:collection
)
{
group_members
}
let
(
:presented_members
)
{
present_members
(
collection
)
}
expect
(
json
).
to
match_schema
(
'group_link/group_group_links'
)
end
end
subject
{
Gitlab
::
Json
.
parse
(
helper
.
group_members_list_data_json
(
group
,
presented_members
,
pagination
))
}
describe
'#group_members_serialized'
do
shared_examples
'members.json'
do
it
'matches json schema'
do
json
=
helper
.
send
(
:group_members_serialized
,
group
,
present_members
([
group_member
])).
to_json
expect
(
json
).
to
match_schema
(
'members'
)
it
'returns `members` property that matches json schema'
do
expect
(
subject
[
'members'
].
to_json
).
to
match_schema
(
'members'
)
end
end
context
'for a group member'
do
let
(
:group_member
)
{
create
(
:group_member
,
group:
group
,
created_by:
current_user
)
}
before
do
allow
(
helper
).
to
receive
(
:group_group_member_path
).
with
(
group
,
':id'
).
and_return
(
'/groups/foo-bar/-/group_members/:id'
)
allow
(
helper
).
to
receive
(
:can?
).
with
(
current_user
,
:admin_group_member
,
group
).
and_return
(
true
)
end
it
'returns expected json'
do
expected
=
{
member_path:
'/groups/foo-bar/-/group_members/:id'
,
source_id:
group
.
id
,
can_manage_members:
true
}.
as_json
expect
(
subject
).
to
include
(
expected
)
end
context
'for a group member'
do
it_behaves_like
'members.json'
context
'with user status set'
do
let
(
:user
)
{
create
(
:user
)
}
let!
(
:status
)
{
create
(
:user_status
,
user:
user
)
}
let
(
:group_member
)
{
create
(
:group_member
,
group:
group
,
user:
user
,
created_by:
current_user
)
}
let
(
:group_member
s
)
{
[
create
(
:group_member
,
group:
group
,
user:
user
,
created_by:
current_user
)]
}
it_behaves_like
'members.json'
end
end
context
'for an invited group member'
do
let
(
:group_member
)
{
create
(
:group_member
,
:invited
,
group:
group
,
created_by:
current_user
)
}
let
(
:group_member
s
)
{
create_list
(
:group_member
,
2
,
:invited
,
group:
group
,
created_by:
current_user
)
}
it_behaves_like
'members.json'
end
context
'for an access request'
do
let
(
:group_member
)
{
create
(
:group_member
,
:access_request
,
group:
group
,
created_by:
current_user
)
}
let
(
:group_member
s
)
{
create_list
(
:group_member
,
2
,
:access_request
,
group:
group
,
created_by:
current_user
)
}
it_behaves_like
'members.json'
end
end
describe
'#group_members_list_data_json'
do
let_it_be
(
:group_members
)
{
create_list
(
:group_member
,
2
,
group:
group
,
created_by:
current_user
)
}
let
(
:pagination
)
{
{}
}
let
(
:collection
)
{
group_members
}
let
(
:presented_members
)
{
present_members
(
collection
)
}
subject
{
Gitlab
::
Json
.
parse
(
helper
.
group_members_list_data_json
(
group
,
presented_members
,
pagination
))
}
before
do
allow
(
helper
).
to
receive
(
:group_group_member_path
).
with
(
group
,
':id'
).
and_return
(
'/groups/foo-bar/-/group_members/:id'
)
allow
(
helper
).
to
receive
(
:can?
).
with
(
current_user
,
:admin_group_member
,
group
).
and_return
(
true
)
end
it
'returns expected json'
do
expected
=
{
members:
helper
.
send
(
:group_members_serialized
,
group
,
presented_members
),
member_path:
'/groups/foo-bar/-/group_members/:id'
,
source_id:
group
.
id
,
can_manage_members:
true
}.
as_json
expect
(
subject
).
to
include
(
expected
)
end
context
'when pagination is not available'
do
it
'sets `pagination` attribute to expected json'
do
...
...
@@ -144,12 +127,15 @@ RSpec.describe Groups::GroupMembersHelper do
param_name:
nil
,
params:
{}
},
members:
helper
.
send
(
:group_group_links_serialized
,
shared_group
.
shared_with_group_links
),
member_path:
'/groups/foo-bar/-/group_links/:id'
,
source_id:
shared_group
.
id
}.
as_json
expect
(
subject
).
to
include
(
expected
)
end
it
'returns `members` property that matches json schema'
do
expect
(
subject
[
'members'
].
to_json
).
to
match_schema
(
'group_link/group_group_links'
)
end
end
end
spec/helpers/projects/project_members_helper_spec.rb
View file @
39a9fe28
...
...
@@ -152,12 +152,6 @@ RSpec.describe Projects::ProjectMembersHelper do
let
(
:collection
)
{
project_members
}
let
(
:presented_members
)
{
present_members
(
collection
)
}
describe
'#project_members_serialized'
do
it
'matches json schema'
do
expect
(
helper
.
send
(
:project_members_serialized
,
project
,
presented_members
).
to_json
).
to
match_schema
(
'members'
)
end
end
describe
'#project_members_list_data_json'
do
let
(
:allow_admin_project
)
{
true
}
let
(
:pagination
)
{
{}
}
...
...
@@ -170,7 +164,6 @@ RSpec.describe Projects::ProjectMembersHelper do
it
'returns expected json'
do
expected
=
{
members:
helper
.
send
(
:project_members_serialized
,
project
,
presented_members
),
member_path:
'/foo-bar/-/project_members/:id'
,
source_id:
project
.
id
,
can_manage_members:
true
...
...
@@ -179,6 +172,10 @@ RSpec.describe Projects::ProjectMembersHelper do
expect
(
subject
).
to
include
(
expected
)
end
it
'returns `members` property that matches json schema'
do
expect
(
subject
[
'members'
].
to_json
).
to
match_schema
(
'members'
)
end
context
'when pagination is not available'
do
it
'sets `pagination` attribute to expected json'
do
expected
=
{
...
...
@@ -217,12 +214,6 @@ RSpec.describe Projects::ProjectMembersHelper do
let
(
:allow_admin_project
)
{
true
}
describe
'#project_group_links_data_json'
do
it
'matches json schema'
do
expect
(
helper
.
send
(
:project_group_links_serialized
,
project_group_links
).
to_json
).
to
match_schema
(
'group_link/project_group_links'
)
end
end
describe
'#project_group_links_list_data_json'
do
subject
{
Gitlab
::
Json
.
parse
(
helper
.
project_group_links_list_data_json
(
project
,
project_group_links
))
}
...
...
@@ -233,7 +224,6 @@ RSpec.describe Projects::ProjectMembersHelper do
it
'returns expected json'
do
expected
=
{
members:
helper
.
send
(
:project_group_links_serialized
,
project_group_links
),
pagination:
{
current_page:
nil
,
per_page:
nil
,
...
...
@@ -248,6 +238,10 @@ RSpec.describe Projects::ProjectMembersHelper do
expect
(
subject
).
to
include
(
expected
)
end
it
'returns `members` property that matches json schema'
do
expect
(
subject
[
'members'
].
to_json
).
to
match_schema
(
'group_link/project_group_links'
)
end
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