Commit 378fe076 authored by Robb Kidd's avatar Robb Kidd

Reduce complexity: replace case statement with method lookup.

parent baf94bd7
...@@ -16,16 +16,11 @@ class NoteObserver < ActiveRecord::Observer ...@@ -16,16 +16,11 @@ class NoteObserver < ActiveRecord::Observer
protected protected
def notify_team_of_new_note(note) 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| team_without_note_author(note).map do |u|
case note.noteable_type Notify.send(notify_method.to_sym, u.id, note.id).deliver
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
end end
end end
end end
......
...@@ -90,7 +90,7 @@ describe NoteObserver do ...@@ -90,7 +90,7 @@ describe NoteObserver do
it 'does nothing for a new note on a snippet' do it 'does nothing for a new note on a snippet' do
note.stub(:noteable_type).and_return('Snippet') 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
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