Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/migrations/update_historical_data_recorded_at_spec.rb')
-rw-r--r--spec/migrations/update_historical_data_recorded_at_spec.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/migrations/update_historical_data_recorded_at_spec.rb b/spec/migrations/update_historical_data_recorded_at_spec.rb
new file mode 100644
index 00000000000..bccc711f339
--- /dev/null
+++ b/spec/migrations/update_historical_data_recorded_at_spec.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require Rails.root.join('db', 'migrate', '20201022094846_update_historical_data_recorded_at.rb')
+
+RSpec.describe UpdateHistoricalDataRecordedAt do
+ let(:historical_data_table) { table(:historical_data) }
+
+ it 'reversibly populates recorded_at from created_at or date' do
+ row1 = historical_data_table.create!(
+ date: Date.current - 1.day,
+ created_at: Time.current - 1.day
+ )
+
+ row2 = historical_data_table.create!(date: Date.current - 2.days)
+ row2.update!(created_at: nil)
+
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(row1.reload.recorded_at).to eq(nil)
+ expect(row2.reload.recorded_at).to eq(nil)
+ }
+
+ migration.after -> {
+ expect(row1.reload.recorded_at).to eq(row1.created_at)
+ expect(row2.reload.recorded_at).to eq(row2.date.in_time_zone(Time.zone).change(hour: 12))
+ }
+ end
+ end
+end