Sha256: 8921651502892d55561c8045981d886781e80e06c6bd420ed9d85f9c033a0b1e

Contents?: true

Size: 1.22 KB

Versions: 11

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

describe EY::CloudClient::ApiStruct do
  class Foo < EY::CloudClient::ApiStruct.new(:fruit, :veggie); end

  it "acts like a normal struct" do
    f = Foo.new(cloud_client, "fruit" => "banana")

    f.fruit.should == "banana"
  end

  describe "from_hash initializer" do
    it "assigns values from string keys" do
      f = Foo.from_hash(cloud_client, "fruit" => "banana")
      f.should == Foo.new(cloud_client, "fruit" => "banana")
    end

    it "assigns values from symbol keys" do
      f = Foo.from_hash(cloud_client, :fruit => "banana")
      f.should == Foo.new(cloud_client, "fruit" => "banana")
    end
  end

  describe "from_array initializer" do
    it "provides a from_array initializer" do
      f = Foo.from_array(cloud_client, [:fruit => "banana"])
      f.should == [Foo.new(cloud_client, "fruit" => "banana")]
    end

    it "handles a common-arguments hash as the second argument" do
      foos = Foo.from_array(cloud_client,
        [{:fruit => "banana"}, {:fruit => 'apple'}],
        :veggie => 'kale')
      foos.should == [
        Foo.new(cloud_client, "fruit" => "banana", "veggie" => "kale"),
        Foo.new(cloud_client, "fruit" => "apple",  "veggie" => "kale"),
      ]
    end
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
engineyard-cloud-client-1.0.8 spec/engineyard-cloud-client/models/api_struct_spec.rb
engineyard-cloud-client-1.0.7 spec/engineyard-cloud-client/models/api_struct_spec.rb
engineyard-cloud-client-1.0.6 spec/engineyard-cloud-client/models/api_struct_spec.rb
engineyard-cloud-client-1.0.5 spec/engineyard-cloud-client/models/api_struct_spec.rb
engineyard-cloud-client-1.0.4 spec/engineyard-cloud-client/models/api_struct_spec.rb
engineyard-cloud-client-1.0.3 spec/engineyard-cloud-client/models/api_struct_spec.rb
engineyard-cloud-client-1.0.2 spec/engineyard-cloud-client/models/api_struct_spec.rb
engineyard-cloud-client-1.0.1 spec/engineyard-cloud-client/models/api_struct_spec.rb
engineyard-cloud-client-1.0.0 spec/engineyard-cloud-client/models/api_struct_spec.rb
engineyard-cloud-client-0.1.4 spec/engineyard-cloud-client/models/api_struct_spec.rb
engineyard-cloud-client-0.1.2 spec/engineyard-cloud-client/models/api_struct_spec.rb