OSDN Git Service

API: get a single note
authorNihad Abbasov <narkoz.2008@gmail.com>
Thu, 29 Nov 2012 19:33:41 +0000 (11:33 -0800)
committerNihad Abbasov <narkoz.2008@gmail.com>
Thu, 29 Nov 2012 20:11:00 +0000 (12:11 -0800)
lib/api/notes.rb
spec/requests/api/notes_spec.rb

index 9b39ff4..84b6beb 100644 (file)
@@ -33,6 +33,21 @@ module Gitlab
           @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"])
           present paginate(@noteable.notes), with: Entities::Note
         end
+
+        # Get a single +noteable+ note
+        #
+        # Parameters:
+        #   id (required) - The ID or code name of a project
+        #   noteable_id (required) - The ID of an issue or snippet
+        #   note_id (required) - The ID of a note
+        # Example Request:
+        #   GET /projects/:id/issues/:noteable_id/notes/:note_id
+        #   GET /projects/:id/snippets/:noteable_id/notes/:note_id
+        get ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do
+          @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"])
+          @note = @noteable.notes.find(params[:note_id])
+          present @note, with: Entities::Note
+        end
       end
     end
   end
index 1d42921..175d405 100644 (file)
@@ -32,7 +32,7 @@ describe Gitlab::API do
 
   describe "GET /projects/:id/noteable/:noteable_id/notes" do
     context "when noteable is an Issue" do
-      it "should return an array of notes" do
+      it "should return an array of issue notes" do
         get api("/projects/#{project.id}/issues/#{issue.id}/notes", user)
         response.status.should == 200
         json_response.should be_an Array
@@ -41,7 +41,7 @@ describe Gitlab::API do
     end
 
     context "when noteable is a Snippet" do
-      it "should return an array of notes" do
+      it "should return an array of snippet notes" do
         get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
         response.status.should == 200
         json_response.should be_an Array
@@ -49,4 +49,22 @@ describe Gitlab::API do
       end
     end
   end
+
+  describe "GET /projects/:id/noteable/:noteable_id/notes/:note_id" do
+    context "when noteable is an Issue" do
+      it "should return an issue note by id" do
+        get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", user)
+        response.status.should == 200
+        json_response['body'].should == issue_note.note
+      end
+    end
+
+    context "when noteable is a Snippet" do
+      it "should return a snippet note by id" do
+        get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user)
+        response.status.should == 200
+        json_response['body'].should == snippet_note.note
+      end
+    end
+  end
 end