Fix bug in personal snippet thread discussions

In personal snippets, there is a bug when starting a
thread, the visual component to response is not displayed.

This is because the object `@snippet` is not set in the
controller and we end up in a policy check without object.
parent a6080c29
......@@ -23,7 +23,7 @@ class Snippets::NotesController < ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def snippet
PersonalSnippet.find_by(id: params[:snippet_id])
@snippet ||= PersonalSnippet.find_by(id: params[:snippet_id])
end
# rubocop: enable CodeReuse/ActiveRecord
alias_method :noteable, :snippet
......
---
title: Fix bug in personal snippet thread discussions
merge_request: 52490
author:
type: fixed
......@@ -4,15 +4,34 @@ require 'spec_helper'
RSpec.describe 'Thread Comments Snippet', :js do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:snippet) { create(:project_snippet, :private, :repository, project: project, author: user) }
before do
project.add_maintainer(user)
sign_in(user)
end
context 'with project snippets' do
let_it_be(:project) do
create(:project).tap do |p|
p.add_maintainer(user)
end
end
let_it_be(:snippet) { create(:project_snippet, :private, :repository, project: project, author: user) }
before do
visit project_snippet_path(project, snippet)
end
visit project_snippet_path(project, snippet)
it_behaves_like 'thread comments', 'snippet'
end
it_behaves_like 'thread comments', 'snippet'
context 'with personal snippets' do
let_it_be(:snippet) { create(:personal_snippet, :private, :repository, author: user) }
before do
visit snippet_path(snippet)
end
it_behaves_like 'thread comments', 'snippet'
end
end
......@@ -150,12 +150,13 @@ RSpec.shared_examples 'thread comments' do |resource_name|
wait_for_requests
end
it 'clicking "Start thread" will post a thread' do
it 'clicking "Start thread" will post a thread and show a reply component' do
expect(page).to have_content(comment)
new_comment = all(comments_selector).last
expect(new_comment).to have_selector('.discussion')
expect(new_comment).to have_css('.discussion-with-resolve-btn')
end
if resource_name =~ /(issue|merge request)/
......
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