summaryrefslogtreecommitdiff
path: root/spec/models/repository_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/repository_spec.rb')
-rw-r--r--spec/models/repository_spec.rb78
1 files changed, 55 insertions, 23 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index dd54a701282..3a4de7ba279 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -483,12 +483,6 @@ RSpec.describe Repository do
it { is_expected.to be_an_instance_of(::Blob) }
end
- context 'readme blob on HEAD' do
- subject { repository.blob_at(repository.head_commit.sha, 'README.md') }
-
- it { is_expected.to be_an_instance_of(::ReadmeBlob) }
- end
-
context 'readme blob not on HEAD' do
subject { repository.blob_at(repository.find_branch('feature').target, 'README.md') }
@@ -1142,11 +1136,11 @@ RSpec.describe Repository do
expect(repository.license_key).to be_nil
end
- it 'returns nil when the content is not recognizable' do
+ it 'returns other when the content is not recognizable' do
repository.create_file(user, 'LICENSE', 'Gitlab B.V.',
message: 'Add LICENSE', branch_name: 'master')
- expect(repository.license_key).to be_nil
+ expect(repository.license_key).to eq('other')
end
it 'returns nil when the commit SHA does not exist' do
@@ -1186,11 +1180,12 @@ RSpec.describe Repository do
expect(repository.license).to be_nil
end
- it 'returns nil when the content is not recognizable' do
+ it 'returns other when the content is not recognizable' do
+ license = Licensee::License.new('other')
repository.create_file(user, 'LICENSE', 'Gitlab B.V.',
message: 'Add LICENSE', branch_name: 'master')
- expect(repository.license).to be_nil
+ expect(repository.license).to eq(license)
end
it 'returns the license' do
@@ -1938,7 +1933,6 @@ RSpec.describe Repository do
expect(repository).to receive(:expire_method_caches).with([
:size,
:commit_count,
- :rendered_readme,
:readme_path,
:contribution_guide,
:changelog,
@@ -1955,8 +1949,8 @@ RSpec.describe Repository do
:root_ref,
:merged_branch_names,
:has_visible_content?,
- :issue_template_names,
- :merge_request_template_names,
+ :issue_template_names_by_category,
+ :merge_request_template_names_by_category,
:user_defined_metrics_dashboard_paths,
:xcode_project?,
:has_ambiguous_refs?
@@ -2314,14 +2308,6 @@ RSpec.describe Repository do
expect(repository.readme).to be_nil
end
end
-
- context 'when a README exists' do
- let(:project) { create(:project, :repository) }
-
- it 'returns the README' do
- expect(repository.readme).to be_an_instance_of(ReadmeBlob)
- end
- end
end
end
@@ -2527,9 +2513,8 @@ RSpec.describe Repository do
describe '#refresh_method_caches' do
it 'refreshes the caches of the given types' do
expect(repository).to receive(:expire_method_caches)
- .with(%i(rendered_readme readme_path license_blob license_key license))
+ .with(%i(readme_path license_blob license_key license))
- expect(repository).to receive(:rendered_readme)
expect(repository).to receive(:readme_path)
expect(repository).to receive(:license_blob)
expect(repository).to receive(:license_key)
@@ -3049,4 +3034,51 @@ RSpec.describe Repository do
end
end
end
+
+ describe '.pick_storage_shard', :request_store do
+ before do
+ storages = {
+ 'default' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/repositories'),
+ 'picked' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/repositories')
+ }
+
+ allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
+ stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
+ Gitlab::CurrentSettings.current_application_settings
+
+ update_storages({ 'picked' => 0, 'default' => 100 })
+ end
+
+ context 'when expire is false' do
+ it 'does not expire existing repository storage value' do
+ previous_storage = described_class.pick_storage_shard
+ expect(previous_storage).to eq('default')
+ expect(Gitlab::CurrentSettings).not_to receive(:expire_current_application_settings)
+
+ update_storages({ 'picked' => 100, 'default' => 0 })
+
+ new_storage = described_class.pick_storage_shard(expire: false)
+ expect(new_storage).to eq(previous_storage)
+ end
+ end
+
+ context 'when expire is true' do
+ it 'expires existing repository storage value' do
+ previous_storage = described_class.pick_storage_shard
+ expect(previous_storage).to eq('default')
+ expect(Gitlab::CurrentSettings).to receive(:expire_current_application_settings).and_call_original
+
+ update_storages({ 'picked' => 100, 'default' => 0 })
+
+ new_storage = described_class.pick_storage_shard(expire: true)
+ expect(new_storage).to eq('picked')
+ end
+ end
+
+ def update_storages(storage_hash)
+ settings = ApplicationSetting.last
+ settings.repository_storages_weighted = storage_hash
+ settings.save!
+ end
+ end
end