Sha256: 0b9a84ad737b406c5ab0d3e6d2756a9131522bf5eaeba45eb514542bed3dfd19

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

require 'spec_helper'
require 'ronin/db/cli/database_command'

describe Ronin::DB::CLI::DatabaseCommand do
  describe "#config" do
    context "when neither options[:db] nor options[:db_uri] are set" do
      it "must default to connecting to the :default database" do
        expect(subject.config).to eq(Ronin::DB.config[:default])
      end
    end

    context "when options[:db] is set" do
      let(:db_name) { :test }
      let(:config) do
        {
          db_name => {
            adapter: 'sqlite3',
            database: '/path/to/db.sqlite3'
          }
        }
      end

      before do
        allow(Ronin::DB).to receive(:config).and_return(config)

        subject.options[:db] = db_name
      end

      it "must return the database configuration for options[:db]" do
        expect(subject.config).to eq(Ronin::DB.config[db_name])
      end
    end

    context "when options[:db_uri] is set" do
      let(:db_uri)     { "postgres://user:password@host:1234/database" }
      let(:parsed_uri) { subject.parse_uri(subject.options[:db_uri])   }

      before { subject.options[:db_uri] = db_uri }

      it "must return the parsed URI for options[:db_uri]" do
        expect(subject.config).to eq(parsed_uri)
      end
    end
  end

  describe "#connect" do
    it "must call ActiveRecord::Base.establish_connection with #config" do
      expect(ActiveRecord::Base).to receive(:establish_connection).with(subject.config)

      subject.connect
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ronin-db-0.1.0.beta1-java spec/cli/database_command_spec.rb
ronin-db-0.1.0.beta1 spec/cli/database_command_spec.rb