summaryrefslogtreecommitdiff
path: root/spec/models/note_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/note_spec.rb')
-rw-r--r--spec/models/note_spec.rb258
1 files changed, 129 insertions, 129 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 385b8a7959f..4e3e6477455 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -1,17 +1,17 @@
-require 'spec_helper'
+require "spec_helper"
describe Note do
include RepoHelpers
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:noteable).touch(false) }
- it { is_expected.to belong_to(:author).class_name('User') }
+ it { is_expected.to belong_to(:author).class_name("User") }
it { is_expected.to have_many(:todos) }
end
- describe 'modules' do
+ describe "modules" do
subject { described_class }
it { is_expected.to include_module(Participable) }
@@ -19,11 +19,11 @@ describe Note do
it { is_expected.to include_module(Awardable) }
end
- describe 'validation' do
+ describe "validation" do
it { is_expected.to validate_presence_of(:note) }
it { is_expected.to validate_presence_of(:project) }
- context 'when note is on commit' do
+ context "when note is on commit" do
before do
allow(subject).to receive(:for_commit?).and_return(true)
end
@@ -32,7 +32,7 @@ describe Note do
it { is_expected.not_to validate_presence_of(:noteable_id) }
end
- context 'when note is not on commit' do
+ context "when note is not on commit" do
before do
allow(subject).to receive(:for_commit?).and_return(false)
end
@@ -41,7 +41,7 @@ describe Note do
it { is_expected.to validate_presence_of(:noteable_id) }
end
- context 'when noteable and note project differ' do
+ context "when noteable and note project differ" do
subject do
build(:note, noteable: build_stubbed(:issue),
project: build_stubbed(:project))
@@ -50,20 +50,20 @@ describe Note do
it { is_expected.to be_invalid }
end
- context 'when noteable and note project are the same' do
+ context "when noteable and note project are the same" do
subject { create(:note) }
it { is_expected.to be_valid }
end
- context 'when project is missing for a project related note' do
+ context "when project is missing for a project related note" do
subject { build(:note, project: nil, noteable: build_stubbed(:issue)) }
it { is_expected.to be_invalid }
end
- context 'when noteable is a personal snippet' do
+ context "when noteable is a personal snippet" do
subject { build(:note_on_personal_snippet) }
- it 'is valid without project' do
+ it "is valid without project" do
is_expected.to be_valid
end
end
@@ -92,7 +92,7 @@ describe Note do
expect(note.project.repository.kept_around?(commit.id)).to be_truthy
end
- it 'does not generate N+1 queries for participants', :request_store do
+ it "does not generate N+1 queries for participants", :request_store do
def retrieve_participants
commit.notes_with_associations.map(&:participants).to_a
end
@@ -100,17 +100,17 @@ describe Note do
# Project authorization checks are cached, establish a baseline
retrieve_participants
- control_count = ActiveRecord::QueryRecorder.new do
+ control_count = ActiveRecord::QueryRecorder.new {
retrieve_participants
- end
+ }
- create(:note_on_commit, project: note.project, note: 'another note', noteable_id: commit.id)
+ create(:note_on_commit, project: note.project, note: "another note", noteable_id: commit.id)
expect { retrieve_participants }.not_to exceed_query_limit(control_count)
end
end
- describe 'authorization' do
+ describe "authorization" do
before do
@p1 = create(:project)
@p2 = create(:project)
@@ -119,7 +119,7 @@ describe Note do
@u3 = create(:user)
end
- describe 'read' do
+ describe "read" do
before do
@p1.project_members.create(user: @u2, access_level: ProjectMember::GUEST)
@p2.project_members.create(user: @u3, access_level: ProjectMember::GUEST)
@@ -130,7 +130,7 @@ describe Note do
it { expect(Ability.allowed?(@u3, :read_note, @p1)).to be_falsey }
end
- describe 'write' do
+ describe "write" do
before do
@p1.project_members.create(user: @u2, access_level: ProjectMember::DEVELOPER)
@p2.project_members.create(user: @u3, access_level: ProjectMember::DEVELOPER)
@@ -141,7 +141,7 @@ describe Note do
it { expect(Ability.allowed?(@u3, :create_note, @p1)).to be_falsey }
end
- describe 'admin' do
+ describe "admin" do
before do
@p1.project_members.create(user: @u1, access_level: ProjectMember::REPORTER)
@p1.project_members.create(user: @u2, access_level: ProjectMember::MAINTAINER)
@@ -154,7 +154,7 @@ describe Note do
end
end
- it_behaves_like 'an editable mentionable' do
+ it_behaves_like "an editable mentionable" do
subject { create :note, noteable: issue, project: issue.project }
let(:issue) { create(:issue, project: create(:project, :repository)) }
@@ -175,8 +175,8 @@ describe Note do
pipeline: :note,
cache_key: [note1, "note"],
project: note1.project,
- author: note1.author
- }
+ author: note1.author,
+ },
}]).and_call_original
expect(Banzai::Renderer).to receive(:cache_collection_render)
@@ -187,8 +187,8 @@ describe Note do
pipeline: :note,
cache_key: [note2, "note"],
project: note2.project,
- author: note2.author
- }
+ author: note2.author,
+ },
}]).and_call_original
note1.all_references.users
@@ -288,19 +288,19 @@ describe Note do
end
end
- describe '#cross_reference?' do
- it 'falsey for user-generated notes' do
+ describe "#cross_reference?" do
+ it "falsey for user-generated notes" do
note = create(:note, system: false)
expect(note.cross_reference?).to be_falsy
end
- context 'when the note might contain cross references' do
+ context "when the note might contain cross references" do
SystemNoteMetadata.new.cross_reference_types.each do |type|
let(:note) { create(:note, :system) }
let!(:metadata) { create(:system_note_metadata, note: note, action: type) }
- it 'delegates to the cross-reference regex' do
+ it "delegates to the cross-reference regex" do
expect(note).to receive(:matches_cross_reference_regex?).and_return(false)
note.cross_reference?
@@ -308,27 +308,27 @@ describe Note do
end
end
- context 'when the note cannot contain cross references' do
- let(:commit_note) { build(:note, note: 'mentioned in 1312312313 something else.', system: true) }
- let(:label_note) { build(:note, note: 'added ~2323232323', system: true) }
+ context "when the note cannot contain cross references" do
+ let(:commit_note) { build(:note, note: "mentioned in 1312312313 something else.", system: true) }
+ let(:label_note) { build(:note, note: "added ~2323232323", system: true) }
- it 'scan for a `mentioned in` prefix' do
+ it "scan for a `mentioned in` prefix" do
expect(commit_note.cross_reference?).to be_truthy
expect(label_note.cross_reference?).to be_falsy
end
end
end
- describe 'clear_blank_line_code!' do
- it 'clears a blank line code before validation' do
- note = build(:note, line_code: ' ')
+ describe "clear_blank_line_code!" do
+ it "clears a blank line code before validation" do
+ note = build(:note, line_code: " ")
expect { note.valid? }.to change(note, :line_code).to(nil)
end
end
- describe '#participants' do
- it 'includes the note author' do
+ describe "#participants" do
+ it "includes the note author" do
project = create(:project, :public)
issue = create(:issue, project: project)
note = create(:note_on_issue, noteable: issue, project: project)
@@ -337,12 +337,12 @@ describe Note do
end
end
- describe '.find_discussion' do
+ describe ".find_discussion" do
let!(:note) { create(:discussion_note_on_merge_request) }
let!(:note2) { create(:discussion_note_on_merge_request, in_reply_to: note) }
let(:merge_request) { note.noteable }
- it 'returns a discussion with multiple notes' do
+ it "returns a discussion with multiple notes" do
discussion = merge_request.notes.find_discussion(note.discussion_id)
expect(discussion).not_to be_nil
@@ -380,7 +380,7 @@ describe Note do
)
end
- context 'active diff discussions' do
+ context "active diff discussions" do
subject { merge_request.notes.grouped_diff_discussions }
it "includes active discussions" do
@@ -403,7 +403,7 @@ describe Note do
expect(subject[active_diff_note3.line_code].first.id).to eq(active_diff_note3.discussion_id)
end
- context 'with image discussions' do
+ context "with image discussions" do
let(:merge_request2) { create(:merge_request_with_diffs, :with_image_diffs, source_project: project, title: "Added images and changes") }
let(:image_path) { "files/images/ee_repo_logo.png" }
let(:text_path) { "bar/branch-test.txt" }
@@ -454,10 +454,10 @@ describe Note do
end
end
- context 'diff discussions for older diff refs' do
+ context "diff discussions for older diff refs" do
subject { merge_request.notes.grouped_diff_discussions(diff_refs) }
- context 'for diff refs a discussion was created at' do
+ context "for diff refs a discussion was created at" do
let(:diff_refs) { active_position2.diff_refs }
it "includes discussions that were created then" do
@@ -480,7 +480,7 @@ describe Note do
end
end
- context 'for diff refs a discussion was last active at' do
+ context "for diff refs a discussion was last active at" do
let(:diff_refs) { outdated_position.diff_refs }
it "includes discussions that were last active" do
@@ -505,123 +505,123 @@ describe Note do
end
end
- describe '#for_personal_snippet?' do
- it 'returns false for a project snippet note' do
+ describe "#for_personal_snippet?" do
+ it "returns false for a project snippet note" do
expect(build(:note_on_project_snippet).for_personal_snippet?).to be_falsy
end
- it 'returns true for a personal snippet note' do
+ it "returns true for a personal snippet note" do
expect(build(:note_on_personal_snippet).for_personal_snippet?).to be_truthy
end
end
- describe '#to_ability_name' do
- it 'returns snippet for a project snippet note' do
- expect(build(:note_on_project_snippet).to_ability_name).to eq('project_snippet')
+ describe "#to_ability_name" do
+ it "returns snippet for a project snippet note" do
+ expect(build(:note_on_project_snippet).to_ability_name).to eq("project_snippet")
end
- it 'returns personal_snippet for a personal snippet note' do
- expect(build(:note_on_personal_snippet).to_ability_name).to eq('personal_snippet')
+ it "returns personal_snippet for a personal snippet note" do
+ expect(build(:note_on_personal_snippet).to_ability_name).to eq("personal_snippet")
end
- it 'returns merge_request for an MR note' do
- expect(build(:note_on_merge_request).to_ability_name).to eq('merge_request')
+ it "returns merge_request for an MR note" do
+ expect(build(:note_on_merge_request).to_ability_name).to eq("merge_request")
end
- it 'returns issue for an issue note' do
- expect(build(:note_on_issue).to_ability_name).to eq('issue')
+ it "returns issue for an issue note" do
+ expect(build(:note_on_issue).to_ability_name).to eq("issue")
end
- it 'returns issue for a commit note' do
- expect(build(:note_on_commit).to_ability_name).to eq('commit')
+ it "returns issue for a commit note" do
+ expect(build(:note_on_commit).to_ability_name).to eq("commit")
end
end
- describe '#cache_markdown_field' do
- let(:html) { '<p>some html</p>'}
+ describe "#cache_markdown_field" do
+ let(:html) { "<p>some html</p>"}
- context 'note for a project snippet' do
+ context "note for a project snippet" do
let(:note) { build(:note_on_project_snippet) }
before do
expect(Banzai::Renderer).to receive(:cacheless_render_field)
- .with(note, :note, { skip_project_check: false }).and_return(html)
+ .with(note, :note, {skip_project_check: false}).and_return(html)
note.save
end
- it 'creates a note' do
+ it "creates a note" do
expect(note.note_html).to eq(html)
end
end
- context 'note for a personal snippet' do
+ context "note for a personal snippet" do
let(:note) { build(:note_on_personal_snippet) }
before do
expect(Banzai::Renderer).to receive(:cacheless_render_field)
- .with(note, :note, { skip_project_check: true }).and_return(html)
+ .with(note, :note, {skip_project_check: true}).and_return(html)
note.save
end
- it 'creates a note' do
+ it "creates a note" do
expect(note.note_html).to eq(html)
end
end
end
- describe '#can_be_discussion_note?' do
- context 'for a note on a merge request' do
- it 'returns true' do
+ describe "#can_be_discussion_note?" do
+ context "for a note on a merge request" do
+ it "returns true" do
note = build(:note_on_merge_request)
expect(note.can_be_discussion_note?).to be_truthy
end
end
- context 'for a note on an issue' do
- it 'returns true' do
+ context "for a note on an issue" do
+ it "returns true" do
note = build(:note_on_issue)
expect(note.can_be_discussion_note?).to be_truthy
end
end
- context 'for a note on a commit' do
- it 'returns true' do
+ context "for a note on a commit" do
+ it "returns true" do
note = build(:note_on_commit)
expect(note.can_be_discussion_note?).to be_truthy
end
end
- context 'for a note on a snippet' do
- it 'returns true' do
+ context "for a note on a snippet" do
+ it "returns true" do
note = build(:note_on_project_snippet)
expect(note.can_be_discussion_note?).to be_truthy
end
end
- context 'for a diff note on merge request' do
- it 'returns false' do
+ context "for a diff note on merge request" do
+ it "returns false" do
note = build(:diff_note_on_merge_request)
expect(note.can_be_discussion_note?).to be_falsey
end
end
- context 'for a diff note on commit' do
- it 'returns false' do
+ context "for a diff note on commit" do
+ it "returns false" do
note = build(:diff_note_on_commit)
expect(note.can_be_discussion_note?).to be_falsey
end
end
- context 'for a discussion note' do
- it 'returns false' do
+ context "for a discussion note" do
+ it "returns false" do
note = build(:discussion_note_on_merge_request)
expect(note.can_be_discussion_note?).to be_falsey
@@ -629,18 +629,18 @@ describe Note do
end
end
- describe '#discussion_class' do
+ describe "#discussion_class" do
let(:note) { build(:note_on_commit) }
let(:merge_request) { create(:merge_request) }
- context 'when the note is displayed out of context' do
- it 'returns OutOfContextDiscussion' do
+ context "when the note is displayed out of context" do
+ it "returns OutOfContextDiscussion" do
expect(note.discussion_class(merge_request)).to be(OutOfContextDiscussion)
end
end
- context 'when the note is displayed in the original context' do
- it 'returns IndividualNoteDiscussion' do
+ context "when the note is displayed in the original context" do
+ it "returns IndividualNoteDiscussion" do
expect(note.discussion_class(note.noteable)).to be(IndividualNoteDiscussion)
end
end
@@ -670,16 +670,16 @@ describe Note do
end
end
- context 'when the note is displayed out of context' do
+ context "when the note is displayed out of context" do
let(:merge_request) { create(:merge_request) }
- it 'overrides the discussion id' do
+ it "overrides the discussion id" do
expect(note.discussion_id(merge_request)).not_to eq(note.discussion_id)
end
end
end
- describe '#to_discussion' do
+ describe "#to_discussion" do
subject { create(:discussion_note_on_merge_request) }
let!(:note2) { create(:discussion_note_on_merge_request, project: subject.project, noteable: subject.noteable, in_reply_to: subject) }
@@ -695,7 +695,7 @@ describe Note do
let!(:note1) { create(:discussion_note_on_merge_request) }
let!(:note2) { create(:diff_note_on_merge_request, project: note1.project, noteable: note1.noteable) }
- context 'when the note is part of a discussion' do
+ context "when the note is part of a discussion" do
subject { create(:discussion_note_on_merge_request, project: note1.project, noteable: note1.noteable, in_reply_to: note1) }
it "returns the discussion this note is in" do
@@ -706,7 +706,7 @@ describe Note do
end
end
- context 'when the note is not part of a discussion' do
+ context "when the note is not part of a discussion" do
subject { create(:note) }
it "returns a discussion with just this note" do
@@ -719,38 +719,38 @@ describe Note do
end
describe "#part_of_discussion?" do
- context 'for a regular note' do
+ context "for a regular note" do
let(:note) { build(:note) }
- it 'returns false' do
+ it "returns false" do
expect(note.part_of_discussion?).to be_falsey
end
end
- context 'for a diff note' do
+ context "for a diff note" do
let(:note) { build(:diff_note_on_commit) }
- it 'returns true' do
+ it "returns true" do
expect(note.part_of_discussion?).to be_truthy
end
end
- context 'for a discussion note' do
+ context "for a discussion note" do
let(:note) { build(:discussion_note_on_merge_request) }
- it 'returns true' do
+ it "returns true" do
expect(note.part_of_discussion?).to be_truthy
end
end
end
- describe '#in_reply_to?' do
- context 'for a note' do
- context 'when part of a discussion' do
+ describe "#in_reply_to?" do
+ context "for a note" do
+ context "when part of a discussion" do
subject { create(:discussion_note_on_issue) }
let(:note) { create(:discussion_note_on_issue, in_reply_to: subject) }
- it 'checks if the note is in reply to the other discussion' do
+ it "checks if the note is in reply to the other discussion" do
expect(subject).to receive(:in_reply_to?).with(note).and_call_original
expect(subject).to receive(:in_reply_to?).with(note.noteable).and_call_original
expect(subject).to receive(:in_reply_to?).with(note.to_discussion).and_call_original
@@ -759,11 +759,11 @@ describe Note do
end
end
- context 'when not part of a discussion' do
+ context "when not part of a discussion" do
subject { create(:note) }
let(:note) { create(:note, in_reply_to: subject) }
- it 'checks if the note is in reply to the other noteable' do
+ it "checks if the note is in reply to the other noteable" do
expect(subject).to receive(:in_reply_to?).with(note).and_call_original
expect(subject).to receive(:in_reply_to?).with(note.noteable).and_call_original
@@ -772,50 +772,50 @@ describe Note do
end
end
- context 'for a discussion' do
- context 'when part of the same discussion' do
+ context "for a discussion" do
+ context "when part of the same discussion" do
subject { create(:diff_note_on_merge_request) }
let(:note) { create(:diff_note_on_merge_request, in_reply_to: subject) }
- it 'returns true' do
+ it "returns true" do
expect(subject.in_reply_to?(note.to_discussion)).to be_truthy
end
end
- context 'when not part of the same discussion' do
+ context "when not part of the same discussion" do
subject { create(:diff_note_on_merge_request) }
let(:note) { create(:diff_note_on_merge_request) }
- it 'returns false' do
+ it "returns false" do
expect(subject.in_reply_to?(note.to_discussion)).to be_falsey
end
end
end
- context 'for a noteable' do
- context 'when a comment on the same noteable' do
+ context "for a noteable" do
+ context "when a comment on the same noteable" do
subject { create(:note) }
let(:note) { create(:note, in_reply_to: subject) }
- it 'returns true' do
+ it "returns true" do
expect(subject.in_reply_to?(note.noteable)).to be_truthy
end
end
- context 'when not a comment on the same noteable' do
+ context "when not a comment on the same noteable" do
subject { create(:note) }
let(:note) { create(:note) }
- it 'returns false' do
+ it "returns false" do
expect(subject.in_reply_to?(note.noteable)).to be_falsey
end
end
end
end
- describe '#references' do
- context 'when part of a discussion' do
- it 'references all earlier notes in the discussion' do
+ describe "#references" do
+ context "when part of a discussion" do
+ it "references all earlier notes in the discussion" do
first_note = create(:discussion_note_on_issue)
second_note = create(:discussion_note_on_issue, in_reply_to: first_note)
third_note = create(:discussion_note_on_issue, in_reply_to: second_note)
@@ -825,17 +825,17 @@ describe Note do
end
end
- context 'when not part of a discussion' do
+ context "when not part of a discussion" do
subject { create(:note) }
let(:note) { create(:note, in_reply_to: subject) }
- it 'returns the noteable' do
+ it "returns the noteable" do
expect(note.references).to eq([note.noteable])
end
end
end
- describe 'expiring ETag cache' do
+ describe "expiring ETag cache" do
let(:note) { build(:note_on_issue) }
def expect_expiration(note)
@@ -856,8 +856,8 @@ describe Note do
note.destroy!
end
- context 'when issuable etag caching is disabled' do
- it 'does not store cache key' do
+ context "when issuable etag caching is disabled" do
+ it "does not store cache key" do
allow(note.noteable).to receive(:etag_caching_enabled?).and_return(false)
expect_any_instance_of(Gitlab::EtagCaching::Store).not_to receive(:touch)
@@ -866,23 +866,23 @@ describe Note do
end
end
- describe '#with_notes_filter' do
+ describe "#with_notes_filter" do
let!(:comment) { create(:note) }
let!(:system_note) { create(:note, system: true) }
- context 'when notes filter is nil' do
+ context "when notes filter is nil" do
subject { described_class.with_notes_filter(nil) }
it { is_expected.to include(comment, system_note) }
end
- context 'when notes filter is set to all notes' do
+ context "when notes filter is set to all notes" do
subject { described_class.with_notes_filter(UserPreference::NOTES_FILTERS[:all_notes]) }
it { is_expected.to include(comment, system_note) }
end
- context 'when notes filter is set to only comments' do
+ context "when notes filter is set to only comments" do
subject { described_class.with_notes_filter(UserPreference::NOTES_FILTERS[:only_comments]) }
it { is_expected.to include(comment) }
@@ -891,15 +891,15 @@ describe Note do
end
end
- describe '#parent' do
- it 'returns project for project notes' do
+ describe "#parent" do
+ it "returns project for project notes" do
project = create(:project)
note = create(:note_on_issue, project: project)
expect(note.parent).to eq(project)
end
- it 'returns nil for personal snippet note' do
+ it "returns nil for personal snippet note" do
note = create(:note_on_personal_snippet)
expect(note.parent).to be_nil