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
46b7a3f8
Unverified
Commit
46b7a3f8
authored
Oct 06, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent PG::Error exception when check commit reference on commit
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
90c96d1d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
3 deletions
+28
-3
note.rb
app/models/note.rb
+8
-3
note_spec.rb
spec/models/note_spec.rb
+20
-0
No files found.
app/models/note.rb
View file @
46b7a3f8
...
...
@@ -47,7 +47,7 @@ class Note < ActiveRecord::Base
scope
:for_commit_id
,
->
(
commit_id
)
{
where
(
noteable_type:
"Commit"
,
commit_id:
commit_id
)
}
scope
:inline
,
->
{
where
(
"line_code IS NOT NULL"
)
}
scope
:not_inline
,
->
{
where
(
line_code:
[
nil
,
''
])
}
scope
:system
,
->
{
where
(
system:
true
)
}
scope
:common
,
->
{
where
(
noteable_type:
[
""
,
nil
])
}
scope
:fresh
,
->
{
order
(
"created_at ASC, id ASC"
)
}
scope
:inc_author_project
,
->
{
includes
(
:project
,
:author
)
}
...
...
@@ -168,9 +168,14 @@ class Note < ActiveRecord::Base
# Determine whether or not a cross-reference note already exists.
def
cross_reference_exists?
(
noteable
,
mentioner
)
gfm_reference
=
mentioner_gfm_ref
(
noteable
,
mentioner
)
notes
=
if
noteable
.
is_a?
(
Commit
)
where
(
commit_id:
noteable
.
id
)
else
where
(
noteable_id:
noteable
.
id
)
end
where
([
'noteable_id = ? and system = ? and note like ?'
,
noteable
.
id
,
true
,
"_mentioned in
#{
gfm_reference
}
_"
])
.
any?
notes
.
where
(
'note like ?'
,
"_mentioned in
#{
gfm_reference
}
_"
).
system
.
any?
end
def
search
(
query
)
...
...
spec/models/note_spec.rb
View file @
46b7a3f8
...
...
@@ -258,6 +258,17 @@ describe Note do
its
(
:commit_id
)
{
should
==
commit
.
id
}
its
(
:note
)
{
should
==
"_mentioned in issue #
#{
issue
.
iid
}
_"
}
end
context
'commit from commit'
do
let
(
:parent_commit
)
{
commit
.
parents
.
first
}
subject
{
Note
.
create_cross_reference_note
(
commit
,
parent_commit
,
author
,
project
)
}
it
{
should
be_valid
}
its
(
:noteable_type
)
{
should
==
"Commit"
}
its
(
:noteable_id
)
{
should
be_nil
}
its
(
:commit_id
)
{
should
==
commit
.
id
}
its
(
:note
)
{
should
==
"_mentioned in commit
#{
parent_commit
.
id
[
0
...
6
]
}
_"
}
end
end
describe
'#cross_reference_exists?'
do
...
...
@@ -278,6 +289,15 @@ describe Note do
it
'detects if a mentionable has not already been mentioned'
do
Note
.
cross_reference_exists?
(
issue
,
commit1
).
should
be_false
end
context
'commit on commit'
do
before
do
Note
.
create_cross_reference_note
(
commit0
,
commit1
,
author
,
project
)
end
it
{
Note
.
cross_reference_exists?
(
commit0
,
commit1
).
should
be_true
}
it
{
Note
.
cross_reference_exists?
(
commit1
,
commit0
).
should
be_false
}
end
end
describe
'#system?'
do
...
...
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