aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support/guards.rb
blob: db6075f73ad43d016a443c8a370ea672246b3f55 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module AdapterGuards
  def adapter_is(*names)
    names = names.map(&:to_s)
    names.each{|name| verify_adapter_name(name)}
    yield if names.include? adapter_name
  end

  def adapter_is_not(*names)
    names = names.map(&:to_s)
    names.each{|name| verify_adapter_name(name)}
    yield unless names.include? adapter_name
  end

  def adapter_name
    name = ActiveRecord::Base.configurations["unit"][:adapter]
    name = 'oracle' if name == 'oracle_enhanced'
    verify_adapter_name(name)
    name
  end

  def verify_adapter_name(name)
    raise "Invalid adapter name: #{name}" unless valid_adapters.include?(name.to_s)
  end

  def valid_adapters
    %w[mysql postgresql sqlite3 oracle]
  end
end