Sha256: 9cbe870f49440c3828e7249bd1726b105c161ded30e494b879e20a7365a9d180

Contents?: true

Size: 1.22 KB

Versions: 17

Compression:

Stored size: 1.22 KB

Contents

require 'database_cleaner/generic/base'
require 'active_record'
require 'erb'

module DatabaseCleaner
  module ActiveRecord

    def self.available_strategies
      %w[truncation transaction deletion]
    end

    def self.config_file_location=(path)
      @config_file_location = path
    end

    def self.config_file_location
      @config_file_location ||= "#{DatabaseCleaner.app_root}/config/database.yml"
    end

    module Base
      include ::DatabaseCleaner::Generic::Base

      attr_accessor :connection_hash

      def db=(desired_db)
        @db = desired_db
        load_config
      end

      def db
        @db || super
      end

      def load_config
        if self.db != :default && File.file?(ActiveRecord.config_file_location)
          connection_details   = YAML::load(ERB.new(IO.read(ActiveRecord.config_file_location)).result)
          @connection_hash = connection_details[self.db.to_s]
        end
      end

      def create_connection_klass
        Class.new(::ActiveRecord::Base)
      end

      def connection_klass
        return ::ActiveRecord::Base unless connection_hash
        klass = create_connection_klass
        klass.send :establish_connection, connection_hash
        klass
      end
    end
  end
end

Version data entries

17 entries across 11 versions & 4 rubygems

Version Path
raffle_v1-0.0.5 lib/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.8.0/lib/database_cleaner/active_record/base.rb
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
database_cleaner-0.8.0 lib/database_cleaner/active_record/base.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
rails-uploader-0.0.1 vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/base.rb
database_cleaner-0.7.2 lib/database_cleaner/active_record/base.rb
database_cleaner-0.7.1 lib/database_cleaner/active_record/base.rb