Commit 96b128aa authored by Arturo Herrero's avatar Arturo Herrero

Merge branch 'fj-fix-bug-rendering-snippet-activity' into 'master'

Fix bug rendering snippet activity

See merge request gitlab-org/gitlab!53993
parents ebcdf105 692d396f
...@@ -178,8 +178,8 @@ module EventsHelper ...@@ -178,8 +178,8 @@ module EventsHelper
def event_note_target_url(event) def event_note_target_url(event)
if event.commit_note? if event.commit_note?
project_commit_url(event.project, event.note_target, anchor: dom_id(event.target)) project_commit_url(event.project, event.note_target, anchor: dom_id(event.target))
elsif event.project_snippet_note? elsif event.snippet_note?
project_snippet_url(event.project, event.note_target, anchor: dom_id(event.target)) gitlab_snippet_url(event.note_target, anchor: dom_id(event.target))
elsif event.issue_note? elsif event.issue_note?
project_issue_url(event.project, id: event.note_target, anchor: dom_id(event.target)) project_issue_url(event.project, id: event.note_target, anchor: dom_id(event.target))
elsif event.merge_request_note? elsif event.merge_request_note?
......
...@@ -294,10 +294,14 @@ class Event < ApplicationRecord ...@@ -294,10 +294,14 @@ class Event < ApplicationRecord
note? && target && target.for_merge_request? note? && target && target.for_merge_request?
end end
def project_snippet_note? def snippet_note?
note? && target && target.for_snippet? note? && target && target.for_snippet?
end end
def project_snippet_note?
note? && target && target.for_project_snippet?
end
def personal_snippet_note? def personal_snippet_note?
note? && target && target.for_personal_snippet? note? && target && target.for_personal_snippet?
end end
......
...@@ -259,6 +259,10 @@ class Note < ApplicationRecord ...@@ -259,6 +259,10 @@ class Note < ApplicationRecord
noteable_type == 'AlertManagement::Alert' noteable_type == 'AlertManagement::Alert'
end end
def for_project_snippet?
noteable.is_a?(ProjectSnippet)
end
def for_personal_snippet? def for_personal_snippet?
noteable.is_a?(PersonalSnippet) noteable.is_a?(PersonalSnippet)
end end
......
---
title: Fix bug rendering snippet activity
merge_request: 53993
author:
type: fixed
...@@ -200,7 +200,13 @@ RSpec.describe EventsHelper do ...@@ -200,7 +200,13 @@ RSpec.describe EventsHelper do
it 'returns a project snippet note url' do it 'returns a project snippet note url' do
event.target = create(:note_on_project_snippet, note: 'keep going') event.target = create(:note_on_project_snippet, note: 'keep going')
expect(subject).to eq("#{project_base_url}/-/snippets/#{event.note_target.id}#note_#{event.target.id}") expect(subject).to eq("#{project_snippet_url(event.note_target.project, event.note_target)}#note_#{event.target.id}")
end
it 'returns a personal snippet note url' do
event.target = create(:note_on_personal_snippet, note: 'keep going')
expect(subject).to eq("#{snippet_url(event.note_target)}#note_#{event.target.id}")
end end
it 'returns a project issue url' do it 'returns a project issue url' do
......
...@@ -907,6 +907,58 @@ RSpec.describe Event do ...@@ -907,6 +907,58 @@ RSpec.describe Event do
end end
end end
context 'with snippet note' do
let_it_be(:user) { create(:user) }
let_it_be(:note_on_project_snippet) { create(:note_on_project_snippet, author: user) }
let_it_be(:note_on_personal_snippet) { create(:note_on_personal_snippet, author: user) }
let_it_be(:other_note) { create(:note_on_issue, author: user)}
let_it_be(:personal_snippet_event) { create(:event, :commented, project: nil, target: note_on_personal_snippet, author: user) }
let_it_be(:project_snippet_event) { create(:event, :commented, project: note_on_project_snippet.project, target: note_on_project_snippet, author: user) }
let_it_be(:other_event) { create(:event, :commented, project: other_note.project, target: other_note, author: user) }
describe '#snippet_note?' do
it 'returns true for a project snippet event' do
expect(project_snippet_event.snippet_note?).to be true
end
it 'returns true for a personal snippet event' do
expect(personal_snippet_event.snippet_note?).to be true
end
it 'returns false for a other kinds of event' do
expect(other_event.snippet_note?).to be false
end
end
describe '#personal_snippet_note?' do
it 'returns false for a project snippet event' do
expect(project_snippet_event.personal_snippet_note?).to be false
end
it 'returns true for a personal snippet event' do
expect(personal_snippet_event.personal_snippet_note?).to be true
end
it 'returns false for a other kinds of event' do
expect(other_event.personal_snippet_note?).to be false
end
end
describe '#project_snippet_note?' do
it 'returns true for a project snippet event' do
expect(project_snippet_event.project_snippet_note?).to be true
end
it 'returns false for a personal snippet event' do
expect(personal_snippet_event.project_snippet_note?).to be false
end
it 'returns false for a other kinds of event' do
expect(other_event.project_snippet_note?).to be false
end
end
end
describe '#action_name' do describe '#action_name' do
it 'handles all valid design events' do it 'handles all valid design events' do
created, updated, destroyed, archived = %i[created updated destroyed archived].map do |trait| created, updated, destroyed, archived = %i[created updated destroyed archived].map do |trait|
......
...@@ -837,6 +837,16 @@ RSpec.describe Note do ...@@ -837,6 +837,16 @@ RSpec.describe Note do
end end
end end
describe '#for_project_snippet?' do
it 'returns true for a project snippet note' do
expect(build(:note_on_project_snippet).for_project_snippet?).to be true
end
it 'returns false for a personal snippet note' do
expect(build(:note_on_personal_snippet).for_project_snippet?).to be false
end
end
describe '#for_personal_snippet?' do describe '#for_personal_snippet?' do
it 'returns false for a project snippet note' do it 'returns false for a project snippet note' do
expect(build(:note_on_project_snippet).for_personal_snippet?).to be_falsy expect(build(:note_on_project_snippet).for_personal_snippet?).to be_falsy
......
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