diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/models/audit_event_partitioned_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/models/audit_event_partitioned_spec.rb')
-rw-r--r-- | spec/models/audit_event_partitioned_spec.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/models/audit_event_partitioned_spec.rb b/spec/models/audit_event_partitioned_spec.rb new file mode 100644 index 00000000000..fe69f0083b7 --- /dev/null +++ b/spec/models/audit_event_partitioned_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe AuditEventPartitioned do + let(:source_table) { AuditEvent } + let(:partitioned_table) { described_class } + + it 'has the same columns as the source table' do + expect(partitioned_table.column_names).to match_array(source_table.column_names) + end + + it 'has the same null constraints as the source table' do + constraints_from_source_table = null_constraints(source_table) + constraints_from_partitioned_table = null_constraints(partitioned_table) + + expect(constraints_from_partitioned_table.to_a).to match_array(constraints_from_source_table.to_a) + end + + it 'inserts the same record as the one in the source table', :aggregate_failures do + expect { create(:audit_event) }.to change { partitioned_table.count }.by(1) + + event_from_source_table = source_table.connection.select_one( + "SELECT * FROM #{source_table.table_name} ORDER BY created_at desc LIMIT 1" + ) + event_from_partitioned_table = partitioned_table.connection.select_one( + "SELECT * FROM #{partitioned_table.table_name} ORDER BY created_at desc LIMIT 1" + ) + + expect(event_from_partitioned_table).to eq(event_from_source_table) + end + + def null_constraints(table) + table.connection.select_all(<<~SQL) + SELECT c.column_name, c.is_nullable + FROM information_schema.columns c + WHERE c.table_name = '#{table.table_name}' + AND c.column_name != 'created_at' + SQL + end +end |