debian-mirror-gitlab/spec/migrations/20210430134202_copy_adoption_snapshot_namespace_spec.rb

46 lines
1.4 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
2021-09-04 01:27:46 +05:30
#
2021-06-08 01:23:25 +05:30
require 'spec_helper'
2021-09-04 01:27:46 +05:30
require_migration!('copy_adoption_snapshot_namespace')
2021-06-08 01:23:25 +05:30
2021-09-04 01:27:46 +05:30
RSpec.describe CopyAdoptionSnapshotNamespace, :migration, schema: 20210430124630 do
2021-06-08 01:23:25 +05:30
let(:namespaces_table) { table(:namespaces) }
let(:segments_table) { table(:analytics_devops_adoption_segments) }
let(:snapshots_table) { table(:analytics_devops_adoption_snapshots) }
2021-09-04 01:27:46 +05:30
it 'updates all snapshots without namespace set' do
2021-06-08 01:23:25 +05:30
namespaces_table.create!(id: 123, name: 'group1', path: 'group1')
namespaces_table.create!(id: 124, name: 'group2', path: 'group2')
segments_table.create!(id: 1, namespace_id: 123)
segments_table.create!(id: 2, namespace_id: 124)
create_snapshot(id: 1, segment_id: 1)
create_snapshot(id: 2, segment_id: 2)
create_snapshot(id: 3, segment_id: 2, namespace_id: 123)
migrate!
expect(snapshots_table.find(1).namespace_id).to eq 123
expect(snapshots_table.find(2).namespace_id).to eq 124
expect(snapshots_table.find(3).namespace_id).to eq 123
end
def create_snapshot(**additional_params)
defaults = {
recorded_at: Time.zone.now,
issue_opened: true,
merge_request_opened: true,
merge_request_approved: true,
runner_configured: true,
pipeline_succeeded: true,
deploy_succeeded: true,
security_scan_succeeded: true,
end_time: Time.zone.now.end_of_month
}
snapshots_table.create!(defaults.merge(additional_params))
end
end