2012-02-28 09:01:14 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ActivityObserver do
|
2012-11-05 22:31:55 -05:00
|
|
|
let(:project) { create(:project) }
|
2012-02-28 09:01:14 -05:00
|
|
|
|
2013-05-30 19:16:49 -04:00
|
|
|
before { Thread.current[:current_user] = create(:user) }
|
|
|
|
|
2012-02-28 09:48:15 -05:00
|
|
|
def self.it_should_be_valid_event
|
|
|
|
it { @event.should_not be_nil }
|
|
|
|
it { @event.project.should == project }
|
|
|
|
end
|
|
|
|
|
2012-11-05 22:31:55 -05:00
|
|
|
describe "Issue created" do
|
2012-06-12 14:27:03 -04:00
|
|
|
before do
|
|
|
|
Issue.observers.enable :activity_observer do
|
2012-11-05 22:31:55 -05:00
|
|
|
@issue = create(:issue, project: project)
|
2012-06-12 14:27:03 -04:00
|
|
|
@event = Event.last
|
|
|
|
end
|
2012-02-28 09:01:14 -05:00
|
|
|
end
|
|
|
|
|
2012-02-28 09:48:15 -05:00
|
|
|
it_should_be_valid_event
|
2013-02-13 06:48:16 -05:00
|
|
|
it { @event.action.should == Event::CREATED }
|
2012-02-28 09:01:14 -05:00
|
|
|
it { @event.target.should == @issue }
|
|
|
|
end
|
|
|
|
|
2012-12-14 15:05:10 -05:00
|
|
|
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
|
2013-02-13 06:48:16 -05:00
|
|
|
it { @event.action.should == Event::COMMENTED }
|
2012-12-14 15:05:10 -05:00
|
|
|
it { @event.target.should == @note }
|
|
|
|
end
|
2013-05-30 19:16:49 -04:00
|
|
|
|
|
|
|
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
|
2012-02-28 09:01:14 -05:00
|
|
|
end
|