Commit 3950b8e8 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #1680 from robbkidd/reduce_note_observer_complexity

Reduce complexity: replace case statement with method lookup.
parents baf94bd7 378fe076
......@@ -16,16 +16,11 @@ class NoteObserver < ActiveRecord::Observer
protected
def notify_team_of_new_note(note)
notify_method = 'note_' + note.noteable_type.underscore + '_email'
if Notify.respond_to? notify_method
team_without_note_author(note).map do |u|
case note.noteable_type
when "Commit"; Notify.note_commit_email(u.id, note.id).deliver
when "Issue"; Notify.note_issue_email(u.id, note.id).deliver
when "Wiki"; Notify.note_wiki_email(u.id, note.id).deliver
when "MergeRequest"; Notify.note_merge_request_email(u.id, note.id).deliver
when "Wall"; Notify.note_wall_email(u.id, note.id).deliver
when "Snippet"; true # no notifications for snippets?
else
true
Notify.send(notify_method.to_sym, u.id, note.id).deliver
end
end
end
......
......@@ -90,7 +90,7 @@ describe NoteObserver do
it 'does nothing for a new note on a snippet' do
note.stub(:noteable_type).and_return('Snippet')
subject.send(:notify_team_of_new_note, note).should == [true, true]
subject.send(:notify_team_of_new_note, note).should be_nil
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment