2012-10-10 00:25:29 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe NoteObserver do
|
|
|
|
subject { NoteObserver.instance }
|
|
|
|
|
2012-10-13 22:46:27 +02:00
|
|
|
let(:team_without_author) { (1..2).map { |n| double :user, id: n } }
|
|
|
|
|
2012-10-10 00:25:29 +02:00
|
|
|
describe '#after_create' do
|
2012-10-13 22:46:27 +02:00
|
|
|
let(:note) { double :note }
|
2012-10-10 00:25:29 +02:00
|
|
|
|
|
|
|
it 'is called after a note is created' do
|
|
|
|
subject.should_receive :after_create
|
|
|
|
|
|
|
|
Note.observers.enable :note_observer do
|
2012-11-06 04:31:55 +01:00
|
|
|
create(:note)
|
2012-10-10 00:25:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-13 22:46:27 +02:00
|
|
|
it 'sends out notifications' do
|
|
|
|
subject.should_receive(:send_notify_mails).with(note)
|
|
|
|
|
|
|
|
subject.after_create(note)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#send_notify_mails" do
|
|
|
|
let(:note) { double :note, notify: false, notify_author: false }
|
|
|
|
|
2012-10-10 00:25:29 +02:00
|
|
|
it 'notifies team of new note when flagged to notify' do
|
|
|
|
note.stub(:notify).and_return(true)
|
2012-10-13 22:46:27 +02:00
|
|
|
subject.should_receive(:notify_team).with(note)
|
2012-10-10 00:25:29 +02:00
|
|
|
|
|
|
|
subject.after_create(note)
|
|
|
|
end
|
2012-10-13 22:46:27 +02:00
|
|
|
|
2012-10-10 00:25:29 +02:00
|
|
|
it 'does not notify team of new note when not flagged to notify' do
|
2012-10-13 22:46:27 +02:00
|
|
|
subject.should_not_receive(:notify_team).with(note)
|
2012-10-10 00:25:29 +02:00
|
|
|
|
|
|
|
subject.after_create(note)
|
|
|
|
end
|
2012-10-13 22:46:27 +02:00
|
|
|
|
2012-10-10 00:25:29 +02:00
|
|
|
it 'notifies the author of a commit when flagged to notify the author' do
|
|
|
|
note.stub(:notify_author).and_return(true)
|
2013-01-15 15:36:35 +01:00
|
|
|
note.stub(:noteable).and_return(double(author_email: 'test@test.com'))
|
2012-10-10 00:25:29 +02:00
|
|
|
note.stub(:id).and_return(42)
|
2013-01-15 15:36:35 +01:00
|
|
|
author = double :user, id: 1, email: 'test@test.com'
|
2012-10-10 00:25:29 +02:00
|
|
|
note.stub(:commit_author).and_return(author)
|
2013-01-09 07:14:05 +01:00
|
|
|
Notify.should_receive(:note_commit_email)
|
2012-10-10 00:25:29 +02:00
|
|
|
|
|
|
|
subject.after_create(note)
|
|
|
|
end
|
2012-10-13 22:46:27 +02:00
|
|
|
|
2012-10-10 00:25:29 +02:00
|
|
|
it 'does not notify the author of a commit when not flagged to notify the author' do
|
2013-01-09 07:14:05 +01:00
|
|
|
notify.should_not_receive(:note_commit_email)
|
2012-10-10 00:25:29 +02:00
|
|
|
|
|
|
|
subject.after_create(note)
|
|
|
|
end
|
2012-10-13 22:46:27 +02:00
|
|
|
|
2012-10-10 00:25:29 +02:00
|
|
|
it 'does nothing if no notify flags are set' do
|
|
|
|
subject.after_create(note).should be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-13 22:46:27 +02:00
|
|
|
describe '#notify_team' do
|
2012-10-10 00:25:29 +02:00
|
|
|
let(:note) { double :note, id: 1 }
|
|
|
|
|
|
|
|
before :each do
|
|
|
|
subject.stub(:team_without_note_author).with(note).and_return(team_without_author)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'notifies team of a new note on' do
|
|
|
|
it 'a commit' do
|
|
|
|
note.stub(:noteable_type).and_return('Commit')
|
2013-01-09 07:14:05 +01:00
|
|
|
notify.should_receive(:note_commit_email).twice
|
2012-10-10 00:25:29 +02:00
|
|
|
|
2012-10-13 22:46:27 +02:00
|
|
|
subject.send(:notify_team, note)
|
2012-10-10 00:25:29 +02:00
|
|
|
end
|
2012-10-13 22:46:27 +02:00
|
|
|
|
2012-10-10 00:25:29 +02:00
|
|
|
it 'an issue' do
|
|
|
|
note.stub(:noteable_type).and_return('Issue')
|
2013-01-09 07:14:05 +01:00
|
|
|
notify.should_receive(:note_issue_email).twice
|
2012-10-10 00:25:29 +02:00
|
|
|
|
2012-10-13 22:46:27 +02:00
|
|
|
subject.send(:notify_team, note)
|
2012-10-10 00:25:29 +02:00
|
|
|
end
|
2012-10-13 22:46:27 +02:00
|
|
|
|
2012-10-10 00:25:29 +02:00
|
|
|
it 'a wiki page' do
|
|
|
|
note.stub(:noteable_type).and_return('Wiki')
|
2013-01-09 07:14:05 +01:00
|
|
|
notify.should_receive(:note_wiki_email).twice
|
2012-10-10 00:25:29 +02:00
|
|
|
|
2012-10-13 22:46:27 +02:00
|
|
|
subject.send(:notify_team, note)
|
2012-10-10 00:25:29 +02:00
|
|
|
end
|
2012-10-13 22:46:27 +02:00
|
|
|
|
2012-10-10 00:25:29 +02:00
|
|
|
it 'a merge request' do
|
|
|
|
note.stub(:noteable_type).and_return('MergeRequest')
|
2013-01-09 07:14:05 +01:00
|
|
|
notify.should_receive(:note_merge_request_email).twice
|
2012-10-10 00:25:29 +02:00
|
|
|
|
2012-10-13 22:46:27 +02:00
|
|
|
subject.send(:notify_team, note)
|
2012-10-10 00:25:29 +02:00
|
|
|
end
|
2012-10-13 22:46:27 +02:00
|
|
|
|
2012-10-10 00:25:29 +02:00
|
|
|
it 'a wall' do
|
2012-10-13 22:46:27 +02:00
|
|
|
# Note: wall posts have #noteable_type of nil
|
2012-10-13 20:37:36 +02:00
|
|
|
note.stub(:noteable_type).and_return(nil)
|
2013-01-09 07:14:05 +01:00
|
|
|
notify.should_receive(:note_wall_email).twice
|
2012-10-10 00:25:29 +02:00
|
|
|
|
2012-10-13 22:46:27 +02:00
|
|
|
subject.send(:notify_team, note)
|
2012-10-10 00:25:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does nothing for a new note on a snippet' do
|
2013-01-09 07:14:05 +01:00
|
|
|
note.stub(:noteable_type).and_return('Snippet')
|
2012-10-10 00:25:29 +02:00
|
|
|
|
2013-01-09 07:14:05 +01:00
|
|
|
subject.send(:notify_team, note).should be_nil
|
2012-10-10 00:25:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
describe '#team_without_note_author' do
|
|
|
|
let(:author) { double :user, id: 4 }
|
|
|
|
|
|
|
|
let(:users) { team_without_author + [author] }
|
|
|
|
let(:project) { double :project, users: users }
|
|
|
|
let(:note) { double :note, project: project, author: author }
|
|
|
|
|
|
|
|
it 'returns the projects user without the note author included' do
|
|
|
|
subject.send(:team_without_note_author, note).should == team_without_author
|
|
|
|
end
|
|
|
|
end
|
2013-01-09 07:14:05 +01:00
|
|
|
|
|
|
|
def notify
|
|
|
|
Notify
|
|
|
|
end
|
2012-10-10 00:25:29 +02:00
|
|
|
end
|