# frozen_string_literal: true RSpec.describe DeclareSchema do describe '#default_charset' do subject { described_class.default_charset } context 'when not explicitly set' do it { is_expected.to eq("utf8mb4") } end context 'when explicitly set' do before { described_class.default_charset = "utf8" } after { described_class.default_charset = "utf8mb4" } it { is_expected.to eq("utf8") } end end describe '#default_collation' do subject { described_class.default_collation } context 'when not explicitly set' do it { is_expected.to eq("utf8mb4_bin") } end context 'when explicitly set' do before { described_class.default_collation = "utf8mb4_general_ci" } after { described_class.default_collation = "utf8mb4_bin" } it { is_expected.to eq("utf8mb4_general_ci") } end end describe '#default_text_limit' do subject { described_class.default_text_limit } context 'when not explicitly set' do it { is_expected.to eq(0xffff_ffff) } end context 'when explicitly set' do before { described_class.default_text_limit = 0xffff } after { described_class.default_text_limit = 0xffff_ffff } it { is_expected.to eq(0xffff) } end end describe '#default_string_limit' do subject { described_class.default_string_limit } context 'when not explicitly set' do it { is_expected.to eq(nil) } end context 'when explicitly set' do before { described_class.default_string_limit = 225 } after { described_class.default_string_limit = nil } it { is_expected.to eq(225) } end end describe '#default_null' do subject { described_class.default_null } context 'when not explicitly set' do it { is_expected.to eq(false) } end context 'when explicitly set' do before { described_class.default_null = true } after { described_class.default_null = false } it { is_expected.to eq(true) } end end describe '#default_generate_foreign_keys' do subject { described_class.default_generate_foreign_keys } context 'when not explicitly set' do it { is_expected.to eq(true) } end context 'when explicitly set' do before { described_class.default_generate_foreign_keys = false } after { described_class.default_generate_foreign_keys = true } it { is_expected.to eq(false) } end end describe '#default_generate_indexing' do subject { described_class.default_generate_indexing } context 'when not explicitly set' do it { is_expected.to eq(true) } end context 'when explicitly set' do before { described_class.default_generate_indexing = false } after { described_class.default_generate_indexing = true } it { is_expected.to eq(false) } end end describe '#max_index_and_constraint_name_length' do subject { described_class.max_index_and_constraint_name_length } context 'when not explicitly set' do it { is_expected.to eq(64) } end context 'when explicitly set' do around do |spec| orig_value = described_class.max_index_and_constraint_name_length described_class.max_index_and_constraint_name_length = max_index_and_constraint_name_length spec.run rescue described_class.max_index_and_constraint_name_length = orig_value end context 'when set to an Integer' do let(:max_index_and_constraint_name_length) { 255 } it { is_expected.to eq(255)} end context 'when set to nil' do let(:max_index_and_constraint_name_length) { nil } it { is_expected.to eq(nil)} end end end end