Sha256: d5f590949c6681bd030a8b4ebc2b70848420f2277523e7282217cffbef90cc71

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

require 'active_record'
require 'logger'

::ActiveRecord::Base.logger = Logger.new SPEC_ROOT.join('debug.log').to_s
::ActiveRecord::Migration.verbose = false

module CryptKeeper
  class SensitiveData < ActiveRecord::Base; end

  module ConnectionHelpers
    def use_postgres
      before :all do
        ::ActiveRecord::Base.clear_active_connections!
        config = YAML.load_file SPEC_ROOT.join('database.yml')
        ::ActiveRecord::Base.establish_connection(config['postgres'])
      end
    end

    def use_mysql
      before :all do
        ::ActiveRecord::Base.clear_active_connections!
        config = YAML.load_file SPEC_ROOT.join('database.yml')
        ::ActiveRecord::Base.establish_connection(config['mysql'])
      end
    end

    def use_sqlite
      before :all do
        ::ActiveRecord::Base.clear_active_connections!
        ::ActiveRecord::Base.establish_connection(:adapter => 'sqlite3',
          :database => ':memory:')

        ::ActiveRecord::Schema.define do
          create_table :sensitive_data, :force => true do |t|
            t.column :name, :string
            t.column :storage, :text
            t.column :secret, :text
          end
        end
      end
    end
  end
end


RSpec.configure do |config|
  config.extend CryptKeeper::ConnectionHelpers
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
crypt_keeper-0.12.0 spec/support/active_record.rb
crypt_keeper-0.11.0 spec/support/active_record.rb
crypt_keeper-0.10.0.pre spec/support/active_record.rb
crypt_keeper-0.9.0.pre spec/support/active_record.rb
crypt_keeper-0.8.0 spec/support/active_record.rb