summaryrefslogtreecommitdiff
path: root/spec/migrations/20220222192524_create_not_null_constraint_releases_tag_spec.rb
blob: bd7d992240aff5dd10dd633d2c0e6ae535e8a2a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true
require 'spec_helper'
require_migration!

RSpec.describe CreateNotNullConstraintReleasesTag do
  let_it_be(:releases) { table(:releases) }
  let_it_be(:migration) { described_class.new }

  before do
    allow(migration).to receive(:transaction_open?).and_return(false)
    allow(migration).to receive(:with_lock_retries).and_yield
  end

  it 'adds a check constraint to tags' do
    constraint = releases.connection.check_constraints(:releases).find { |constraint| constraint.expression == "tag IS NOT NULL" }
    expect(constraint).to be_nil

    migration.up

    constraint = releases.connection.check_constraints(:releases).find { |constraint| constraint.expression == "tag IS NOT NULL" }
    expect(constraint).to be_a(ActiveRecord::ConnectionAdapters::CheckConstraintDefinition)
  end
end