note_observer_spec.rb 1.52 KB
Newer Older
1 2 3 4
require 'spec_helper'

describe NoteObserver do
  subject { NoteObserver.instance }
skv's avatar
skv committed
5
  before { subject.stub(notification: double('NotificationService').as_null_object) }
6

7
  let(:team_without_author) { (1..2).map { |n| double :user, id: n } }
8
  let(:note) { double(:note).as_null_object }
9

10 11 12 13 14 15
  describe '#after_create' do

    it 'is called after a note is created' do
      subject.should_receive :after_create

      Note.observers.enable :note_observer do
16
        create(:note)
17 18 19
      end
    end

20
    it 'sends out notifications' do
21
      subject.should_receive(:notification)
22 23 24

      subject.after_create(note)
    end
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

    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
55
  end
56
end