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
6149dba5
Commit
6149dba5
authored
Jun 17, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove NotesObserver
parent
a7f3672b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
81 deletions
+51
-81
app/controllers/projects/notes_controller.rb
app/controllers/projects/notes_controller.rb
+1
-1
app/models/note.rb
app/models/note.rb
+5
-0
app/observers/note_observer.rb
app/observers/note_observer.rb
+0
-20
app/services/notes/create_service.rb
app/services/notes/create_service.rb
+17
-2
config/application.rb
config/application.rb
+1
-2
spec/observers/note_observer_spec.rb
spec/observers/note_observer_spec.rb
+0
-56
spec/services/notes/create_service_spec.rb
spec/services/notes/create_service_spec.rb
+27
-0
No files found.
app/controllers/projects/notes_controller.rb
View file @
6149dba5
...
...
@@ -21,7 +21,7 @@ class Projects::NotesController < Projects::ApplicationController
end
def
create
@note
=
Notes
::
CreateService
.
new
(
project
,
current_user
,
params
).
execute
@note
=
Notes
::
CreateService
.
new
(
project
,
current_user
,
params
[
:note
]
).
execute
respond_to
do
|
format
|
format
.
json
{
render_note_json
(
@note
)
}
...
...
app/models/note.rb
View file @
6149dba5
...
...
@@ -57,6 +57,7 @@ class Note < ActiveRecord::Base
serialize
:st_diff
before_create
:set_diff
,
if:
->
(
n
)
{
n
.
line_code
.
present?
}
after_update
:set_references
class
<<
self
def
create_status_change_note
(
noteable
,
project
,
author
,
status
,
source
)
...
...
@@ -314,4 +315,8 @@ class Note < ActiveRecord::Base
order
(
'id DESC'
).
limit
(
100
).
update_all
(
updated_at:
Time
.
now
)
end
def
set_references
notice_added_references
(
project
,
author
)
end
end
app/observers/note_observer.rb
deleted
100644 → 0
View file @
a7f3672b
class
NoteObserver
<
BaseObserver
def
after_create
(
note
)
notification
.
new_note
(
note
)
# Skip system notes, like status changes and cross-references.
unless
note
.
system
event_service
.
leave_note
(
note
,
note
.
author
)
# Create a cross-reference note if this Note contains GFM that names an
# issue, merge request, or commit.
note
.
references
.
each
do
|
mentioned
|
Note
.
create_cross_reference_note
(
mentioned
,
note
.
noteable
,
note
.
author
,
note
.
project
)
end
end
end
def
after_update
(
note
)
note
.
notice_added_references
(
note
.
project
,
note
.
author
)
end
end
app/services/notes/create_service.rb
View file @
6149dba5
module
Notes
class
CreateService
<
BaseService
def
execute
note
=
project
.
notes
.
new
(
params
[
:note
]
)
note
=
project
.
notes
.
new
(
params
)
note
.
author
=
current_user
note
.
system
=
false
note
.
save
if
note
.
save
notification_service
.
new_note
(
note
)
# Skip system notes, like status changes and cross-references.
unless
note
.
system
event_service
.
leave_note
(
note
,
note
.
author
)
# Create a cross-reference note if this Note contains GFM that names an
# issue, merge request, or commit.
note
.
references
.
each
do
|
mentioned
|
Note
.
create_cross_reference_note
(
mentioned
,
note
.
noteable
,
note
.
author
,
note
.
project
)
end
end
end
note
end
end
...
...
config/application.rb
View file @
6149dba5
...
...
@@ -19,8 +19,7 @@ module Gitlab
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
config
.
active_record
.
observers
=
:note_observer
,
:system_hook_observer
,
config
.
active_record
.
observers
=
:system_hook_observer
,
:user_observer
,
:users_project_observer
...
...
spec/observers/note_observer_spec.rb
deleted
100644 → 0
View file @
a7f3672b
require
'spec_helper'
describe
NoteObserver
do
subject
{
NoteObserver
.
instance
}
before
{
subject
.
stub
(
notification:
double
(
'NotificationService'
).
as_null_object
)
}
let
(
:team_without_author
)
{
(
1
..
2
).
map
{
|
n
|
double
:user
,
id:
n
}
}
let
(
:note
)
{
double
(
:note
).
as_null_object
}
describe
'#after_create'
do
it
'is called after a note is created'
do
subject
.
should_receive
:after_create
Note
.
observers
.
enable
:note_observer
do
create
(
:note
)
end
end
it
'sends out notifications'
do
subject
.
should_receive
(
:notification
)
subject
.
after_create
(
note
)
end
it
'creates cross-reference notes as appropriate'
do
@p
=
create
(
:project
)
@referenced
=
create
(
:issue
,
project:
@p
)
@referencer
=
create
(
:issue
,
project:
@p
)
@author
=
create
(
:user
)
Note
.
should_receive
(
:create_cross_reference_note
).
with
(
@referenced
,
@referencer
,
@author
,
@p
)
Note
.
observers
.
enable
:note_observer
do
create
(
:note
,
project:
@p
,
author:
@author
,
noteable:
@referencer
,
note:
"Duplicate of #
#{
@referenced
.
iid
}
"
)
end
end
it
"doesn't cross-reference system notes"
do
Note
.
should_receive
(
:create_cross_reference_note
).
once
Note
.
observers
.
enable
:note_observer
do
Note
.
create_cross_reference_note
(
create
(
:issue
),
create
(
:issue
))
end
end
end
describe
'#after_update'
do
it
'checks for new cross-references'
do
note
.
should_receive
(
:notice_added_references
)
subject
.
after_update
(
note
)
end
end
end
spec/services/notes/create_service_spec.rb
0 → 100644
View file @
6149dba5
require
'spec_helper'
describe
Notes
::
CreateService
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:user
)
{
create
(
:user
)
}
describe
:execute
do
context
"valid params"
do
before
do
project
.
team
<<
[
user
,
:master
]
opts
=
{
note:
'Awesome comment'
,
description:
'please fix'
,
noteable_type:
'Issue'
,
noteable_id:
issue
.
id
}
@note
=
Notes
::
CreateService
.
new
(
project
,
user
,
opts
).
execute
end
it
{
@note
.
should
be_valid
}
it
{
@note
.
note
.
should
==
'Awesome comment'
}
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