Added methods for detecting MySQL/PostgreSQL

These two methods remove the need for manually going into
ActiveRecord::Base.connection all over the place.
This commit is contained in:
Yorick Peterse 2015-10-07 12:30:10 +02:00
parent c670f07366
commit 85c6a3743a
2 changed files with 28 additions and 0 deletions

11
lib/gitlab/database.rb Normal file
View file

@ -0,0 +1,11 @@
module Gitlab
module Database
def self.mysql?
ActiveRecord::Base.connection.adapter_name.downcase == 'mysql'
end
def self.postgresql?
ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql'
end
end
end

View file

@ -0,0 +1,17 @@
require 'spec_helper'
describe Gitlab::Database do
# 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
end