From 378fe076b6d6bf6d6808a7336a25ebeb3eca7683 Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Thu, 11 Oct 2012 13:27:58 -0400 Subject: [PATCH] Reduce complexity: replace case statement with method lookup. --- app/observers/note_observer.rb | 15 +++++---------- spec/observers/note_observer_spec.rb | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/observers/note_observer.rb b/app/observers/note_observer.rb index 84484856..3d51b9c2 100644 --- a/app/observers/note_observer.rb +++ b/app/observers/note_observer.rb @@ -16,16 +16,11 @@ class NoteObserver < ActiveRecord::Observer protected def notify_team_of_new_note(note) - 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_method = 'note_' + note.noteable_type.underscore + '_email' + + if Notify.respond_to? notify_method + team_without_note_author(note).map do |u| + Notify.send(notify_method.to_sym, u.id, note.id).deliver end end end diff --git a/spec/observers/note_observer_spec.rb b/spec/observers/note_observer_spec.rb index fd211789..3538cf04 100644 --- a/spec/observers/note_observer_spec.rb +++ b/spec/observers/note_observer_spec.rb @@ -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