2015-10-07 10:30:10 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-02-15 19:13:47 +00:00
|
|
|
class MigrationTest
|
|
|
|
include Gitlab::Database
|
|
|
|
end
|
|
|
|
|
2015-12-09 10:55:36 +00:00
|
|
|
describe Gitlab::Database, lib: true do
|
2015-10-07 10:30:10 +00:00
|
|
|
# These are just simple smoke tests to check if the methods work (regardless
|
|
|
|
# of what they may return).
|
|
|
|
describe '.mysql?' do
|
|
|
|
subject { described_class.mysql? }
|
|
|
|
|
|
|
|
it { is_expected.to satisfy { |val| val == true || val == false } }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.postgresql?' do
|
|
|
|
subject { described_class.postgresql? }
|
|
|
|
|
|
|
|
it { is_expected.to satisfy { |val| val == true || val == false } }
|
|
|
|
end
|
2016-02-02 02:29:37 +00:00
|
|
|
|
|
|
|
describe '.version' do
|
|
|
|
context "on mysql" do
|
|
|
|
it "extracts the version number" do
|
|
|
|
allow(described_class).to receive(:database_version).
|
|
|
|
and_return("5.7.12-standard")
|
|
|
|
|
|
|
|
expect(described_class.version).to eq '5.7.12-standard'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "on postgresql" do
|
|
|
|
it "extracts the version number" do
|
|
|
|
allow(described_class).to receive(:database_version).
|
|
|
|
and_return("PostgreSQL 9.4.4 on x86_64-apple-darwin14.3.0")
|
|
|
|
|
|
|
|
expect(described_class.version).to eq '9.4.4'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-15 19:13:47 +00:00
|
|
|
|
2016-05-13 15:26:18 +00:00
|
|
|
describe '.nulls_last_order' do
|
|
|
|
context 'when using PostgreSQL' do
|
|
|
|
before { expect(described_class).to receive(:postgresql?).and_return(true) }
|
|
|
|
|
|
|
|
it { expect(described_class.nulls_last_order('column', 'ASC')).to eq 'column ASC NULLS LAST'}
|
|
|
|
it { expect(described_class.nulls_last_order('column', 'DESC')).to eq 'column DESC NULLS LAST'}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using MySQL' do
|
|
|
|
before { expect(described_class).to receive(:postgresql?).and_return(false) }
|
|
|
|
|
|
|
|
it { expect(described_class.nulls_last_order('column', 'ASC')).to eq 'column IS NULL, column ASC'}
|
|
|
|
it { expect(described_class.nulls_last_order('column', 'DESC')).to eq 'column DESC'}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-15 19:13:47 +00:00
|
|
|
describe '#true_value' do
|
|
|
|
it 'returns correct value for PostgreSQL' do
|
|
|
|
expect(described_class).to receive(:postgresql?).and_return(true)
|
|
|
|
|
|
|
|
expect(MigrationTest.new.true_value).to eq "'t'"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for MySQL' do
|
|
|
|
expect(described_class).to receive(:postgresql?).and_return(false)
|
|
|
|
|
|
|
|
expect(MigrationTest.new.true_value).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#false_value' do
|
|
|
|
it 'returns correct value for PostgreSQL' do
|
|
|
|
expect(described_class).to receive(:postgresql?).and_return(true)
|
|
|
|
|
|
|
|
expect(MigrationTest.new.false_value).to eq "'f'"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for MySQL' do
|
|
|
|
expect(described_class).to receive(:postgresql?).and_return(false)
|
|
|
|
|
|
|
|
expect(MigrationTest.new.false_value).to eq 0
|
|
|
|
end
|
|
|
|
end
|
2015-10-07 10:30:10 +00:00
|
|
|
end
|