debian-mirror-gitlab/spec/models/project_wiki_spec.rb

80 lines
2.7 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2020-05-24 23:13:21 +05:30
require 'spec_helper'
2014-09-02 18:07:02 +05:30
2023-07-09 08:55:56 +05:30
RSpec.describe ProjectWiki, feature_category: :wiki do
2020-05-24 23:13:21 +05:30
it_behaves_like 'wiki model' do
let(:wiki_container) { create(:project, :wiki_repo, namespace: user.namespace) }
let(:wiki_container_without_repo) { create(:project, namespace: user.namespace) }
2021-01-03 14:25:43 +05:30
let(:wiki_lfs_enabled) { true }
2014-09-02 18:07:02 +05:30
2020-05-24 23:13:21 +05:30
it { is_expected.to delegate_method(:storage).to(:container) }
it { is_expected.to delegate_method(:repository_storage).to(:container) }
it { is_expected.to delegate_method(:hashed_storage?).to(:container) }
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
describe '#disk_path' do
it 'returns the repository storage path' do
expect(subject.disk_path).to eq("#{subject.container.disk_path}.wiki")
2019-02-15 15:39:39 +05:30
end
2014-09-02 18:07:02 +05:30
end
2023-06-20 00:43:36 +05:30
describe '#create_wiki_repository' do
context 'when a project_wiki_repositories record does not exist' do
let_it_be(:wiki_container) { create(:project) }
it 'creates a new record' do
expect { subject.create_wiki_repository }.to change { wiki_container.wiki_repository }
.from(nil).to(kind_of(Projects::WikiRepository))
end
context 'on a read-only instance' do
before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end
it 'does not attempt to create a new record' do
expect { subject.create_wiki_repository }.not_to change { wiki_container.wiki_repository }
end
end
end
context 'when a project_wiki_repositories record exists' do
it 'does not create a new record in the database' do
expect { subject.create_wiki_repository }.not_to change { wiki_container.wiki_repository }
end
end
end
2018-11-18 11:00:15 +05:30
2020-11-24 15:15:51 +05:30
describe '#after_wiki_activity' do
2020-05-24 23:13:21 +05:30
it 'updates project activity' do
wiki_container.update!(
last_activity_at: nil,
last_repository_updated_at: nil
)
2018-03-17 18:26:18 +05:30
2020-11-24 15:15:51 +05:30
subject.send(:after_wiki_activity)
2020-05-24 23:13:21 +05:30
wiki_container.reload
2018-05-09 12:01:36 +05:30
2020-06-23 00:09:42 +05:30
expect(wiki_container.last_activity_at).to be_within(1.minute).of(Time.current)
expect(wiki_container.last_repository_updated_at).to be_within(1.minute).of(Time.current)
2019-01-03 12:48:30 +05:30
end
2019-02-15 15:39:39 +05:30
end
2020-11-24 15:15:51 +05:30
describe '#after_post_receive' do
it 'updates project activity and expires caches' do
expect(wiki).to receive(:after_wiki_activity)
expect(ProjectCacheWorker).to receive(:perform_async).with(wiki_container.id, [], [:wiki_size])
subject.send(:after_post_receive)
end
end
2014-09-02 18:07:02 +05:30
end
2021-03-08 18:12:59 +05:30
it_behaves_like 'can housekeep repository' do
let_it_be(:resource) { create(:project_wiki) }
let(:resource_key) { 'project_wikis' }
2021-03-11 19:13:27 +05:30
let(:expected_worker_class) { Wikis::GitGarbageCollectWorker }
2021-03-08 18:12:59 +05:30
end
2014-09-02 18:07:02 +05:30
end