summaryrefslogtreecommitdiff
path: root/spec/observers/activity_observer_spec.rb
blob: dc14ab86b6d8e5716da8404c922ab290b26df4b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
55
56
57
58
59
60
61
require 'spec_helper'

describe ActivityObserver do
  let(:project)  { create(:project) }

  before { Thread.current[:current_user] = create(:user) }

  def self.it_should_be_valid_event
    it { @event.should_not be_nil }
    it { @event.project.should == project }
  end

  describe "Issue created" do
    before do
      Issue.observers.enable :activity_observer do
        @issue = create(:issue, project: project)
        @event = Event.last
      end
    end

    it_should_be_valid_event
    it { @event.action.should == Event::CREATED }
    it { @event.target.should == @issue }
  end

  describe "Issue commented" do
    before do
      Note.observers.enable :activity_observer do
        @issue = create(:issue, project: project)
        @note = create(:note, noteable: @issue, project: project, author: @issue.author)
        @event = Event.last
      end
    end

    it_should_be_valid_event
    it { @event.action.should == Event::COMMENTED }
    it { @event.target.should == @note }
  end

  describe "Ignore system notes" do
    let(:author) { create(:user) }
    let!(:issue) { create(:issue, project: project) }
    let!(:other) { create(:issue) }

    it "should not create events for status change notes" do
      expect do
        Note.observers.enable :activity_observer do
          Note.create_status_change_note(issue, project, author, 'reopened', nil)
        end
      end.to_not change { Event.count }
    end

    it "should not create events for cross-reference notes" do
      expect do
        Note.observers.enable :activity_observer do
          Note.create_cross_reference_note(issue, other, author, issue.project)
        end
      end.to_not change { Event.count }
    end
  end
end