Sha256: f1e4719e5583cd7c89a92567eaf3c58d320823473ebf9c70f1e1389ae05395d3

Contents?: true

Size: 1.92 KB

Versions: 42

Compression:

Stored size: 1.92 KB

Contents

require "spec_helper"

describe Brightbox::Api, ".find" do
  before do
    config_from_contents(API_CLIENT_CONFIG_CONTENTS)
  end

  context "when passed nil" do
    it "raises an error" do
      expect do
        Brightbox::Api.find(nil)
      end.to raise_error(Brightbox::Api::InvalidArguments)
    end
  end

  context "when passed an empty object" do
    it "raises an error" do
      expect do
        Brightbox::Api.find([])
      end.to raise_error(Brightbox::Api::InvalidArguments)
    end
  end

  context "when all objects are requested" do
    it "returns a collection" do
      @fog_model = double
      @resource = double
      expect(Brightbox::Api).to receive(:all).and_return([@fog_model])
      expect(Brightbox::Api).to receive(:new).with(@fog_model).and_return(@resource)
      expect(Brightbox::Api.find(:all)).to eql([@resource])
    end
  end

  context "when passed an identifier string" do
    it "returns a wrapped Api model" do
      @identifier = "api-12345"
      @fog_model = double
      @resource = double
      expect(Brightbox::Api).to receive(:get).with(@identifier).and_return(@fog_model)
      expect(Brightbox::Api).to receive(:new).with(@fog_model).and_return(@resource)
      expect(Brightbox::Api.find(@identifier)).to eql(@resource)
    end
  end

  context "when passed a collection of identifiers" do
    before do
      @identifier = "api-12345"
      @fog_model = double
      @resource = double
    end

    it "returns collection of found resources" do
      expect(Brightbox::Api).to receive(:cached_get).with(@identifier).and_return(@fog_model)
      expect(Brightbox::Api).to receive(:new).with(@fog_model).and_return(@resource)
      expect(Brightbox::Api.find([@identifier])).to eq([@resource])
    end
  end

  context "when passed a bad search value" do
    it "raises an error" do
      expect do
        Brightbox::Api.find(double)
      end.to raise_error(Brightbox::Api::InvalidArguments)
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
brightbox-cli-4.8.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.7.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.6.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.5.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.5.0.rc1 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.4.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.3.2 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.3.1 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.3.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.2.1 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.2.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.1.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.0.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-4.0.0.rc2 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-3.3.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-3.2.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-3.1.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-3.0.1 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-3.0.0 spec/unit/brightbox/api/find_spec.rb
brightbox-cli-2.12.0 spec/unit/brightbox/api/find_spec.rb