Commit 378fe076b6d6bf6d6808a7336a25ebeb3eca7683
1 parent
baf94bd7
Exists in
master
and in
4 other branches
Reduce complexity: replace case statement with method lookup.
Showing
2 changed files
with
6 additions
and
11 deletions
Show diff stats
app/observers/note_observer.rb
@@ -16,16 +16,11 @@ class NoteObserver < ActiveRecord::Observer | @@ -16,16 +16,11 @@ class NoteObserver < ActiveRecord::Observer | ||
16 | protected | 16 | protected |
17 | 17 | ||
18 | def notify_team_of_new_note(note) | 18 | def notify_team_of_new_note(note) |
19 | - team_without_note_author(note).map do |u| | ||
20 | - case note.noteable_type | ||
21 | - when "Commit"; Notify.note_commit_email(u.id, note.id).deliver | ||
22 | - when "Issue"; Notify.note_issue_email(u.id, note.id).deliver | ||
23 | - when "Wiki"; Notify.note_wiki_email(u.id, note.id).deliver | ||
24 | - when "MergeRequest"; Notify.note_merge_request_email(u.id, note.id).deliver | ||
25 | - when "Wall"; Notify.note_wall_email(u.id, note.id).deliver | ||
26 | - when "Snippet"; true # no notifications for snippets? | ||
27 | - else | ||
28 | - true | 19 | + notify_method = 'note_' + note.noteable_type.underscore + '_email' |
20 | + | ||
21 | + if Notify.respond_to? notify_method | ||
22 | + team_without_note_author(note).map do |u| | ||
23 | + Notify.send(notify_method.to_sym, u.id, note.id).deliver | ||
29 | end | 24 | end |
30 | end | 25 | end |
31 | end | 26 | end |
spec/observers/note_observer_spec.rb
@@ -90,7 +90,7 @@ describe NoteObserver do | @@ -90,7 +90,7 @@ describe NoteObserver do | ||
90 | it 'does nothing for a new note on a snippet' do | 90 | it 'does nothing for a new note on a snippet' do |
91 | note.stub(:noteable_type).and_return('Snippet') | 91 | note.stub(:noteable_type).and_return('Snippet') |
92 | 92 | ||
93 | - subject.send(:notify_team_of_new_note, note).should == [true, true] | 93 | + subject.send(:notify_team_of_new_note, note).should be_nil |
94 | end | 94 | end |
95 | end | 95 | end |
96 | 96 |