diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-28 15:06:57 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-28 15:06:57 +0000 |
commit | 7cdd70dcec27402e89e65451b4b1feb75b5eb267 (patch) | |
tree | 1691c8e1afd469fa426ecf5bc127de8df16d4855 /spec/models | |
parent | 79348faced5e7e62103ad27f6a6594dfdca463e2 (diff) | |
download | gitlab-ce-7cdd70dcec27402e89e65451b4b1feb75b5eb267.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/merge_request_spec.rb | 15 | ||||
-rw-r--r-- | spec/models/note_spec.rb | 62 |
2 files changed, 59 insertions, 18 deletions
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 79ea29c84a4..f3d270cdf7e 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -33,6 +33,21 @@ describe MergeRequest do end end + describe '.from_and_to_forks' do + it 'returns only MRs from and to forks (with no internal MRs)' do + project = create(:project) + fork = fork_project(project) + fork_2 = fork_project(project) + mr_from_fork = create(:merge_request, source_project: fork, target_project: project) + mr_to_fork = create(:merge_request, source_project: project, target_project: fork) + + create(:merge_request, source_project: fork, target_project: fork_2) + create(:merge_request, source_project: project, target_project: project) + + expect(described_class.from_and_to_forks(project)).to contain_exactly(mr_from_fork, mr_to_fork) + end + end + describe 'locking' do using RSpec::Parameterized::TableSyntax 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 |