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
2e89f7c9
Commit
2e89f7c9
authored
Dec 10, 2019
by
nmilojevic1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix MR comments
Add empty lines in specs Fix format for DIFFLINENOTFOUNDMESSAGE
parent
948ac8b9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
8 deletions
+22
-8
app/models/diff_note.rb
app/models/diff_note.rb
+3
-3
spec/models/diff_note_spec.rb
spec/models/diff_note_spec.rb
+17
-3
spec/support/shared_examples/models/diff_note_after_commit_shared_examples.rb
...examples/models/diff_note_after_commit_shared_examples.rb
+2
-2
No files found.
app/models/diff_note.rb
View file @
2e89f7c9
...
...
@@ -26,7 +26,7 @@ class DiffNote < Note
NoteDiffFileCreationError
=
Class
.
new
(
StandardError
)
DIFF_LINE_NOT_FOUND_MESSAGE
=
_
(
"Failed to find diff line for: %{file_path},
new_pos: %{new_pos}, old_pos: %{old_pos
}"
)
DIFF_LINE_NOT_FOUND_MESSAGE
=
_
(
"Failed to find diff line for: %{file_path},
old_line: %{old_line}, new_line: %{new_line
}"
)
DIFF_FILE_NOT_FOUND_MESSAGE
=
_
(
"Failed to find diff file"
)
after_commit
:create_diff_file
,
on: :create
...
...
@@ -45,8 +45,8 @@ class DiffNote < Note
unless
diff_line
raise
NoteDiffFileCreationError
,
DIFF_LINE_NOT_FOUND_MESSAGE
%
{
file_path:
diff_file
.
file_path
,
new_pos:
original_position
.
new
_line
,
old_pos:
original_position
.
old
_line
old_line:
original_position
.
old
_line
,
new_line:
original_position
.
new
_line
}
end
...
...
spec/models/diff_note_spec.rb
View file @
2e89f7c9
...
...
@@ -99,11 +99,13 @@ describe DiffNote do
new_line:
9
,
diff_refs:
merge_request
.
diff_refs
)
end
subject
{
build
(
:diff_note_on_merge_request
,
project:
project
,
position:
position
,
noteable:
merge_request
)
}
let
(
:diff_file_from_repository
)
do
position
.
diff_file
(
project
.
repository
)
end
let
(
:diff_file
)
do
diffs
=
merge_request
.
diffs
raw_diff
=
diffs
.
diffable
.
raw_diffs
(
diffs
.
diff_options
.
merge
(
paths:
[
'files/ruby/popen.rb'
])).
first
...
...
@@ -112,18 +114,23 @@ describe DiffNote do
diff_refs:
diffs
.
diff_refs
,
fallback_diff_refs:
diffs
.
fallback_diff_refs
)
end
let
(
:diff_line
)
{
diff_file
.
diff_lines
.
first
}
before
do
allow_any_instance_of
(
::
Gitlab
::
Diff
::
Position
).
to
receive
(
:line_code
).
with
(
project
.
repository
).
and_return
(
'2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14'
)
end
context
'when diffs are already created'
do
before
do
allow
(
subject
).
to
receive
(
:created_at_diff?
).
and_return
(
true
)
end
context
'when diff_file is found in persisted diffs'
do
before
do
allow
(
merge_request
).
to
receive_message_chain
(
:diffs
,
:diff_files
,
:first
).
and_return
(
diff_file
)
end
context
'when importing'
do
before
do
subject
.
importing
=
true
...
...
@@ -134,11 +141,13 @@ describe DiffNote do
before
do
allow
(
diff_file
).
to
receive
(
:line_for_position
).
with
(
position
).
and_return
(
diff_line
)
end
it
'creates a diff note file'
do
subject
.
save
expect
(
subject
.
note_diff_file
).
to
be_present
end
end
context
'when diff_line is not found in persisted diff_file'
do
before
do
allow
(
diff_file
).
to
receive
(
:line_for_position
).
and_return
(
nil
)
...
...
@@ -150,12 +159,15 @@ describe DiffNote do
context
'when not importing'
do
context
'when diff_line is not found'
do
it
'raises an error'
do
before
do
allow
(
diff_file
).
to
receive
(
:line_for_position
).
with
(
position
).
and_return
(
nil
)
end
it
'raises an error'
do
expect
{
subject
.
save
}.
to
raise_error
(
::
DiffNote
::
NoteDiffFileCreationError
,
"Failed to find diff line for:
#{
diff_file
.
file_path
}
, "
\
"
new_pos:
#{
position
.
new
_line
}
"
\
",
old_pos:
#{
position
.
old
_line
}
"
)
"
old_line:
#{
position
.
old
_line
}
"
\
",
new_line:
#{
position
.
new
_line
}
"
)
end
end
...
...
@@ -180,10 +192,12 @@ describe DiffNote do
it_behaves_like
'a valid diff note with after commit callback'
end
end
context
'when diffs are not already created'
do
before
do
allow
(
subject
).
to
receive
(
:created_at_diff?
).
and_return
(
false
)
end
it_behaves_like
'a valid diff note with after commit callback'
end
...
...
spec/support/shared_examples/models/diff_note_after_commit_shared_examples.rb
View file @
2e89f7c9
...
...
@@ -11,8 +11,8 @@ shared_examples 'a valid diff note with after commit callback' do
allow
(
diff_file_from_repository
).
to
receive
(
:line_for_position
).
with
(
position
).
and_return
(
nil
)
expect
{
subject
.
save
}.
to
raise_error
(
::
DiffNote
::
NoteDiffFileCreationError
,
"Failed to find diff line for:
#{
diff_file_from_repository
.
file_path
}
, "
\
"
new_pos:
#{
position
.
new
_line
}
"
\
",
old_pos:
#{
position
.
old
_line
}
"
)
"
old_line:
#{
position
.
old
_line
}
"
\
",
new_line:
#{
position
.
new
_line
}
"
)
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