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
Léo-Paul Géneau
gitlab-ce
Commits
6114aedf
Commit
6114aedf
authored
Jul 14, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce
parents
ee53ba9f
90e47dd9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
18 deletions
+81
-18
app/models/concerns/mentionable.rb
app/models/concerns/mentionable.rb
+28
-14
app/models/note.rb
app/models/note.rb
+1
-1
app/services/issues/update_service.rb
app/services/issues/update_service.rb
+1
-1
app/services/merge_requests/update_service.rb
app/services/merge_requests/update_service.rb
+1
-1
spec/models/concerns/mentionable_spec.rb
spec/models/concerns/mentionable_spec.rb
+49
-0
spec/support/mentionable_shared_examples.rb
spec/support/mentionable_shared_examples.rb
+1
-1
No files found.
app/models/concerns/mentionable.rb
View file @
6114aedf
...
...
@@ -79,22 +79,36 @@ module Mentionable
end
end
# If the mentionable_text field is about to change, locate any *added* references and create cross references for
# them. Invoke from an observer's #before_save implementation.
def
notice_added_references
(
p
=
project
,
a
=
author
)
ch
=
changed_attributes
original
,
mentionable_changed
=
""
,
false
self
.
class
.
mentionable_attrs
.
each
do
|
attr
|
if
ch
[
attr
]
original
<<
ch
[
attr
]
mentionable_changed
=
true
end
end
# When a mentionable field is changed, creates cross-reference notes that
# don't already exist
def
create_new_cross_references!
(
p
=
project
,
a
=
author
)
changes
=
detect_mentionable_changes
return
if
changes
.
empty?
# Only proceed if the saved changes actually include a chance to an attr_mentionable field.
return
unless
mentionable_changed
original_text
=
changes
.
collect
{
|
_
,
vals
|
vals
.
first
}.
join
(
' '
)
preexisting
=
references
(
p
,
self
.
author
,
original
)
preexisting
=
references
(
p
,
self
.
author
,
original
_text
)
create_cross_references!
(
p
,
a
,
preexisting
)
end
private
# Returns a Hash of changed mentionable fields
#
# Preference is given to the `changes` Hash, but falls back to
# `previous_changes` if it's empty (i.e., the changes have already been
# persisted).
#
# See ActiveModel::Dirty.
#
# Returns a Hash.
def
detect_mentionable_changes
source
=
(
changes
.
present?
?
changes
:
previous_changes
).
dup
mentionable
=
self
.
class
.
mentionable_attrs
# Only include changed fields that are mentionable
source
.
select
{
|
key
,
val
|
mentionable
.
include?
(
key
)
}
end
end
app/models/note.rb
View file @
6114aedf
...
...
@@ -356,7 +356,7 @@ class Note < ActiveRecord::Base
end
def
set_references
notice_added_references
(
project
,
author
)
create_new_cross_references!
(
project
,
author
)
end
def
editable?
...
...
app/services/issues/update_service.rb
View file @
6114aedf
...
...
@@ -35,7 +35,7 @@ module Issues
create_title_change_note
(
issue
,
issue
.
previous_changes
[
'title'
].
first
)
end
issue
.
notice_added_references
(
issue
.
project
,
current_user
)
issue
.
create_new_cross_references!
(
issue
.
project
,
current_user
)
execute_hooks
(
issue
,
'update'
)
end
...
...
app/services/merge_requests/update_service.rb
View file @
6114aedf
...
...
@@ -59,7 +59,7 @@ module MergeRequests
merge_request
.
mark_as_unchecked
end
merge_request
.
notice_added_references
(
merge_request
.
project
,
current_user
)
merge_request
.
create_new_cross_references!
(
merge_request
.
project
,
current_user
)
execute_hooks
(
merge_request
,
'update'
)
end
...
...
spec/models/concerns/mentionable_spec.rb
View file @
6114aedf
...
...
@@ -28,4 +28,53 @@ describe Issue, "Mentionable" do
issue
.
create_cross_references!
(
project
,
author
,
[
commit2
])
end
end
describe
'#create_new_cross_references!'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:issues
)
{
create_list
(
:issue
,
2
,
project:
project
)
}
context
'before changes are persisted'
do
it
'ignores pre-existing references'
do
issue
=
create_issue
(
description:
issues
[
0
].
to_reference
)
expect
(
SystemNoteService
).
not_to
receive
(
:cross_reference
)
issue
.
description
=
'New description'
issue
.
create_new_cross_references!
end
it
'notifies new references'
do
issue
=
create_issue
(
description:
issues
[
0
].
to_reference
)
expect
(
SystemNoteService
).
to
receive
(
:cross_reference
).
with
(
issues
[
1
],
any_args
)
issue
.
description
=
issues
[
1
].
to_reference
issue
.
create_new_cross_references!
end
end
context
'after changes are persisted'
do
it
'ignores pre-existing references'
do
issue
=
create_issue
(
description:
issues
[
0
].
to_reference
)
expect
(
SystemNoteService
).
not_to
receive
(
:cross_reference
)
issue
.
update_attributes
(
description:
'New description'
)
issue
.
create_new_cross_references!
end
it
'notifies new references'
do
issue
=
create_issue
(
description:
issues
[
0
].
to_reference
)
expect
(
SystemNoteService
).
to
receive
(
:cross_reference
).
with
(
issues
[
1
],
any_args
)
issue
.
update_attributes
(
description:
issues
[
1
].
to_reference
)
issue
.
create_new_cross_references!
end
end
def
create_issue
(
description
:)
create
(
:issue
,
project:
project
,
description:
description
)
end
end
end
spec/support/mentionable_shared_examples.rb
View file @
6114aedf
...
...
@@ -143,6 +143,6 @@ shared_examples 'an editable mentionable' do
end
set_mentionable_text
.
call
(
new_text
)
subject
.
notice_added_references
(
project
,
author
)
subject
.
create_new_cross_references!
(
project
,
author
)
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