Sha256: d5f0ff845e51c6420f861a1b82113dbcc1f89c854eafc6144ee64cf2a6824f52

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require "minitest_helper"
require "heroku/client"

describe Heroku::Client::PgbackupsArchive do
  let(:archive) {
    Heroku::Client::PgbackupsArchive.new(
      :pgbackups_url => "https://ip:password@pgbackups.heroku.com/client"
    )
  }
  let(:backup) { { "finished_at" => "some timestamp" } }

  it "should use a pgbackup client" do
    archive.client.class.must_equal Heroku::Client::Pgbackups
  end

  describe "given a finished_at timestamp" do
    before { archive.client.stubs(:create_transfer).returns(backup) }

    it "should capture the backup" do
      archive.capture.must_equal backup
    end

    it "should store the backup" do
      archive.stubs(:key).returns("key")
      archive.stubs(:file).returns("file")
      archive.store.class.must_equal Fog::Storage::AWS::File
    end
  end

  describe "configure the backup database" do

    describe "backup database is not configured" do
      before do
        ENV["PGBACKUPS_DATABASE_URL"] = nil
        ENV["DATABASE_URL"] = "db_url"
      end

      it "defaults to using the DATABASE_URL" do
        archive.client.expects(:create_transfer)
        .with("db_url", "db_url", nil, "BACKUP", :expire => true)
        .returns(backup)

        archive.capture
      end
    end

    describe "backup database is configured" do
      before do
        ENV["PGBACKUPS_DATABASE_URL"] = "backup_db"
        ENV["DATABASE_URL"] = "db_url"
      end

      it "defaults to using the DATABASE_URL" do
        archive.client.expects(:create_transfer)
        .with("backup_db", "backup_db", nil, "BACKUP", :expire => true)
        .returns(backup)

        archive.capture
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pgbackups-archive-0.1.0 test/lib/pgbackups-archive/heroku/client/pgbackups_archive_test.rb