diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-08 13:33:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-08 13:33:01 +0300 |
commit | 6edb7e9bb152d919c215f35bd6cb7d52fd3d99be (patch) | |
tree | f12ef4b7953932f9b2b9c28313277bf636115bc8 /spec/models | |
parent | 305ea394efd2d5afe16234406dede486d9ca37af (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-ee
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/legacy_diff_note_spec.rb | 42 | ||||
-rw-r--r-- | spec/models/protected_branch_spec.rb | 17 |
2 files changed, 53 insertions, 6 deletions
diff --git a/spec/models/legacy_diff_note_spec.rb b/spec/models/legacy_diff_note_spec.rb index ee3bbf186b9..8934fe6b107 100644 --- a/spec/models/legacy_diff_note_spec.rb +++ b/spec/models/legacy_diff_note_spec.rb @@ -8,4 +8,46 @@ RSpec.describe LegacyDiffNote do it { is_expected.to eq('note') } end + + describe 'callbacks' do + describe '#set_diff' do + let(:note) do + build(:legacy_diff_note_on_merge_request, st_diff: '_st_diff_').tap do |record| + record.instance_variable_set(:@diff, {}) + end + end + + context 'when not importing' do + it 'updates st_diff' do + note.save!(validate: false) + + expect(note.st_diff).to eq({}) + end + end + + context 'when importing' do + before do + note.importing = true + end + + it 'does not update st_diff' do + note.save!(validate: false) + + expect(note.st_diff).to eq('_st_diff_') + end + + context 'when st_diff is blank' do + before do + note.st_diff = nil + end + + it 'updates st_diff' do + note.save!(validate: false) + + expect(note.st_diff).to eq({}) + end + end + end + end + end end diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb index 587a9683a8e..f7c723cd134 100644 --- a/spec/models/protected_branch_spec.rb +++ b/spec/models/protected_branch_spec.rb @@ -163,27 +163,32 @@ RSpec.describe ProtectedBranch do expect(described_class.protected?(project, 'staging/some-branch')).to eq(false) end + it 'returns false when branch name is nil' do + expect(described_class.protected?(project, nil)).to eq(false) + end + context 'with caching', :use_clean_rails_memory_store_caching do let_it_be(:project) { create(:project, :repository) } - let_it_be(:protected_branch) { create(:protected_branch, project: project, name: "jawn") } + let_it_be(:protected_branch) { create(:protected_branch, project: project, name: "“jawn”") } before do - allow(described_class).to receive(:matching).once.and_call_original + allow(described_class).to receive(:matching).with(protected_branch.name, protected_refs: anything).once.and_call_original + # the original call works and warms the cache - described_class.protected?(project, 'jawn') + described_class.protected?(project, protected_branch.name) end it 'correctly invalidates a cache' do - expect(described_class).to receive(:matching).once.and_call_original + expect(described_class).to receive(:matching).with(protected_branch.name, protected_refs: anything).once.and_call_original create(:protected_branch, project: project, name: "bar") # the cache is invalidated because the project has been "updated" - expect(described_class.protected?(project, 'jawn')).to eq(true) + expect(described_class.protected?(project, protected_branch.name)).to eq(true) end it 'correctly uses the cached version' do expect(described_class).not_to receive(:matching) - expect(described_class.protected?(project, 'jawn')).to eq(true) + expect(described_class.protected?(project, protected_branch.name)).to eq(true) end end end |