Sha256: 970566bcf70d3ba04e5450408d37635639c06341445a9b2814c71289d613e0bc
Contents?: true
Size: 1.47 KB
Versions: 3
Compression:
Stored size: 1.47 KB
Contents
require "spec_helper" RSpec.describe Brightbox::Api, "#attributes" do subject(:model_attributes) { api_model.attributes } let(:api_model) { Brightbox::Api.new(fog_model) } let(:fog_model) do double( "Fog::Compute::Brightbox::Api", id: "res-12345", attributes: attributes ) end context "when attributes are not set" do let(:attributes) { nil } it "returns an indifferent access hash" do expect(model_attributes).to be_instance_of(IndifferentAccessHash) end end context "when attributes are set with a mix of string and symbols" do let(:attributes) do { id: "res-12345", name: "test", acme: acme_details } end let(:acme_details) do { "domains" => [ { "identifier" => "example.test", "status" => "pending" } ] } end it "transforms the keys with deep symbolize" do expect(model_attributes).to eq( id: "res-12345", name: "test", acme: { domains: [ { identifier: "example.test", status: "pending" } ] } ) end it "can accessed by string keys" do expect(model_attributes["acme"]["domains"].first["identifier"]).to eq("example.test") end it "can accessed by symbol keys" do expect(model_attributes[:acme][:domains].first[:identifier]).to eq("example.test") end end end
Version data entries
3 entries across 3 versions & 1 rubygems