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
6dd71888
Commit
6dd71888
authored
Jul 07, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make `DiffNote#update_position` private
parent
70a64f6a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
58 deletions
+58
-58
app/models/diff_note.rb
app/models/diff_note.rb
+14
-19
spec/models/diff_note_spec.rb
spec/models/diff_note_spec.rb
+44
-39
No files found.
app/models/diff_note.rb
View file @
6dd71888
...
@@ -72,6 +72,20 @@ class DiffNote < Note
...
@@ -72,6 +72,20 @@ class DiffNote < Note
self
.
position
.
diff_refs
==
diff_refs
self
.
position
.
diff_refs
==
diff_refs
end
end
private
def
supported?
!
self
.
for_merge_request?
||
self
.
noteable
.
support_new_diff_notes?
end
def
set_original_position
self
.
original_position
=
self
.
position
.
dup
end
def
set_line_code
self
.
line_code
=
self
.
position
.
line_code
(
self
.
project
.
repository
)
end
def
update_position
def
update_position
return
unless
supported?
return
unless
supported?
return
if
for_commit?
return
if
for_commit?
...
@@ -87,25 +101,6 @@ class DiffNote < Note
...
@@ -87,25 +101,6 @@ class DiffNote < Note
).
execute
(
self
)
).
execute
(
self
)
end
end
def
update_position!
update_position
&&
Gitlab
::
Timeless
.
timeless
(
self
,
&
:save
)
end
private
def
supported?
!
self
.
for_merge_request?
||
self
.
noteable
.
support_new_diff_notes?
end
def
set_original_position
self
.
original_position
=
self
.
position
.
dup
end
def
set_line_code
self
.
line_code
=
self
.
position
.
line_code
(
self
.
project
.
repository
)
end
def
verify_supported
def
verify_supported
return
if
supported?
return
if
supported?
...
...
spec/models/diff_note_spec.rb
View file @
6dd71888
...
@@ -9,7 +9,7 @@ describe DiffNote, models: true do
...
@@ -9,7 +9,7 @@ describe DiffNote, models: true do
let
(
:path
)
{
"files/ruby/popen.rb"
}
let
(
:path
)
{
"files/ruby/popen.rb"
}
let
(
:position
)
do
let
!
(
:position
)
do
Gitlab
::
Diff
::
Position
.
new
(
Gitlab
::
Diff
::
Position
.
new
(
old_path:
path
,
old_path:
path
,
new_path:
path
,
new_path:
path
,
...
@@ -19,7 +19,7 @@ describe DiffNote, models: true do
...
@@ -19,7 +19,7 @@ describe DiffNote, models: true do
)
)
end
end
let
(
:new_position
)
do
let
!
(
:new_position
)
do
Gitlab
::
Diff
::
Position
.
new
(
Gitlab
::
Diff
::
Position
.
new
(
old_path:
path
,
old_path:
path
,
new_path:
path
,
new_path:
path
,
...
@@ -129,56 +129,61 @@ describe DiffNote, models: true do
...
@@ -129,56 +129,61 @@ describe DiffNote, models: true do
end
end
end
end
describe
"#update_position"
do
describe
"creation"
do
context
"when noteable is a commit"
do
describe
"updating of position"
do
subject
{
create
(
:diff_note_on_commit
,
project:
project
,
position:
position
)
}
context
"when noteable is a commit"
do
let
(
:diff_note
)
{
create
(
:diff_note_on_commit
,
project:
project
,
position:
position
)
}
it
"doesn't use the DiffPositionUpdateService"
do
expect
(
Notes
::
DiffPositionUpdateService
).
not_to
receive
(
:new
)
subject
.
update_position
end
it
"doesn't update the position"
do
subject
.
update_position
expect
(
subject
.
original_position
).
to
eq
(
position
)
expect
(
subject
.
position
).
to
eq
(
position
)
end
end
context
"when noteable is a merge request"
do
context
"when the note is active"
do
it
"doesn't use the DiffPositionUpdateService"
do
it
"doesn't use the DiffPositionUpdateService"
do
expect
(
Notes
::
DiffPositionUpdateService
).
not_to
receive
(
:new
)
expect
(
Notes
::
DiffPositionUpdateService
).
not_to
receive
(
:new
)
subject
.
update_position
diff_note
end
end
it
"doesn't update the position"
do
it
"doesn't update the position"
do
subject
.
update_position
diff_note
expect
(
subject
.
original_position
).
to
eq
(
position
)
expect
(
diff_note
.
original_position
).
to
eq
(
position
)
expect
(
subject
.
position
).
to
eq
(
position
)
expect
(
diff_note
.
position
).
to
eq
(
position
)
end
end
end
end
context
"when the note is outdated"
do
context
"when noteable is a merge request"
do
before
do
let
(
:diff_note
)
{
create
(
:diff_note_on_merge_request
,
project:
project
,
position:
position
,
noteable:
merge_request
)
}
allow
(
subject
.
noteable
).
to
receive
(
:diff_refs
).
and_return
(
commit
.
diff_refs
)
context
"when the note is active"
do
it
"doesn't use the DiffPositionUpdateService"
do
expect
(
Notes
::
DiffPositionUpdateService
).
not_to
receive
(
:new
)
diff_note
end
it
"doesn't update the position"
do
diff_note
expect
(
diff_note
.
original_position
).
to
eq
(
position
)
expect
(
diff_note
.
position
).
to
eq
(
position
)
end
end
end
it
"uses the DiffPositionUpdateService"
do
context
"when the note is outdated"
do
expect
(
Notes
::
DiffPositionUpdateService
).
to
receive
(
:new
).
with
(
before
do
project
,
allow
(
merge_request
).
to
receive
(
:diff_refs
).
and_return
(
commit
.
diff_refs
)
nil
,
end
old_diff_refs:
position
.
diff_refs
,
new_diff_refs:
commit
.
diff_refs
,
it
"uses the DiffPositionUpdateService"
do
paths:
[
path
]
service
=
instance_double
(
"Notes::DiffPositionUpdateService"
)
).
and_call_original
expect
(
Notes
::
DiffPositionUpdateService
).
to
receive
(
:new
).
with
(
expect_any_instance_of
(
Notes
::
DiffPositionUpdateService
).
to
receive
(
:execute
).
with
(
subject
)
project
,
nil
,
subject
.
update_position
old_diff_refs:
position
.
diff_refs
,
new_diff_refs:
commit
.
diff_refs
,
paths:
[
path
]
).
and_return
(
service
)
expect
(
service
).
to
receive
(
:execute
)
diff_note
end
end
end
end
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