Sha256: 62168c0354b1a0453ea783ca9d465b78bd4bbbc5ed0d5d46709deb1cfa5061c9

Contents?: true

Size: 1.74 KB

Versions: 18

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper'

describe Ridley::DataBagItemResource do
  let(:connection) { double('connection') }
  let(:data_bag) { double('data_bag') }

  subject { Ridley::DataBagItemResource.new(connection, data_bag) }

  describe "::from_hash" do
    context "when JSON has a 'raw_data' field" do
      let(:response) do
        {
          "name" => "data_bag_item_ridley-test_appconfig",
          "raw_data" => {
            "id" => "appconfig",
            "host" => "host.local"
          },
          "json_class" => "Chef::DataBagItem",
          "data_bag" => "ridley-test",
          "chef_type" => "data_bag_item"
        }
      end

      it "returns a new object from attributes in the 'raw_data' field" do
        subject.from_hash(response).attributes.should eql(response["raw_data"])
      end
    end

    context "when JSON does not contain a 'raw_data' field" do
      let(:response) do
        {
          "id" => "appconfig",
          "host" => "host.local"
        }
      end

      it "returns a new object from the hash" do
        subject.from_hash(response).attributes.should eql(response)
      end
    end
  end

  describe "#decrypt" do
    before(:each) do
      encrypted_data_bag_secret = File.read(fixtures_path.join("encrypted_data_bag_secret").to_s)
      connection.stub(:encrypted_data_bag_secret).and_return(encrypted_data_bag_secret)
    end

    it "decrypts an encrypted value" do
      subject.attributes[:test] = "Xk0E8lV9r4BhZzcg4wal0X4w9ZexN3azxMjZ9r1MCZc="
      subject.decrypt
      subject.attributes[:test][:database][:username].should == "test"
    end

    it "does not decrypt the id field" do
      id = "dbi_id"
      subject.attributes[:id] = id
      subject.decrypt
      subject.attributes[:id].should == id
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ridley-0.10.2 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.9.1 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.10.1 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.10.0 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.10.0.rc3 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.10.0.rc2 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.10.0.rc1 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.9.0 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.8.6 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.8.5 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.8.3 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.8.2 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.8.1 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.8.0 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.7.0 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.7.0.rc4 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.7.0.rc3 spec/unit/ridley/resources/data_bag_item_resource_spec.rb
ridley-0.7.0.rc1 spec/unit/ridley/resources/data_bag_item_resource_spec.rb