Sha256: 96bbf3c6d58f2232268b14731634ab1dee9f66050898d84453a81d2496a37e71

Contents?: true

Size: 980 Bytes

Versions: 4

Compression:

Stored size: 980 Bytes

Contents

require 'spec_helper'

describe EY::Account::ApiStruct do
  class Foo < EY::Account::ApiStruct.new(:fruit); end
  class FooWithAccount < EY::Account::ApiStruct.new(:fruit, :account); end

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

    f.fruit.should == "banana"
  end

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

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

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

    it "handles an account as the second argument" do
      f = FooWithAccount.from_array([:fruit => "banana"], "account")
      f.should == [FooWithAccount.new("banana", "account")]
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
engineyard-0.3.1 spec/engineyard/account/api_struct_spec.rb
engineyard-0.3.0 spec/engineyard/account/api_struct_spec.rb
engineyard-0.2.13 spec/engineyard/account/api_struct_spec.rb
engineyard-0.2.12 spec/engineyard/account/api_struct_spec.rb