Commit 1c5aa848ce6141b8679e167171096055dc7f4df3
1 parent
9a4974b7
Exists in
master
and in
4 other branches
API: get a single note
Showing
2 changed files
with
35 additions
and
2 deletions
Show diff stats
lib/api/notes.rb
@@ -33,6 +33,21 @@ module Gitlab | @@ -33,6 +33,21 @@ module Gitlab | ||
33 | @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"]) | 33 | @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"]) |
34 | present paginate(@noteable.notes), with: Entities::Note | 34 | present paginate(@noteable.notes), with: Entities::Note |
35 | end | 35 | end |
36 | + | ||
37 | + # Get a single +noteable+ note | ||
38 | + # | ||
39 | + # Parameters: | ||
40 | + # id (required) - The ID or code name of a project | ||
41 | + # noteable_id (required) - The ID of an issue or snippet | ||
42 | + # note_id (required) - The ID of a note | ||
43 | + # Example Request: | ||
44 | + # GET /projects/:id/issues/:noteable_id/notes/:note_id | ||
45 | + # GET /projects/:id/snippets/:noteable_id/notes/:note_id | ||
46 | + get ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do | ||
47 | + @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"]) | ||
48 | + @note = @noteable.notes.find(params[:note_id]) | ||
49 | + present @note, with: Entities::Note | ||
50 | + end | ||
36 | end | 51 | end |
37 | end | 52 | end |
38 | end | 53 | end |
spec/requests/api/notes_spec.rb
@@ -32,7 +32,7 @@ describe Gitlab::API do | @@ -32,7 +32,7 @@ describe Gitlab::API do | ||
32 | 32 | ||
33 | describe "GET /projects/:id/noteable/:noteable_id/notes" do | 33 | describe "GET /projects/:id/noteable/:noteable_id/notes" do |
34 | context "when noteable is an Issue" do | 34 | context "when noteable is an Issue" do |
35 | - it "should return an array of notes" do | 35 | + it "should return an array of issue notes" do |
36 | get api("/projects/#{project.id}/issues/#{issue.id}/notes", user) | 36 | get api("/projects/#{project.id}/issues/#{issue.id}/notes", user) |
37 | response.status.should == 200 | 37 | response.status.should == 200 |
38 | json_response.should be_an Array | 38 | json_response.should be_an Array |
@@ -41,7 +41,7 @@ describe Gitlab::API do | @@ -41,7 +41,7 @@ describe Gitlab::API do | ||
41 | end | 41 | end |
42 | 42 | ||
43 | context "when noteable is a Snippet" do | 43 | context "when noteable is a Snippet" do |
44 | - it "should return an array of notes" do | 44 | + it "should return an array of snippet notes" do |
45 | get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user) | 45 | get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user) |
46 | response.status.should == 200 | 46 | response.status.should == 200 |
47 | json_response.should be_an Array | 47 | json_response.should be_an Array |
@@ -49,4 +49,22 @@ describe Gitlab::API do | @@ -49,4 +49,22 @@ describe Gitlab::API do | ||
49 | end | 49 | end |
50 | end | 50 | end |
51 | end | 51 | end |
52 | + | ||
53 | + describe "GET /projects/:id/noteable/:noteable_id/notes/:note_id" do | ||
54 | + context "when noteable is an Issue" do | ||
55 | + it "should return an issue note by id" do | ||
56 | + get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", user) | ||
57 | + response.status.should == 200 | ||
58 | + json_response['body'].should == issue_note.note | ||
59 | + end | ||
60 | + end | ||
61 | + | ||
62 | + context "when noteable is a Snippet" do | ||
63 | + it "should return a snippet note by id" do | ||
64 | + get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user) | ||
65 | + response.status.should == 200 | ||
66 | + json_response['body'].should == snippet_note.note | ||
67 | + end | ||
68 | + end | ||
69 | + end | ||
52 | end | 70 | end |