Commit a540f55c authored by Douwe Maan's avatar Douwe Maan

Fix specs

parent b181d312
...@@ -89,7 +89,7 @@ module NotesActions ...@@ -89,7 +89,7 @@ module NotesActions
if note.persisted? if note.persisted?
attrs[:valid] = true attrs[:valid] = true
if noteable.discussions_rendered_on_frontend? if noteable.nil? || noteable.discussions_rendered_on_frontend?
attrs.merge!(note_serializer.represent(note)) attrs.merge!(note_serializer.represent(note))
else else
attrs.merge!( attrs.merge!(
......
...@@ -300,7 +300,7 @@ class Note < ActiveRecord::Base ...@@ -300,7 +300,7 @@ class Note < ActiveRecord::Base
end end
def expire_etag_cache def expire_etag_cache
return unless noteable.discussions_rendered_on_frontend? return unless noteable&.discussions_rendered_on_frontend?
key = Gitlab::Routing.url_helpers.project_noteable_notes_path( key = Gitlab::Routing.url_helpers.project_noteable_notes_path(
project, project,
......
...@@ -14,8 +14,8 @@ class NoteEntity < API::Entities::Note ...@@ -14,8 +14,8 @@ class NoteEntity < API::Entities::Note
expose :redacted_note_html, as: :note_html expose :redacted_note_html, as: :note_html
expose :last_edited_at, if: -> (note, _) { note.is_edited? } expose :last_edited_at, if: -> (note, _) { note.edited? }
expose :last_edited_by, using: NoteUserEntity, if: -> (note, _) { note.is_edited? } expose :last_edited_by, using: NoteUserEntity, if: -> (note, _) { note.edited? }
expose :current_user do expose :current_user do
expose :can_edit do |note| expose :can_edit do |note|
......
...@@ -46,10 +46,13 @@ describe Projects::NotesController do ...@@ -46,10 +46,13 @@ describe Projects::NotesController do
end end
context 'for a discussion note' do context 'for a discussion note' do
let!(:note) { create(:discussion_note_on_issue, noteable: issue, project: project) } let(:project) { create(:project, :repository) }
let!(:note) { create(:discussion_note_on_merge_request, project: project) }
let(:params) { request_params.merge(target_type: 'merge_request', target_id: note.noteable_id) }
it 'responds with the expected attributes' do it 'responds with the expected attributes' do
get :index, request_params get :index, params
expect(note_json[:id]).to eq(note.id) expect(note_json[:id]).to eq(note.id)
expect(note_json[:discussion_html]).not_to be_nil expect(note_json[:discussion_html]).not_to be_nil
...@@ -104,10 +107,12 @@ describe Projects::NotesController do ...@@ -104,10 +107,12 @@ describe Projects::NotesController do
end end
context 'for a regular note' do context 'for a regular note' do
let!(:note) { create(:note, noteable: issue, project: project) } let!(:note) { create(:note_on_merge_request, project: project) }
let(:params) { request_params.merge(target_type: 'merge_request', target_id: note.noteable_id) }
it 'responds with the expected attributes' do it 'responds with the expected attributes' do
get :index, request_params get :index, params
expect(note_json[:id]).to eq(note.id) expect(note_json[:id]).to eq(note.id)
expect(note_json[:html]).not_to be_nil expect(note_json[:html]).not_to be_nil
...@@ -125,7 +130,9 @@ describe Projects::NotesController do ...@@ -125,7 +130,9 @@ describe Projects::NotesController do
note: { note: 'some note', noteable_id: merge_request.id, noteable_type: 'MergeRequest' }, note: { note: 'some note', noteable_id: merge_request.id, noteable_type: 'MergeRequest' },
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
merge_request_diff_head_sha: 'sha' merge_request_diff_head_sha: 'sha',
target_type: 'merge_request',
target_id: merge_request.id
} }
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment