BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
94ca25c9
Commit
94ca25c9
authored
Jul 25, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve merge request diff creation and update tests
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
ceff8106
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
merge_request.rb
app/models/merge_request.rb
+1
-5
merge_request_spec.rb
spec/models/merge_request_spec.rb
+16
-12
No files found.
app/models/merge_request.rb
View file @
94ca25c9
...
...
@@ -299,12 +299,8 @@ class MergeRequest < ActiveRecord::Base
def
reload_diff
return
unless
open
?
merge_request_diff
=
merge_request_diffs
.
create
old_diff_refs
=
self
.
diff_refs
merge_request_diff
.
reload_content
create_merge_request_diff
new_diff_refs
=
self
.
diff_refs
update_diff_notes_positions
(
...
...
spec/models/merge_request_spec.rb
View file @
94ca25c9
...
...
@@ -9,7 +9,7 @@ describe MergeRequest, models: true do
it
{
is_expected
.
to
belong_to
(
:target_project
).
with_foreign_key
(
:target_project_id
).
class_name
(
'Project'
)
}
it
{
is_expected
.
to
belong_to
(
:source_project
).
with_foreign_key
(
:source_project_id
).
class_name
(
'Project'
)
}
it
{
is_expected
.
to
belong_to
(
:merge_user
).
class_name
(
"User"
)
}
it
{
is_expected
.
to
have_
one
(
:merge_request_diff
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_
many
(
:merge_request_diffs
).
dependent
(
:destroy
)
}
end
describe
'modules'
do
...
...
@@ -134,7 +134,7 @@ describe MergeRequest, models: true do
context
'when there are MR diffs'
do
it
'delegates to the MR diffs'
do
merge_request
.
merge_request_diff
=
MergeRequestDiff
.
new
merge_request
.
merge_request_diff
s
.
build
expect
(
merge_request
.
merge_request_diff
).
to
receive
(
:diffs
).
with
(
options
)
...
...
@@ -654,22 +654,26 @@ describe MergeRequest, models: true do
let
(
:commit
)
{
subject
.
project
.
commit
(
sample_commit
.
id
)
}
it
"reloads the diff content"
do
expect
(
subject
.
merge_request_diff
).
to
receive
(
:reload_content
)
it
"does not change existing merge request diff"
do
expect
(
subject
.
merge_request_diff
).
not_to
receive
(
:reload_content
)
subject
.
reload_diff
end
it
"creates new merge request diff"
do
expect
{
subject
.
reload_diff
}.
to
change
{
subject
.
merge_request_diffs
.
count
}.
by
(
1
)
end
it
"updates diff note positions"
do
old_diff_refs
=
subject
.
diff_refs
merge_request_diff
=
subject
.
merge_request_diff
# Update merge_request_diff so that #diff_refs will return commit.diff_refs
allow
(
merge_request_diff
).
to
receive
(
:reload_content
)
do
merge_request_diff
.
base_commit_sha
=
commit
.
parent_id
merge_request_diff
.
start_commit_sha
=
commit
.
parent_id
merge_request_diff
.
head_commit_sha
=
commit
.
sha
allow
(
subject
).
to
receive
(
:create_merge_request_diff
)
do
subject
.
merge_request_diffs
.
create
(
importing:
true
,
base_commit_sha:
commit
.
parent_id
,
start_commit_sha:
commit
.
parent_id
,
head_commit_sha:
commit
.
sha
)
end
expect
(
Notes
::
DiffPositionUpdateService
).
to
receive
(
:new
).
with
(
...
...
@@ -679,8 +683,8 @@ describe MergeRequest, models: true do
new_diff_refs:
commit
.
diff_refs
,
paths:
note
.
position
.
paths
).
and_call_original
expect_any_instance_of
(
Notes
::
DiffPositionUpdateService
).
to
receive
(
:execute
).
with
(
note
)
expect_any_instance_of
(
Notes
::
DiffPositionUpdateService
).
to
receive
(
:execute
).
with
(
note
)
expect_any_instance_of
(
DiffNote
).
to
receive
(
:save
).
once
subject
.
reload_diff
...
...
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