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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
631f59d4
Commit
631f59d4
authored
Aug 03, 2016
by
Paco Guzman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change the API on the merge_request_diff model from diffs -> raw_diffs
parent
6a928360
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
14 deletions
+14
-14
app/models/merge_request.rb
app/models/merge_request.rb
+1
-1
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+5
-5
spec/models/merge_request_diff_spec.rb
spec/models/merge_request_diff_spec.rb
+6
-6
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+2
-2
No files found.
app/models/merge_request.rb
View file @
631f59d4
...
@@ -165,7 +165,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -165,7 +165,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
raw_diffs
(
*
args
)
def
raw_diffs
(
*
args
)
merge_request_diff
?
merge_request_diff
.
diffs
(
*
args
)
:
compare
.
raw_diffs
(
*
args
)
merge_request_diff
?
merge_request_diff
.
raw_
diffs
(
*
args
)
:
compare
.
raw_diffs
(
*
args
)
end
end
def
diffs
(
diff_options
=
nil
)
def
diffs
(
diff_options
=
nil
)
...
...
app/models/merge_request_diff.rb
View file @
631f59d4
...
@@ -33,12 +33,12 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -33,12 +33,12 @@ class MergeRequestDiff < ActiveRecord::Base
end
end
def
size
def
size
real_size
.
presence
||
diffs
.
size
real_size
.
presence
||
raw_
diffs
.
size
end
end
def
diffs
(
options
=
{})
def
raw_
diffs
(
options
=
{})
if
options
[
:ignore_whitespace_change
]
if
options
[
:ignore_whitespace_change
]
@diffs_no_whitespace
||=
begin
@
raw_
diffs_no_whitespace
||=
begin
compare
=
Gitlab
::
Git
::
Compare
.
new
(
compare
=
Gitlab
::
Git
::
Compare
.
new
(
repository
.
raw_repository
,
repository
.
raw_repository
,
self
.
start_commit_sha
||
self
.
target_branch_sha
,
self
.
start_commit_sha
||
self
.
target_branch_sha
,
...
@@ -47,8 +47,8 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -47,8 +47,8 @@ class MergeRequestDiff < ActiveRecord::Base
compare
.
diffs
(
options
)
compare
.
diffs
(
options
)
end
end
else
else
@diffs
||=
{}
@
raw_
diffs
||=
{}
@diffs
[
options
]
||=
load_diffs
(
st_diffs
,
options
)
@
raw_
diffs
[
options
]
||=
load_diffs
(
st_diffs
,
options
)
end
end
end
end
...
...
spec/models/merge_request_diff_spec.rb
View file @
631f59d4
...
@@ -10,7 +10,7 @@ describe MergeRequestDiff, models: true do
...
@@ -10,7 +10,7 @@ describe MergeRequestDiff, models: true do
expect
(
mr_diff
).
not_to
receive
(
:load_diffs
)
expect
(
mr_diff
).
not_to
receive
(
:load_diffs
)
expect
(
Gitlab
::
Git
::
Compare
).
to
receive
(
:new
).
and_call_original
expect
(
Gitlab
::
Git
::
Compare
).
to
receive
(
:new
).
and_call_original
mr_diff
.
diffs
(
ignore_whitespace_change:
true
)
mr_diff
.
raw_
diffs
(
ignore_whitespace_change:
true
)
end
end
end
end
...
@@ -18,19 +18,19 @@ describe MergeRequestDiff, models: true do
...
@@ -18,19 +18,19 @@ describe MergeRequestDiff, models: true do
before
{
mr_diff
.
update_attributes
(
st_diffs:
''
)
}
before
{
mr_diff
.
update_attributes
(
st_diffs:
''
)
}
it
'returns an empty DiffCollection'
do
it
'returns an empty DiffCollection'
do
expect
(
mr_diff
.
diffs
).
to
be_a
(
Gitlab
::
Git
::
DiffCollection
)
expect
(
mr_diff
.
raw_
diffs
).
to
be_a
(
Gitlab
::
Git
::
DiffCollection
)
expect
(
mr_diff
.
diffs
).
to
be_empty
expect
(
mr_diff
.
raw_
diffs
).
to
be_empty
end
end
end
end
context
'when the raw diffs exist'
do
context
'when the raw diffs exist'
do
it
'returns the diffs'
do
it
'returns the diffs'
do
expect
(
mr_diff
.
diffs
).
to
be_a
(
Gitlab
::
Git
::
DiffCollection
)
expect
(
mr_diff
.
raw_
diffs
).
to
be_a
(
Gitlab
::
Git
::
DiffCollection
)
expect
(
mr_diff
.
diffs
).
not_to
be_empty
expect
(
mr_diff
.
raw_
diffs
).
not_to
be_empty
end
end
context
'when the :paths option is set'
do
context
'when the :paths option is set'
do
let
(
:diffs
)
{
mr_diff
.
diffs
(
paths:
[
'files/ruby/popen.rb'
,
'files/ruby/popen.rb'
])
}
let
(
:diffs
)
{
mr_diff
.
raw_
diffs
(
paths:
[
'files/ruby/popen.rb'
,
'files/ruby/popen.rb'
])
}
it
'only returns diffs that match the (old path, new path) given'
do
it
'only returns diffs that match the (old path, new path) given'
do
expect
(
diffs
.
map
(
&
:new_path
)).
to
contain_exactly
(
'files/ruby/popen.rb'
)
expect
(
diffs
.
map
(
&
:new_path
)).
to
contain_exactly
(
'files/ruby/popen.rb'
)
...
...
spec/models/merge_request_spec.rb
View file @
631f59d4
...
@@ -136,7 +136,7 @@ describe MergeRequest, models: true do
...
@@ -136,7 +136,7 @@ describe MergeRequest, models: true do
it
'delegates to the MR diffs'
do
it
'delegates to the MR diffs'
do
merge_request
.
merge_request_diff
=
MergeRequestDiff
.
new
merge_request
.
merge_request_diff
=
MergeRequestDiff
.
new
expect
(
merge_request
.
merge_request_diff
).
to
receive
(
:diffs
).
with
(
options
)
expect
(
merge_request
.
merge_request_diff
).
to
receive
(
:
raw_
diffs
).
with
(
options
)
merge_request
.
raw_diffs
(
options
)
merge_request
.
raw_diffs
(
options
)
end
end
...
@@ -161,7 +161,7 @@ describe MergeRequest, models: true do
...
@@ -161,7 +161,7 @@ describe MergeRequest, models: true do
it
'delegates to the MR diffs'
do
it
'delegates to the MR diffs'
do
merge_request
.
merge_request_diff
=
MergeRequestDiff
.
new
merge_request
.
merge_request_diff
=
MergeRequestDiff
.
new
expect
(
merge_request
.
merge_request_diff
).
to
receive
(
:diffs
).
with
(
hash_including
(
options
))
expect
(
merge_request
.
merge_request_diff
).
to
receive
(
:
raw_
diffs
).
with
(
hash_including
(
options
))
merge_request
.
diffs
(
options
)
merge_request
.
diffs
(
options
)
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