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:
parent
c670f07366
commit
85c6a3743a
2 changed files with 28 additions and 0 deletions
11
lib/gitlab/database.rb
Normal file
11
lib/gitlab/database.rb
Normal 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
|
17
spec/lib/gitlab/database_spec.rb
Normal file
17
spec/lib/gitlab/database_spec.rb
Normal 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
|
Loading…
Reference in a new issue