summaryrefslogtreecommitdiff
path: root/spec/models/note_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-28 15:06:57 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-28 15:06:57 +0000
commit7cdd70dcec27402e89e65451b4b1feb75b5eb267 (patch)
tree1691c8e1afd469fa426ecf5bc127de8df16d4855 /spec/models/note_spec.rb
parent79348faced5e7e62103ad27f6a6594dfdca463e2 (diff)
downloadgitlab-ce-7cdd70dcec27402e89e65451b4b1feb75b5eb267.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/note_spec.rb')
-rw-r--r--spec/models/note_spec.rb62
1 files changed, 44 insertions, 18 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 74f2fc1bb61..a6d9ecaa7c5 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -1048,20 +1048,20 @@ describe Note do
describe 'expiring ETag cache' do
let(:note) { build(:note_on_issue) }
- def expect_expiration(note)
+ def expect_expiration(noteable)
expect_any_instance_of(Gitlab::EtagCaching::Store)
.to receive(:touch)
- .with("/#{note.project.namespace.to_param}/#{note.project.to_param}/noteable/issue/#{note.noteable.id}/notes")
+ .with("/#{noteable.project.namespace.to_param}/#{noteable.project.to_param}/noteable/#{noteable.class.name.underscore}/#{noteable.id}/notes")
end
it "expires cache for note's issue when note is saved" do
- expect_expiration(note)
+ expect_expiration(note.noteable)
note.save!
end
it "expires cache for note's issue when note is destroyed" do
- expect_expiration(note)
+ expect_expiration(note.noteable)
note.destroy!
end
@@ -1076,28 +1076,54 @@ describe Note do
end
end
- describe '#with_notes_filter' do
- let!(:comment) { create(:note) }
- let!(:system_note) { create(:note, system: true) }
+ context 'for merge requests' do
+ let_it_be(:merge_request) { create(:merge_request) }
- context 'when notes filter is nil' do
- subject { described_class.with_notes_filter(nil) }
+ context 'when adding a note to the MR' do
+ let(:note) { build(:note, noteable: merge_request, project: merge_request.project) }
- it { is_expected.to include(comment, system_note) }
+ it 'expires the MR note etag cache' do
+ expect_expiration(merge_request)
+
+ note.save!
+ end
end
- context 'when notes filter is set to all notes' do
- subject { described_class.with_notes_filter(UserPreference::NOTES_FILTERS[:all_notes]) }
+ context 'when adding a note to a commit on the MR' do
+ let(:note) { build(:note_on_commit, commit_id: merge_request.commits.first.id, project: merge_request.project) }
- it { is_expected.to include(comment, system_note) }
+ it 'expires the MR note etag cache' do
+ expect_expiration(merge_request)
+
+ note.save!
+ end
end
+ end
+ end
- context 'when notes filter is set to only comments' do
- subject { described_class.with_notes_filter(UserPreference::NOTES_FILTERS[:only_comments]) }
+ describe '#with_notes_filter' do
+ let!(:comment) { create(:note) }
+ let!(:system_note) { create(:note, system: true) }
- it { is_expected.to include(comment) }
- it { is_expected.not_to include(system_note) }
- end
+ subject { described_class.with_notes_filter(filter) }
+
+ context 'when notes filter is nil' do
+ let(:filter) { nil }
+
+ it { is_expected.to include(comment, system_note) }
+ end
+
+ context 'when notes filter is set to all notes' do
+ let(: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
+ let(:filter) { UserPreference::NOTES_FILTERS[:only_comments] }
+
+ it { is_expected.to include(comment) }
+ it { is_expected.not_to include(system_note) }
end
end