diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-30 15:09:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-30 15:09:48 +0300 |
commit | 96ee4961ce1984902f738ab651b99d2a1f01a65c (patch) | |
tree | 4add0def83c37189b44a15b203357303bba20582 /spec/models | |
parent | 4ac9f1b8eaef29daa484b27a3113505cfa6a6dcb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/error_tracking/error_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/protected_branch_spec.rb | 24 |
2 files changed, 42 insertions, 0 deletions
diff --git a/spec/models/error_tracking/error_spec.rb b/spec/models/error_tracking/error_spec.rb index 57899985daf..739ef1c10d4 100644 --- a/spec/models/error_tracking/error_spec.rb +++ b/spec/models/error_tracking/error_spec.rb @@ -16,6 +16,24 @@ RSpec.describe ErrorTracking::Error, type: :model do it { is_expected.to validate_presence_of(:actor) } end + describe '.report_error' do + it 'updates existing record with a new timestamp' do + timestamp = Time.zone.now + + reported_error = described_class.report_error( + name: error.name, + description: 'Lorem ipsum', + actor: error.actor, + platform: error.platform, + timestamp: timestamp + ) + + expect(reported_error.id).to eq(error.id) + expect(reported_error.last_seen_at).to eq(timestamp) + expect(reported_error.description).to eq('Lorem ipsum') + end + end + describe '#title' do it { expect(error.title).to eq('ActionView::MissingTemplate Missing template posts/edit') } end diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb index a173ab48f17..019c01af672 100644 --- a/spec/models/protected_branch_spec.rb +++ b/spec/models/protected_branch_spec.rb @@ -162,6 +162,30 @@ RSpec.describe ProtectedBranch do expect(described_class.protected?(project, 'staging/some-branch')).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") } + + before do + allow(described_class).to receive(:matching).once.and_call_original + # the original call works and warms the cache + described_class.protected?(project, 'jawn') + end + + it 'correctly invalidates a cache' do + expect(described_class).to receive(:matching).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) + end + + it 'correctly uses the cached version' do + expect(described_class).not_to receive(:matching) + expect(described_class.protected?(project, 'jawn')).to eq(true) + end + end end context 'new project' do |