diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/broadcast_message_spec.rb | 37 | ||||
-rw-r--r-- | spec/models/members/project_member_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 26 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 23 | ||||
-rw-r--r-- | spec/models/remote_mirror_spec.rb | 39 |
5 files changed, 122 insertions, 7 deletions
diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb index 5326f9cb8c0..d6e5b557870 100644 --- a/spec/models/broadcast_message_spec.rb +++ b/spec/models/broadcast_message_spec.rb @@ -58,6 +58,12 @@ describe BroadcastMessage do end end + it 'does not create new records' do + create(:broadcast_message) + + expect { described_class.current }.not_to change { described_class.count } + end + it 'includes messages that need to be displayed in the future' do create(:broadcast_message) @@ -77,9 +83,37 @@ describe BroadcastMessage do it 'does not clear the cache if only a future message should be displayed' do create(:broadcast_message, :future) - expect(Rails.cache).not_to receive(:delete) + expect(Rails.cache).not_to receive(:delete).with(described_class::CACHE_KEY) expect(described_class.current.length).to eq(0) end + + it 'clears the legacy cache key' do + create(:broadcast_message, :future) + + expect(Rails.cache).to receive(:delete).with(described_class::LEGACY_CACHE_KEY) + expect(described_class.current.length).to eq(0) + end + + it 'gracefully handles bad cache entry' do + allow(described_class).to receive(:current_and_future_messages).and_return('{') + + expect(described_class.current).to be_empty + end + + it 'gracefully handles an empty hash' do + allow(described_class).to receive(:current_and_future_messages).and_return('{}') + + expect(described_class.current).to be_empty + end + + it 'gracefully handles unknown attributes' do + message = create(:broadcast_message) + + allow(described_class).to receive(:current_and_future_messages) + .and_return([{ bad_attr: 1 }, message]) + + expect(described_class.current).to eq([message]) + end end describe '#active?' do @@ -143,6 +177,7 @@ describe BroadcastMessage do message = create(:broadcast_message) expect(Rails.cache).to receive(:delete).with(described_class::CACHE_KEY) + expect(Rails.cache).to receive(:delete).with(described_class::LEGACY_CACHE_KEY) message.flush_redis_cache end diff --git a/spec/models/members/project_member_spec.rb b/spec/models/members/project_member_spec.rb index 097b1bb30dc..99d3ab41b97 100644 --- a/spec/models/members/project_member_spec.rb +++ b/spec/models/members/project_member_spec.rb @@ -11,10 +11,6 @@ describe ProjectMember do it { is_expected.to validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) } end - describe 'modules' do - it { is_expected.to include_module(Gitlab::ShellAdapter) } - end - describe '.access_level_roles' do it 'returns Gitlab::Access.options' do expect(described_class.access_level_roles).to eq(Gitlab::Access.options) diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 9b60054e14a..bf4117fbcaf 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -1339,6 +1339,30 @@ describe MergeRequest do end end + describe '#calculate_reactive_cache' do + let(:project) { create(:project, :repository) } + let(:merge_request) { create(:merge_request, source_project: project) } + subject { merge_request.calculate_reactive_cache(service_class_name) } + + context 'when given an unknown service class name' do + let(:service_class_name) { 'Integer' } + + it 'raises a NameError exception' do + expect { subject }.to raise_error(NameError, service_class_name) + end + end + + context 'when given a known service class name' do + let(:service_class_name) { 'Ci::CompareTestReportsService' } + + it 'does not raises a NameError exception' do + allow_any_instance_of(service_class_name.constantize).to receive(:execute).and_return(nil) + + expect { subject }.not_to raise_error(NameError) + end + end + end + describe '#compare_test_reports' do subject { merge_request.compare_test_reports } @@ -1885,7 +1909,7 @@ describe MergeRequest do allow(subject).to receive(:head_pipeline) { nil } end - it { expect(subject.mergeable_ci_state?).to be_falsey } + it { expect(subject.mergeable_ci_state?).to be_truthy } end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 9e5b06b745a..5e63f14b720 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -4102,6 +4102,29 @@ describe Project do end end + describe '#object_pool_params' do + let(:project) { create(:project, :repository, :public) } + + subject { project.object_pool_params } + + before do + stub_application_setting(hashed_storage_enabled: true) + end + + context 'when the objects cannot be pooled' do + let(:project) { create(:project, :repository, :private) } + + it { is_expected.to be_empty } + end + + context 'when a pool is created' do + it 'returns that pool repository' do + expect(subject).not_to be_empty + expect(subject[:pool_repository]).to be_persisted + end + end + end + describe '#git_objects_poolable?' do subject { project } diff --git a/spec/models/remote_mirror_spec.rb b/spec/models/remote_mirror_spec.rb index b12ca79847c..5d3c25062d5 100644 --- a/spec/models/remote_mirror_spec.rb +++ b/spec/models/remote_mirror_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe RemoteMirror do +describe RemoteMirror, :mailer do include GitHelpers describe 'URL validation' do @@ -137,6 +137,43 @@ describe RemoteMirror do end end + describe '#mark_as_failed' do + let(:remote_mirror) { create(:remote_mirror) } + let(:error_message) { 'http://user:pass@test.com/root/repoC.git/' } + let(:sanitized_error_message) { 'http://*****:*****@test.com/root/repoC.git/' } + + subject do + remote_mirror.update_start + remote_mirror.mark_as_failed(error_message) + end + + it 'sets the update_status to failed' do + subject + + expect(remote_mirror.reload.update_status).to eq('failed') + end + + it 'saves the sanitized error' do + subject + + expect(remote_mirror.last_error).to eq(sanitized_error_message) + end + + context 'notifications' do + let(:user) { create(:user) } + + before do + remote_mirror.project.add_maintainer(user) + end + + it 'notifies the project maintainers' do + perform_enqueued_jobs { subject } + + should_email(user) + end + end + end + context 'when remote mirror gets destroyed' do it 'removes remote' do mirror = create_mirror(url: 'http://foo:bar@test.com') |