Sha256: 007653b5d7be6c94ca709c81c8b8b6d9085276c531a952eadea014c537a957d9

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

describe RabbitMQ::Definition::Load do
  let(:client) do
    double(
      "client",
      :upload_definitions => nil,
      :endpoint => ENV['RABBITMQ_MANAGEMENT_URL'],
      :update_permissions_of => nil
    )
  end
  let(:all_permissions) do
    {
      :configure => ".*",
      :write     => ".*",
      :read       => ".*"
    }
  end

  context "when a definition file does NOT exist" do
    before { allow(RabbitMQ::Definition::FileDefinition).to receive(:exists?).and_return(false) }

    it "notifies about error" do
      expect(RabbitMQ::Definition::Logger).to receive(:error).with("No definition with vhosts exists").once
      described_class.run(client, false)
    end
  end

  context "when a definition file does NOT exist" do
    let(:json) { '{"definitions": "json"}' }
    before do
      definition = double(:to_json => json, :vhosts => [{'name' => '/'}])
      allow(RabbitMQ::Definition::FileDefinition).to receive(:exists?).and_return(true)
      expect(RabbitMQ::Definition::FileDefinition).to receive(:read).and_return(definition)
    end

    it "notifies progress" do
      expect(RabbitMQ::Definition::Logger).to receive(:progress).with("Uploading definition...").once
      described_class.run(client, true)
    end

    it "notifies success" do
      expect(RabbitMQ::Definition::Logger).to receive(:success).with("Done").once
      described_class.run(client, true)
    end

    it "ensures the user has granted permissions for the definition vhosts" do
      expect(client).to receive(:update_permissions_of).with('/', 'guest', all_permissions).once
      described_class.run(client, false)
    end

    it "uploads the json definition to the client " do
      expect(client).to receive(:upload_definitions).with(json).once
      described_class.run(client, false)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rabbitmq-definition-0.1.3 spec/rabbitmq_definition/load_spec.rb