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
18183f8c
Commit
18183f8c
authored
Jan 15, 2019
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract approval specs under ee/
The logics are copied over but unchanged.
parent
8b34de94
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
664 additions
and
547 deletions
+664
-547
ee/spec/models/merge_request_spec.rb
ee/spec/models/merge_request_spec.rb
+441
-0
ee/spec/services/ee/notification_service_spec.rb
ee/spec/services/ee/notification_service_spec.rb
+122
-0
ee/spec/services/merge_requests/update_service_spec.rb
ee/spec/services/merge_requests/update_service_spec.rb
+101
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+0
-410
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+0
-94
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+0
-43
No files found.
ee/spec/models/merge_request_spec.rb
View file @
18183f8c
This diff is collapsed.
Click to expand it.
ee/spec/services/ee/notification_service_spec.rb
View file @
18183f8c
...
@@ -509,4 +509,126 @@ describe EE::NotificationService, :mailer do
...
@@ -509,4 +509,126 @@ describe EE::NotificationService, :mailer do
# Make the watcher a subscriber to detect dupes
# Make the watcher a subscriber to detect dupes
issuable
.
subscriptions
.
create
(
user:
@watcher_and_subscriber
,
subscribed:
true
)
issuable
.
subscriptions
.
create
(
user:
@watcher_and_subscriber
,
subscribed:
true
)
end
end
describe
'Merge Requests'
do
let
(
:notification
)
{
NotificationService
.
new
}
let
(
:assignee
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
,
namespace:
group
)
}
let
(
:another_project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
let
(
:merge_request
)
{
create
:merge_request
,
source_project:
project
,
assignee:
create
(
:user
),
description:
'cc @participant'
}
around
do
|
example
|
perform_enqueued_jobs
do
example
.
run
end
end
before
do
stub_feature_flags
(
approval_rule:
false
)
project
.
add_maintainer
(
merge_request
.
author
)
project
.
add_maintainer
(
merge_request
.
assignee
)
build_team
(
merge_request
.
target_project
)
add_users_with_subscription
(
merge_request
.
target_project
,
merge_request
)
update_custom_notification
(
:new_merge_request
,
@u_guest_custom
,
resource:
project
)
update_custom_notification
(
:new_merge_request
,
@u_custom_global
)
reset_delivered_emails!
end
describe
'#new_merge_request'
do
context
'when the target project has approvers set'
do
let
(
:project_approvers
)
{
create_list
(
:user
,
3
)
}
before
do
merge_request
.
target_project
.
update
(
approvals_before_merge:
1
)
project_approvers
.
each
{
|
approver
|
create
(
:approver
,
user:
approver
,
target:
merge_request
.
target_project
)
}
end
it
'emails the approvers'
do
notification
.
new_merge_request
(
merge_request
,
@u_disabled
)
project_approvers
.
each
{
|
approver
|
should_email
(
approver
)
}
end
it
'does not email the approvers when approval is not necessary'
do
merge_request
.
target_project
.
update
(
approvals_before_merge:
0
)
notification
.
new_merge_request
(
merge_request
,
@u_disabled
)
project_approvers
.
each
{
|
approver
|
should_not_email
(
approver
)
}
end
context
'when the merge request has approvers set'
do
let
(
:mr_approvers
)
{
create_list
(
:user
,
3
)
}
before
do
mr_approvers
.
each
{
|
approver
|
create
(
:approver
,
user:
approver
,
target:
merge_request
)
}
end
it
'emails the MR approvers'
do
notification
.
new_merge_request
(
merge_request
,
@u_disabled
)
mr_approvers
.
each
{
|
approver
|
should_email
(
approver
)
}
end
it
'does not email approvers set on the project who are not approvers of this MR'
do
notification
.
new_merge_request
(
merge_request
,
@u_disabled
)
project_approvers
.
each
{
|
approver
|
should_not_email
(
approver
)
}
end
end
end
end
def
build_team
(
project
)
@u_watcher
=
create_global_setting_for
(
create
(
:user
),
:watch
)
@u_participating
=
create_global_setting_for
(
create
(
:user
),
:participating
)
@u_participant_mentioned
=
create_global_setting_for
(
create
(
:user
,
username:
'participant'
),
:participating
)
@u_disabled
=
create_global_setting_for
(
create
(
:user
),
:disabled
)
@u_mentioned
=
create_global_setting_for
(
create
(
:user
,
username:
'mention'
),
:mention
)
@u_committer
=
create
(
:user
,
username:
'committer'
)
@u_not_mentioned
=
create_global_setting_for
(
create
(
:user
,
username:
'regular'
),
:participating
)
@u_outsider_mentioned
=
create
(
:user
,
username:
'outsider'
)
@u_custom_global
=
create_global_setting_for
(
create
(
:user
,
username:
'custom_global'
),
:custom
)
# User to be participant by default
# This user does not contain any record in notification settings table
# It should be treated with a :participating notification_level
@u_lazy_participant
=
create
(
:user
,
username:
'lazy-participant'
)
@u_guest_watcher
=
create_user_with_notification
(
:watch
,
'guest_watching'
)
@u_guest_custom
=
create_user_with_notification
(
:custom
,
'guest_custom'
)
project
.
add_maintainer
(
@u_watcher
)
project
.
add_maintainer
(
@u_participating
)
project
.
add_maintainer
(
@u_participant_mentioned
)
project
.
add_maintainer
(
@u_disabled
)
project
.
add_maintainer
(
@u_mentioned
)
project
.
add_maintainer
(
@u_committer
)
project
.
add_maintainer
(
@u_not_mentioned
)
project
.
add_maintainer
(
@u_lazy_participant
)
project
.
add_maintainer
(
@u_custom_global
)
end
def
add_users_with_subscription
(
project
,
issuable
)
@subscriber
=
create
:user
@unsubscriber
=
create
:user
@unsubscribed_mentioned
=
create
:user
,
username:
'unsubscribed_mentioned'
@subscribed_participant
=
create_global_setting_for
(
create
(
:user
,
username:
'subscribed_participant'
),
:participating
)
@watcher_and_subscriber
=
create_global_setting_for
(
create
(
:user
),
:watch
)
project
.
add_maintainer
(
@subscribed_participant
)
project
.
add_maintainer
(
@subscriber
)
project
.
add_maintainer
(
@unsubscriber
)
project
.
add_maintainer
(
@watcher_and_subscriber
)
project
.
add_maintainer
(
@unsubscribed_mentioned
)
issuable
.
subscriptions
.
create
(
user:
@unsubscribed_mentioned
,
project:
project
,
subscribed:
false
)
issuable
.
subscriptions
.
create
(
user:
@subscriber
,
project:
project
,
subscribed:
true
)
issuable
.
subscriptions
.
create
(
user:
@subscribed_participant
,
project:
project
,
subscribed:
true
)
issuable
.
subscriptions
.
create
(
user:
@unsubscriber
,
project:
project
,
subscribed:
false
)
# Make the watcher a subscriber to detect dupes
issuable
.
subscriptions
.
create
(
user:
@watcher_and_subscriber
,
project:
project
,
subscribed:
true
)
end
end
end
end
ee/spec/services/merge_requests/update_service_spec.rb
View file @
18183f8c
...
@@ -79,5 +79,106 @@ describe MergeRequests::UpdateService, :mailer do
...
@@ -79,5 +79,106 @@ describe MergeRequests::UpdateService, :mailer do
end
end
end
end
end
end
context
'merge'
do
before
do
stub_feature_flags
(
approval_rule:
false
)
end
let
(
:opts
)
{
{
merge:
merge_request
.
diff_head_sha
}
}
context
'when not approved'
do
before
do
merge_request
.
update
(
approvals_before_merge:
1
)
perform_enqueued_jobs
do
update_merge_request
(
opts
)
@merge_request
=
MergeRequest
.
find
(
merge_request
.
id
)
end
end
it
{
expect
(
@merge_request
).
to
be_valid
}
it
{
expect
(
@merge_request
.
state
).
to
eq
(
'opened'
)
}
end
context
'when approved'
do
before
do
merge_request
.
update
(
approvals_before_merge:
1
)
merge_request
.
approvals
.
create
(
user:
user
)
perform_enqueued_jobs
do
update_merge_request
(
opts
)
@merge_request
=
MergeRequest
.
find
(
merge_request
.
id
)
end
end
it
{
expect
(
@merge_request
).
to
be_valid
}
it
{
expect
(
@merge_request
.
state
).
to
eq
(
'merged'
)
}
end
end
context
'when the approvers change'
do
let
(
:existing_approver
)
{
create
(
:user
)
}
let
(
:removed_approver
)
{
create
(
:user
)
}
let
(
:new_approver
)
{
create
(
:user
)
}
before
do
stub_feature_flags
(
approval_rule:
false
)
perform_enqueued_jobs
do
update_merge_request
(
approver_ids:
[
existing_approver
,
removed_approver
].
map
(
&
:id
).
join
(
','
))
end
Todo
.
where
(
action:
Todo
::
APPROVAL_REQUIRED
).
destroy_all
# rubocop: disable DestroyAll
ActionMailer
::
Base
.
deliveries
.
clear
end
context
'when an approver is added and an approver is removed'
do
before
do
perform_enqueued_jobs
do
update_merge_request
(
approver_ids:
[
new_approver
,
existing_approver
].
map
(
&
:id
).
join
(
','
))
end
end
it
'adds todos for and sends emails to the new approvers'
do
expect
(
Todo
.
where
(
user:
new_approver
,
action:
Todo
::
APPROVAL_REQUIRED
)).
not_to
be_empty
should_email
(
new_approver
)
end
it
'does not add todos for or send emails to the existing approvers'
do
expect
(
Todo
.
where
(
user:
existing_approver
,
action:
Todo
::
APPROVAL_REQUIRED
)).
to
be_empty
should_not_email
(
existing_approver
)
end
it
'does not add todos for or send emails to the removed approvers'
do
expect
(
Todo
.
where
(
user:
removed_approver
,
action:
Todo
::
APPROVAL_REQUIRED
)).
to
be_empty
should_not_email
(
removed_approver
)
end
end
context
'when the approvers are set to the same values'
do
it
'does not create any todos'
do
expect
do
update_merge_request
(
approver_ids:
[
existing_approver
,
removed_approver
].
map
(
&
:id
).
join
(
','
))
end
.
not_to
change
{
Todo
.
count
}
end
it
'does not send any emails'
do
expect
do
update_merge_request
(
approver_ids:
[
existing_approver
,
removed_approver
].
map
(
&
:id
).
join
(
','
))
end
.
not_to
change
{
ActionMailer
::
Base
.
deliveries
.
count
}
end
end
end
context
'updating target_branch'
do
it
'resets approvals when target_branch is changed'
do
merge_request
.
target_project
.
update
(
reset_approvals_on_push:
true
)
merge_request
.
approvals
.
create
(
user_id:
user2
.
id
)
update_merge_request
(
target_branch:
'video'
)
expect
(
merge_request
.
reload
.
approvals
).
to
be_empty
end
end
end
end
end
end
spec/models/merge_request_spec.rb
View file @
18183f8c
This diff is collapsed.
Click to expand it.
spec/services/merge_requests/update_service_spec.rb
View file @
18183f8c
...
@@ -19,8 +19,6 @@ describe MergeRequests::UpdateService, :mailer do
...
@@ -19,8 +19,6 @@ describe MergeRequests::UpdateService, :mailer do
end
end
before
do
before
do
stub_feature_flags
(
approval_rule:
false
)
project
.
add_maintainer
(
user
)
project
.
add_maintainer
(
user
)
project
.
add_developer
(
user2
)
project
.
add_developer
(
user2
)
project
.
add_developer
(
user3
)
project
.
add_developer
(
user3
)
...
@@ -260,35 +258,6 @@ describe MergeRequests::UpdateService, :mailer do
...
@@ -260,35 +258,6 @@ describe MergeRequests::UpdateService, :mailer do
it
{
expect
(
@merge_request
.
state
).
to
eq
(
'opened'
)
}
it
{
expect
(
@merge_request
.
state
).
to
eq
(
'opened'
)
}
end
end
context
'when not approved'
do
before
do
merge_request
.
update
(
approvals_before_merge:
1
)
perform_enqueued_jobs
do
service
.
execute
(
merge_request
)
@merge_request
=
MergeRequest
.
find
(
merge_request
.
id
)
end
end
it
{
expect
(
@merge_request
).
to
be_valid
}
it
{
expect
(
@merge_request
.
state
).
to
eq
(
'opened'
)
}
end
context
'when approved'
do
before
do
merge_request
.
update
(
approvals_before_merge:
1
)
merge_request
.
approvals
.
create
(
user:
user
)
perform_enqueued_jobs
do
service
.
execute
(
merge_request
)
@merge_request
=
MergeRequest
.
find
(
merge_request
.
id
)
end
end
it
{
expect
(
@merge_request
).
to
be_valid
}
it
{
expect
(
@merge_request
.
state
).
to
eq
(
'merged'
)
}
end
end
end
context
'todos'
do
context
'todos'
do
...
@@ -485,58 +454,6 @@ describe MergeRequests::UpdateService, :mailer do
...
@@ -485,58 +454,6 @@ describe MergeRequests::UpdateService, :mailer do
end
end
end
end
context
'when the approvers change'
do
let
(
:existing_approver
)
{
create
(
:user
)
}
let
(
:removed_approver
)
{
create
(
:user
)
}
let
(
:new_approver
)
{
create
(
:user
)
}
before
do
perform_enqueued_jobs
do
update_merge_request
(
approver_ids:
[
existing_approver
,
removed_approver
].
map
(
&
:id
).
join
(
','
))
end
Todo
.
where
(
action:
Todo
::
APPROVAL_REQUIRED
).
destroy_all
# rubocop: disable DestroyAll
ActionMailer
::
Base
.
deliveries
.
clear
end
context
'when an approver is added and an approver is removed'
do
before
do
perform_enqueued_jobs
do
update_merge_request
(
approver_ids:
[
new_approver
,
existing_approver
].
map
(
&
:id
).
join
(
','
))
end
end
it
'adds todos for and sends emails to the new approvers'
do
expect
(
Todo
.
where
(
user:
new_approver
,
action:
Todo
::
APPROVAL_REQUIRED
)).
not_to
be_empty
should_email
(
new_approver
)
end
it
'does not add todos for or send emails to the existing approvers'
do
expect
(
Todo
.
where
(
user:
existing_approver
,
action:
Todo
::
APPROVAL_REQUIRED
)).
to
be_empty
should_not_email
(
existing_approver
)
end
it
'does not add todos for or send emails to the removed approvers'
do
expect
(
Todo
.
where
(
user:
removed_approver
,
action:
Todo
::
APPROVAL_REQUIRED
)).
to
be_empty
should_not_email
(
removed_approver
)
end
end
context
'when the approvers are set to the same values'
do
it
'does not create any todos'
do
expect
do
update_merge_request
(
approver_ids:
[
existing_approver
,
removed_approver
].
map
(
&
:id
).
join
(
','
))
end
.
not_to
change
{
Todo
.
count
}
end
it
'does not send any emails'
do
expect
do
update_merge_request
(
approver_ids:
[
existing_approver
,
removed_approver
].
map
(
&
:id
).
join
(
','
))
end
.
not_to
change
{
ActionMailer
::
Base
.
deliveries
.
count
}
end
end
end
context
'updating mentions'
do
context
'updating mentions'
do
let
(
:mentionable
)
{
merge_request
}
let
(
:mentionable
)
{
merge_request
}
include_examples
'updating mentions'
,
described_class
include_examples
'updating mentions'
,
described_class
...
@@ -622,17 +539,6 @@ describe MergeRequests::UpdateService, :mailer do
...
@@ -622,17 +539,6 @@ describe MergeRequests::UpdateService, :mailer do
end
end
end
end
context
'updating target_branch'
do
it
'resets approvals when target_branch is changed'
do
merge_request
.
target_project
.
update
(
reset_approvals_on_push:
true
)
merge_request
.
approvals
.
create
(
user_id:
user2
.
id
)
update_merge_request
(
target_branch:
'video'
)
expect
(
merge_request
.
reload
.
approvals
).
to
be_empty
end
end
context
'updating asssignee_id'
do
context
'updating asssignee_id'
do
it
'does not update assignee when assignee_id is invalid'
do
it
'does not update assignee when assignee_id is invalid'
do
merge_request
.
update
(
assignee_id:
user
.
id
)
merge_request
.
update
(
assignee_id:
user
.
id
)
...
...
spec/services/notification_service_spec.rb
View file @
18183f8c
...
@@ -1304,49 +1304,6 @@ describe NotificationService, :mailer do
...
@@ -1304,49 +1304,6 @@ describe NotificationService, :mailer do
should_email
(
user_4
)
should_email
(
user_4
)
end
end
context
'when the target project has approvers set'
do
let
(
:project_approvers
)
{
create_list
(
:user
,
3
)
}
before
do
stub_feature_flags
(
approval_rule:
false
)
merge_request
.
target_project
.
update
(
approvals_before_merge:
1
)
project_approvers
.
each
{
|
approver
|
create
(
:approver
,
user:
approver
,
target:
merge_request
.
target_project
)
}
end
it
'emails the approvers'
do
notification
.
new_merge_request
(
merge_request
,
@u_disabled
)
project_approvers
.
each
{
|
approver
|
should_email
(
approver
)
}
end
it
'does not email the approvers when approval is not necessary'
do
merge_request
.
target_project
.
update
(
approvals_before_merge:
0
)
notification
.
new_merge_request
(
merge_request
,
@u_disabled
)
project_approvers
.
each
{
|
approver
|
should_not_email
(
approver
)
}
end
context
'when the merge request has approvers set'
do
let
(
:mr_approvers
)
{
create_list
(
:user
,
3
)
}
before
do
mr_approvers
.
each
{
|
approver
|
create
(
:approver
,
user:
approver
,
target:
merge_request
)
}
end
it
'emails the MR approvers'
do
notification
.
new_merge_request
(
merge_request
,
@u_disabled
)
mr_approvers
.
each
{
|
approver
|
should_email
(
approver
)
}
end
it
'does not email approvers set on the project who are not approvers of this MR'
do
notification
.
new_merge_request
(
merge_request
,
@u_disabled
)
project_approvers
.
each
{
|
approver
|
should_not_email
(
approver
)
}
end
end
end
context
'participating'
do
context
'participating'
do
it_should_behave_like
'participating by assignee notification'
do
it_should_behave_like
'participating by assignee notification'
do
let
(
:participant
)
{
create
(
:user
,
username:
'user-participant'
)}
let
(
:participant
)
{
create
(
:user
,
username:
'user-participant'
)}
...
...
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