diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-07 18:08:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-07 18:08:49 +0300 |
commit | a93bf027c2619af8c11b030414c339346f13ead6 (patch) | |
tree | 283f1b4096a255a535a79c60ebe2445a9e5df4d2 /spec/migrations | |
parent | 0254867cf0f3341fd63cc6da07290f1da91f99ef (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/active_record/schema_spec.rb | 2 | ||||
-rw-r--r-- | spec/migrations/schedule_calculate_wiki_sizes_spec.rb | 60 |
2 files changed, 61 insertions, 1 deletions
diff --git a/spec/migrations/active_record/schema_spec.rb b/spec/migrations/active_record/schema_spec.rb index d26e6437b32..8199f55f5fc 100644 --- a/spec/migrations/active_record/schema_spec.rb +++ b/spec/migrations/active_record/schema_spec.rb @@ -25,6 +25,6 @@ RSpec.describe ActiveRecord::Schema, schema: :latest do it 'the schema_migrations table contains all schema versions' do versions = ActiveRecord::Base.connection.execute('SELECT version FROM schema_migrations ORDER BY version').map { |m| Integer(m['version']) } - expect(versions).to eq(all_migrations) + expect(versions).to match_array(all_migrations) end end diff --git a/spec/migrations/schedule_calculate_wiki_sizes_spec.rb b/spec/migrations/schedule_calculate_wiki_sizes_spec.rb new file mode 100644 index 00000000000..39a93f3ed25 --- /dev/null +++ b/spec/migrations/schedule_calculate_wiki_sizes_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20190527194900_schedule_calculate_wiki_sizes.rb') + +RSpec.describe ScheduleCalculateWikiSizes do + let(:migration_class) { Gitlab::BackgroundMigration::CalculateWikiSizes } + let(:migration_name) { migration_class.to_s.demodulize } + + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:project_statistics) { table(:project_statistics) } + let(:namespace) { namespaces.create!(name: 'wiki-migration', path: 'wiki-migration') } + let(:project1) { projects.create!(name: 'wiki-project-1', path: 'wiki-project-1', namespace_id: namespace.id) } + let(:project2) { projects.create!(name: 'wiki-project-2', path: 'wiki-project-2', namespace_id: namespace.id) } + let(:project3) { projects.create!(name: 'wiki-project-3', path: 'wiki-project-3', namespace_id: namespace.id) } + + context 'when missing wiki sizes exist' do + let!(:project_statistic1) { project_statistics.create!(id: 1, project_id: project1.id, namespace_id: namespace.id, wiki_size: 1000) } + let!(:project_statistic2) { project_statistics.create!(id: 2, project_id: project2.id, namespace_id: namespace.id, wiki_size: nil) } + let!(:project_statistic3) { project_statistics.create!(id: 3, project_id: project3.id, namespace_id: namespace.id, wiki_size: nil) } + + it 'schedules a background migration' do + Timecop.freeze do + migrate! + + expect(migration_name).to be_scheduled_delayed_migration(5.minutes, project_statistic2.id, project_statistic3.id) + expect(BackgroundMigrationWorker.jobs.size).to eq 1 + end + end + + it 'calculates missing wiki sizes', :sidekiq_inline do + expect(project_statistic2.wiki_size).to be_nil + expect(project_statistic3.wiki_size).to be_nil + + migrate! + + expect(project_statistic2.reload.wiki_size).not_to be_nil + expect(project_statistic3.reload.wiki_size).not_to be_nil + end + end + + context 'when missing wiki sizes do not exist' do + before do + namespace = namespaces.create!(name: 'wiki-migration', path: 'wiki-migration') + project = projects.create!(name: 'wiki-project-1', path: 'wiki-project-1', namespace_id: namespace.id) + project_statistics.create!(project_id: project.id, namespace_id: 1, wiki_size: 1000) + end + + it 'does not schedule a background migration' do + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + expect(BackgroundMigrationWorker.jobs.size).to eq 0 + end + end + end + end +end |