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
a57c77f6
Commit
a57c77f6
authored
Sep 21, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a spec for merge request metric caching while refreshing a merge request from a forked project.
parent
68e1b5bb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
12 deletions
+38
-12
app/services/merge_requests/refresh_service.rb
app/services/merge_requests/refresh_service.rb
+1
-1
spec/services/merge_requests/create_service_spec.rb
spec/services/merge_requests/create_service_spec.rb
+2
-1
spec/services/merge_requests/refresh_service_spec.rb
spec/services/merge_requests/refresh_service_spec.rb
+29
-7
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+6
-3
No files found.
app/services/merge_requests/refresh_service.rb
View file @
a57c77f6
...
...
@@ -145,7 +145,7 @@ module MergeRequests
# If the merge requests closes any issues, save this information in the
# `MergeRequestsClosingIssues` model (as a performance optimization).
def
cache_merge_requests_closing_issues
merge_requests_for_source_branch
.
each
do
|
merge_request
|
@project
.
merge_requests
.
where
(
source_branch:
@branch_name
)
.
each
do
|
merge_request
|
merge_request
.
cache_merge_request_closes_issues!
(
@current_user
)
end
end
...
...
spec/services/merge_requests/create_service_spec.rb
View file @
a57c77f6
...
...
@@ -108,7 +108,8 @@ describe MergeRequests::CreateService, services: true do
allow
(
service
).
to
receive
(
:execute_hooks
)
merge_request
=
service
.
execute
expect
(
merge_request
.
reload
.
closes_issues
(
user
)).
to
match_array
([
first_issue
,
second_issue
])
issue_ids
=
MergeRequestsClosingIssues
.
where
(
merge_request:
merge_request
).
pluck
(
:issue_id
)
expect
(
issue_ids
).
to
match_array
([
first_issue
.
id
,
second_issue
.
id
])
end
end
end
...
...
spec/services/merge_requests/refresh_service_spec.rb
View file @
a57c77f6
...
...
@@ -174,11 +174,10 @@ describe MergeRequests::RefreshService, services: true do
end
end
context
'
push commits closing issue
s'
do
context
'
merge request metric
s'
do
let
(
:issue
)
{
create
:issue
,
project:
@project
}
let
(
:commit_author
)
{
create
:user
}
let
(
:commit
)
{
project
.
commit
}
let!
(
:merge_request
)
{
create
(
:merge_request
,
target_branch:
'master'
,
source_branch:
'feature'
,
source_project:
@project
)
}
before
do
project
.
team
<<
[
commit_author
,
:developer
]
...
...
@@ -195,12 +194,35 @@ describe MergeRequests::RefreshService, services: true do
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:commits
).
and_return
([
commit
])
end
it
'creates a `MergeRequestsClosingIssues` record for each closed issue'
do
refresh_service
=
service
.
new
(
@project
,
@user
)
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/feature'
)
context
'when the merge request is sourced from the same project'
do
it
'creates a `MergeRequestsClosingIssues` record for each issue closed by a commit'
do
merge_request
=
create
(
:merge_request
,
target_branch:
'master'
,
source_branch:
'feature'
,
source_project:
@project
)
refresh_service
=
service
.
new
(
@project
,
@user
)
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/feature'
)
issue_ids
=
MergeRequestsClosingIssues
.
where
(
merge_request:
merge_request
).
pluck
(
:issue_id
)
expect
(
issue_ids
).
to
eq
([
issue
.
id
])
end
end
expect
(
merge_request
.
reload
.
closes_issues
(
@user
)).
to
eq
([
issue
])
context
'when the merge request is sourced from a different project'
do
it
'creates a `MergeRequestsClosingIssues` record for each issue closed by a commit'
do
forked_project
=
create
(
:project
)
create
(
:forked_project_link
,
forked_to_project:
forked_project
,
forked_from_project:
@project
)
merge_request
=
create
(
:merge_request
,
target_branch:
'master'
,
source_branch:
'feature'
,
target_project:
@project
,
source_project:
forked_project
)
refresh_service
=
service
.
new
(
@project
,
@user
)
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/feature'
)
issue_ids
=
MergeRequestsClosingIssues
.
where
(
merge_request:
merge_request
).
pluck
(
:issue_id
)
expect
(
issue_ids
).
to
eq
([
issue
.
id
])
end
end
end
...
...
spec/services/merge_requests/update_service_spec.rb
View file @
a57c77f6
...
...
@@ -274,7 +274,8 @@ describe MergeRequests::UpdateService, services: true do
allow
(
service
).
to
receive
(
:execute_hooks
)
service
.
execute
(
merge_request
)
expect
(
merge_request
.
reload
.
closes_issues
(
user
)).
to
match_array
([
first_issue
,
second_issue
])
issue_ids
=
MergeRequestsClosingIssues
.
where
(
merge_request:
merge_request
).
pluck
(
:issue_id
)
expect
(
issue_ids
).
to
match_array
([
first_issue
.
id
,
second_issue
.
id
])
end
it
'removes `MergeRequestsClosingIssues` records when issues are not closed anymore'
do
...
...
@@ -288,13 +289,15 @@ describe MergeRequests::UpdateService, services: true do
merge_request
=
MergeRequests
::
CreateService
.
new
(
project
,
user
,
opts
).
execute
expect
(
merge_request
.
reload
.
closes_issues
(
user
)).
to
match_array
([
first_issue
,
second_issue
])
issue_ids
=
MergeRequestsClosingIssues
.
where
(
merge_request:
merge_request
).
pluck
(
:issue_id
)
expect
(
issue_ids
).
to
match_array
([
first_issue
.
id
,
second_issue
.
id
])
service
=
described_class
.
new
(
project
,
user
,
description:
"not closing any issues"
)
allow
(
service
).
to
receive
(
:execute_hooks
)
service
.
execute
(
merge_request
.
reload
)
expect
(
merge_request
.
reload
.
closes_issues
(
user
)).
to
be_empty
issue_ids
=
MergeRequestsClosingIssues
.
where
(
merge_request:
merge_request
).
pluck
(
:issue_id
)
expect
(
issue_ids
).
to
be_empty
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