From 7339464e7701c0778cca12c12ace83ebd8ffe2f7 Mon Sep 17 00:00:00 2001
From: Jacob Vosmaer <contact@jacobvosmaer.nl>
Date: Mon, 28 Apr 2014 11:53:37 +0200
Subject: [PATCH] Fail faster on an invalid target_type

---
 app/finders/notes_finder.rb       | 2 ++
 spec/finders/notes_finder_spec.rb | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb
index 384316e14b7..4e80bd81757 100644
--- a/app/finders/notes_finder.rb
+++ b/app/finders/notes_finder.rb
@@ -12,6 +12,8 @@ class NotesFinder
       project.merge_requests.find(target_id).mr_and_commit_notes.inc_author.fresh
     when "snippet"
       project.snippets.find(target_id).notes.fresh
+    else
+      raise 'invalid target_type'
     end
   end
 end
diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb
index 3b28070ffaa..27eaba8dfa1 100644
--- a/spec/finders/notes_finder_spec.rb
+++ b/spec/finders/notes_finder_spec.rb
@@ -22,5 +22,10 @@ describe NotesFinder do
       notes = NotesFinder.new.execute(project, user, params)
       notes.size.should eq(2)
     end
+
+    it 'should raise an exception for an invalid target_type' do
+      params = { target_id: commit.id, target_type: 'invalid' }
+      expect { NotesFinder.new.execute(project, user, params) }.to raise_error('invalid target_type')
+    end
   end
 end
-- 
GitLab