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
fe8aa11a
Commit
fe8aa11a
authored
Feb 01, 2019
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for Approvable feature switch
Specs are based from existing approvable spec.
parent
d8018047
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
248 additions
and
0 deletions
+248
-0
ee/spec/models/approvable_for_rule_spec.rb
ee/spec/models/approvable_for_rule_spec.rb
+129
-0
ee/spec/models/visible_approvable_for_rule_spec.rb
ee/spec/models/visible_approvable_for_rule_spec.rb
+119
-0
No files found.
ee/spec/models/approvable_for_rule_spec.rb
0 → 100644
View file @
fe8aa11a
# frozen_string_literal: true
require
'spec_helper'
# Based on approvable_spec.rb
describe
ApprovableForRule
do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:project
)
{
merge_request
.
project
}
let
(
:author
)
{
merge_request
.
author
}
describe
'#approvers_overwritten?'
do
subject
{
merge_request
.
approvers_overwritten?
}
it
'returns false when merge request has no approvers'
do
is_expected
.
to
be
false
end
it
'returns true when merge request has user approver'
do
create
(
:approver
,
target:
merge_request
)
is_expected
.
to
be
true
end
it
'returns true when merge request has group approver'
do
group
=
create
(
:group_with_members
)
create
(
:approver_group
,
target:
merge_request
,
group:
group
)
is_expected
.
to
be
true
end
end
describe
'#can_approve?'
do
subject
{
merge_request
.
can_approve?
(
user
)
}
it
'returns false if user is nil'
do
expect
(
merge_request
.
can_approve?
(
nil
)).
to
be
false
end
it
'returns true when user is included in the approvers list'
do
user
=
create
(
:approver
,
target:
merge_request
).
user
expect
(
merge_request
.
can_approve?
(
user
)).
to
be
true
end
context
'when authors can approve'
do
before
do
project
.
update
(
merge_requests_author_approval:
true
)
end
context
'when the user is the author'
do
it
'returns true when user is approver'
do
create
(
:approver
,
target:
merge_request
,
user:
author
)
expect
(
merge_request
.
can_approve?
(
author
)).
to
be
true
end
it
'returns false when user is not approver'
do
expect
(
merge_request
.
can_approve?
(
author
)).
to
be
false
end
end
context
'when user is committer'
do
let
(
:user
)
{
create
(
:user
,
email:
merge_request
.
commits
.
first
.
committer_email
)
}
before
do
project
.
add_developer
(
user
)
end
it
'returns true when user is approver'
do
create
(
:approver
,
target:
merge_request
,
user:
user
)
expect
(
merge_request
.
can_approve?
(
user
)).
to
be
true
end
it
'returns false when user is not approver'
do
expect
(
merge_request
.
can_approve?
(
user
)).
to
be
false
end
end
end
context
'when authors cannot approve'
do
before
do
project
.
update
(
merge_requests_author_approval:
false
)
end
it
'returns false when user is the author'
do
create
(
:approver
,
target:
merge_request
,
user:
author
)
expect
(
merge_request
.
can_approve?
(
author
)).
to
be
false
end
it
'returns false when user is a committer'
do
user
=
create
(
:user
,
email:
merge_request
.
commits
.
first
.
committer_email
)
project
.
add_developer
(
user
)
create
(
:approver
,
target:
merge_request
,
user:
user
)
expect
(
merge_request
.
can_approve?
(
user
)).
to
be
false
end
end
it
'returns false when user is unable to update the merge request'
do
user
=
create
(
:user
)
project
.
add_guest
(
user
)
expect
(
merge_request
.
can_approve?
(
user
)).
to
be
false
end
context
'when approvals are required'
do
before
do
project
.
update
(
approvals_before_merge:
1
)
end
it
'returns true when approvals are still accepted and user still has not approved'
do
user
=
create
(
:user
)
project
.
add_developer
(
user
)
expect
(
merge_request
.
can_approve?
(
user
)).
to
be
true
end
it
'returns false when there is still one approver missing'
do
user
=
create
(
:user
)
project
.
add_developer
(
user
)
create
(
:approver
,
target:
merge_request
)
expect
(
merge_request
.
can_approve?
(
user
)).
to
be
false
end
end
end
end
ee/spec/models/visible_approvable_for_rule_spec.rb
0 → 100644
View file @
fe8aa11a
# frozen_string_literal: true
require
'spec_helper'
# Based on visible_approvable_spec.rb
describe
VisibleApprovableForRule
do
let
(
:resource
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let!
(
:project
)
{
create
(
:project
,
:repository
)
}
let!
(
:user
)
{
project
.
creator
}
describe
'#approvers_left'
do
let!
(
:private_group
)
{
create
(
:group_with_members
,
:private
)
}
let!
(
:public_group
)
{
create
(
:group_with_members
)
}
let!
(
:public_approver_group
)
{
create
(
:approver_group
,
target:
resource
,
group:
public_group
)
}
let!
(
:private_approver_group
)
{
create
(
:approver_group
,
target:
resource
,
group:
private_group
)
}
let!
(
:approver
)
{
create
(
:approver
,
target:
resource
)
}
subject
{
resource
.
approvers_left
}
it
'avoids N+1 queries'
do
control
=
ActiveRecord
::
QueryRecorder
.
new
{
subject
}
expect
{
subject
}.
not_to
exceed_query_limit
(
control
)
end
it
'returns all approvers left'
do
resource
.
approvals
.
create!
(
user:
approver
.
user
)
is_expected
.
to
match_array
(
public_approver_group
.
users
+
private_approver_group
.
users
)
end
end
describe
'#overall_approvers'
do
let
(
:approver
)
{
create
(
:user
)
}
let
(
:code_owner
)
{
build
(
:user
)
}
let!
(
:project_regular_rule
)
{
create
(
:approval_project_rule
,
project:
project
,
users:
[
approver
])
}
let!
(
:code_owner_rule
)
{
create
(
:approval_merge_request_rule
,
merge_request:
resource
,
users:
[
code_owner
],
code_owner:
true
)
}
before
do
project
.
add_developer
(
approver
)
project
.
add_developer
(
code_owner
)
end
subject
{
resource
.
overall_approvers
}
it
'returns a list of all the project approvers'
do
is_expected
.
to
contain_exactly
(
approver
,
code_owner
)
end
context
'when exclude_code_owners is true'
do
subject
{
resource
.
overall_approvers
(
exclude_code_owners:
true
)
}
it
'excludes code owners'
do
is_expected
.
to
contain_exactly
(
approver
)
end
end
context
'when approvers are overwritten'
do
let!
(
:merge_request_regular_rule
)
{
create
(
:approval_merge_request_rule
,
merge_request:
resource
,
users:
[
create
(
:user
)])
}
it
'returns the list of all the merge request level approvers'
do
is_expected
.
to
contain_exactly
(
*
merge_request_regular_rule
.
users
,
code_owner
)
end
end
shared_examples_for
'able to exclude authors'
do
it
'excludes author if authors cannot approve'
do
project
.
update
(
merge_requests_author_approval:
false
)
is_expected
.
not_to
include
(
approver
)
end
it
'includes author if authors are able to approve'
do
project
.
update
(
merge_requests_author_approval:
true
)
is_expected
.
to
include
(
approver
)
end
end
context
'when author is approver'
do
let!
(
:approver
)
{
resource
.
author
}
it_behaves_like
'able to exclude authors'
end
context
'when committer is approver'
do
let
(
:approver
)
{
create
(
:user
,
email:
resource
.
commits
.
first
.
committer_email
)
}
it_behaves_like
'able to exclude authors'
end
end
describe
'#all_approvers_including_groups'
do
let!
(
:group
)
{
create
(
:group_with_members
)
}
let!
(
:approver_group
)
{
create
(
:approver_group
,
target:
resource
,
group:
group
)
}
let!
(
:approver
)
{
create
(
:approver
,
target:
resource
)
}
subject
{
resource
.
all_approvers_including_groups
}
it
'returns all approvers (groups and users)'
do
is_expected
.
to
match_array
(
approver_group
.
users
+
[
approver
.
user
])
end
end
describe
'#authors_can_approve?'
do
subject
{
resource
.
authors_can_approve?
}
it
'returns false when merge_requests_author_approval flag is off'
do
is_expected
.
to
be
false
end
it
'returns true when merge_requests_author_approval flag is turned on'
do
project
.
update
(
merge_requests_author_approval:
true
)
is_expected
.
to
be
true
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