diff options
author | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-09-16 14:30:28 +0200 |
---|---|---|
committer | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-09-16 14:30:28 +0200 |
commit | a9d638d371adcd853a07e1f11a075b5e1e2c653c (patch) | |
tree | 0e3e7527b0e4034551ffd17cbb5eb8d50c167717 | |
parent | 065341bf04958b862db9cc2891c7822a3da7f7f8 (diff) | |
download | gitlab-ce-22256-nomethoderror-api-entities-note-missing-attribute-note-on-awardemoji-0x00000015142480.tar.gz |
Fix API notes endpoint when posting only emoji22256-nomethoderror-api-entities-note-missing-attribute-note-on-awardemoji-0x00000015142480
-rw-r--r-- | doc/api/notes.md | 7 | ||||
-rw-r--r-- | lib/api/notes.rb | 14 | ||||
-rw-r--r-- | spec/requests/api/notes_spec.rb | 9 |
3 files changed, 24 insertions, 6 deletions
diff --git a/doc/api/notes.md b/doc/api/notes.md index 85d140d06ac..49422fb09d9 100644 --- a/doc/api/notes.md +++ b/doc/api/notes.md @@ -78,7 +78,8 @@ Parameters: ### Create new issue note -Creates a new note to a single project issue. +Creates a new note to a single project issue. If you create a note where the body +only contains an Award Emoji, you'll receive this object back. ``` POST /projects/:id/issues/:issue_id/notes @@ -158,6 +159,7 @@ Example Response: ### List all snippet notes Gets a list of all notes for a single snippet. Snippet notes are comments users can post to a snippet. +If you create a note where the body only contains an Award Emoji, you'll receive this object back. ``` GET /projects/:id/snippets/:snippet_id/notes @@ -204,6 +206,7 @@ Parameters: ### Create new snippet note Creates a new note for a single snippet. Snippet notes are comments users can post to a snippet. +If you create a note where the body only contains an Award Emoji, you'll receive this object back. ``` POST /projects/:id/snippets/:snippet_id/notes @@ -332,6 +335,8 @@ Parameters: ### Create new merge request note Creates a new note for a single merge request. +If you create a note where the body only contains an Award Emoji, you'll receive +this object back. ``` POST /projects/:id/merge_requests/:merge_request_id/notes diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 8bfa998dc53..038da030061 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -83,12 +83,16 @@ module API opts[:created_at] = params[:created_at] end - @note = ::Notes::CreateService.new(user_project, current_user, opts).execute - - if @note.valid? - present @note, with: Entities::Note + note = ::Notes::CreateService.new(user_project, current_user, opts).execute + + if note.valid? + if note.is_a?(Note) + present note, with: Entities::Note + else + present note, with: Entities::AwardEmoji + end else - not_found!("Note #{@note.errors.messages}") + not_found!("Note #{note.errors.messages}") end end diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb index 223444ea39f..063a8706e76 100644 --- a/spec/requests/api/notes_spec.rb +++ b/spec/requests/api/notes_spec.rb @@ -220,6 +220,15 @@ describe API::API, api: true do expect(Time.parse(json_response['created_at'])).to be_within(1.second).of(creation_time) end end + + context 'when the user is posting an award emoji' do + it 'returns an award emoji' do + post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: ':+1:' + + expect(response).to have_http_status(201) + expect(json_response['awardable_id']).to eq issue.id + end + end end context "when noteable is a Snippet" do |