diff --git a/lib/fog/core/attributes.rb b/lib/fog/core/attributes.rb index 26b74c6d1..83bccae79 100644 --- a/lib/fog/core/attributes.rb +++ b/lib/fog/core/attributes.rb @@ -73,8 +73,8 @@ module Fog class_eval <<-EOS, __FILE__, __LINE__ def #{name}=(new_data) if new_data.is_a?(Hash) - if new_data[:#{squash}] - @#{name} = new_data[:#{squash}] + if new_data[:#{squash}] || new_data["#{squash}"] + @#{name} = new_data[:#{squash}] || new_data["#{squash}"] else @#{name} = [ new_data ] end diff --git a/spec/core/attributes_spec.rb b/spec/core/attributes_spec.rb new file mode 100644 index 000000000..8095ce75d --- /dev/null +++ b/spec/core/attributes_spec.rb @@ -0,0 +1,28 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +class FogAttributeTestModel < Fog::Model + attribute :key_id, :aliases => "key", :squash => "id" +end + +describe 'Fog::Attributes' do + + describe ".attribute" do + describe "squashing a value" do + it "should accept squashed key as symbol" do + data = {"key" => {:id => "value"}} + model = FogAttributeTestModel.new + model.merge_attributes(data) + model.key_id.should == "value" + end + + it "should accept squashed key as string" do + data = {"key" => {"id" => "value"}} + model = FogAttributeTestModel.new + model.merge_attributes(data) + model.key_id.should == "value" + end + end + + end + +end \ No newline at end of file