blob: 7cbba9ef20e79b85f43678f317df2df6428d0fd2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20191004081520_fill_productivity_analytics_start_date.rb')
describe FillProductivityAnalyticsStartDate, :migration do
let(:settings_table) { table('application_settings') }
let(:metrics_table) { table('merge_request_metrics') }
before do
settings_table.create!
end
context 'with NO productivity analytics data available' do
it 'sets start_date to NOW' do
expect { migrate! }.to change {
settings_table.first&.productivity_analytics_start_date
}.to(be_like_time(Time.now))
end
end
context 'with productivity analytics data available' do
before do
ActiveRecord::Base.transaction do
ActiveRecord::Base.connection.execute('ALTER TABLE merge_request_metrics DISABLE TRIGGER ALL')
metrics_table.create!(merged_at: Time.parse('2019-09-09'), commits_count: nil, merge_request_id: 3)
metrics_table.create!(merged_at: Time.parse('2019-10-10'), commits_count: 5, merge_request_id: 1)
metrics_table.create!(merged_at: Time.parse('2019-11-11'), commits_count: 10, merge_request_id: 2)
ActiveRecord::Base.connection.execute('ALTER TABLE merge_request_metrics ENABLE TRIGGER ALL')
end
end
it 'set start_date to earliest merged_at value with PA data available' do
expect { migrate! }.to change {
settings_table.first&.productivity_analytics_start_date
}.to(be_like_time(Time.parse('2019-10-10')))
end
end
end
|