diff options
author | Alessio Caiazza <acaiazza@gitlab.com> | 2019-05-31 12:59:36 +0300 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2019-05-31 12:59:36 +0300 |
commit | 724b5afbd99ab31242eed386d9169a1f1b5a7610 (patch) | |
tree | 46a00a2e87d440a106c11006ce2099c242af8293 /spec/migrations | |
parent | bc32249b30f294db242928e9f76a353d2e7e5b5e (diff) |
Remove nils from project_statistics.packages_size
Now it defaults to 0
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb b/spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb new file mode 100644 index 00000000000..93e7e9304b1 --- /dev/null +++ b/spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20190516155724_change_packages_size_defaults_in_project_statistics.rb') + +describe ChangePackagesSizeDefaultsInProjectStatistics, :migration do + let(:project_statistics) { table(:project_statistics) } + let(:projects) { table(:projects) } + + it 'removes null packages_size' do + stats_to_migrate = 10 + + stats_to_migrate.times do |i| + p = projects.create!(name: "project #{i}", namespace_id: 1) + project_statistics.create!(project_id: p.id, namespace_id: p.namespace_id) + end + + expect { migrate! } + .to change { ProjectStatistics.where(packages_size: nil).count } + .from(stats_to_migrate) + .to(0) + end + + it 'defaults packages_size to 0' do + project = projects.create!(name: 'a new project', namespace_id: 2) + stat = project_statistics.create!(project_id: project.id, namespace_id: project.namespace_id) + + expect(stat.packages_size).to be_nil + + migrate! + + stat.reload + expect(stat.packages_size).to eq(0) + end +end |