Remove NotesObserver
This commit is contained in:
parent
a7f3672b75
commit
6149dba518
|
@ -21,7 +21,7 @@ class Projects::NotesController < Projects::ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
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|
|
respond_to do |format|
|
||||||
format.json { render_note_json(@note) }
|
format.json { render_note_json(@note) }
|
||||||
|
|
|
@ -57,6 +57,7 @@ class Note < ActiveRecord::Base
|
||||||
|
|
||||||
serialize :st_diff
|
serialize :st_diff
|
||||||
before_create :set_diff, if: ->(n) { n.line_code.present? }
|
before_create :set_diff, if: ->(n) { n.line_code.present? }
|
||||||
|
after_update :set_references
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def create_status_change_note(noteable, project, author, status, source)
|
def create_status_change_note(noteable, project, author, status, source)
|
||||||
|
@ -314,4 +315,8 @@ class Note < ActiveRecord::Base
|
||||||
order('id DESC').limit(100).
|
order('id DESC').limit(100).
|
||||||
update_all(updated_at: Time.now)
|
update_all(updated_at: Time.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_references
|
||||||
|
notice_added_references(project, author)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
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
|
|
|
@ -1,10 +1,25 @@
|
||||||
module Notes
|
module Notes
|
||||||
class CreateService < BaseService
|
class CreateService < BaseService
|
||||||
def execute
|
def execute
|
||||||
note = project.notes.new(params[:note])
|
note = project.notes.new(params)
|
||||||
note.author = current_user
|
note.author = current_user
|
||||||
note.system = false
|
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
|
note
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,8 +19,7 @@ module Gitlab
|
||||||
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
||||||
|
|
||||||
# Activate observers that should always be running.
|
# Activate observers that should always be running.
|
||||||
config.active_record.observers = :note_observer,
|
config.active_record.observers = :system_hook_observer,
|
||||||
:system_hook_observer,
|
|
||||||
:user_observer,
|
:user_observer,
|
||||||
:users_project_observer
|
:users_project_observer
|
||||||
|
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
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
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue