Sha256: c8571c16e1bb8345991a06dd5ed3ae3823b26f78a53d2bfe48f28177882d1d62

Contents?: true

Size: 1.45 KB

Versions: 10

Compression:

Stored size: 1.45 KB

Contents

require 'assert'
require 'ardb'

module Ardb

  class UnitTests < Assert::Context
    desc "Ardb"
    subject{ Ardb }
    setup do
      @orig_ar_logger = ActiveRecord::Base.logger
    end
    teardown do
      Adapter.reset
      ActiveRecord::Base.logger = @orig_ar_logger
    end

    should have_imeths :config, :configure, :adapter, :validate!, :init

    should "return its `Config` class with the `config` method" do
      assert_same Config, subject.config
    end

    should "complain if init'ing and not all configs are set" do
      orig_adapter = Ardb.config.db.adapter
      Ardb.config.db.adapter = nil
      assert_raises(NotConfiguredError) { subject.init }
      Ardb.config.db.adapter = orig_adapter
    end

    should "init the adapter on init" do
      Adapter.reset
      assert_nil Adapter.current
      begin
        subject.init
      rescue LoadError
      end

      assert_not_nil Adapter.current
      exp_adapter = Adapter.send(subject.config.db.adapter)
      assert_equal exp_adapter, Adapter.current
      assert_same Adapter.current, subject.adapter
    end

    should "establish an AR connection on init" do
      assert_raises(LoadError) do
        # not going to test this b/c I don't want to bring in all the crap it
        # takes to actually establish a connection with AR (adapters, etc)
        # plus, most of this should be handled by AR, ns-options, and the above
        # tests anyway
        subject.init
      end
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ardb-0.27.2 test/unit/ardb_tests.rb
ardb-0.27.1 test/unit/ardb_tests.rb
ardb-0.27.0 test/unit/ardb_tests.rb
ardb-0.26.0 test/unit/ardb_tests.rb
ardb-0.25.0 test/unit/ardb_tests.rb
ardb-0.24.0 test/unit/ardb_tests.rb
ardb-0.23.0 test/unit/ardb_tests.rb
ardb-0.22.1 test/unit/ardb_tests.rb
ardb-0.22.0 test/unit/ardb_tests.rb
ardb-0.21.0 test/unit/ardb_tests.rb