1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[patch] Change Model#attribute's :squash options to accept a String as well as a Symbol

* Spec to test "squashed" value patch
This commit is contained in:
Paul Thornthwaite 2010-09-08 16:09:21 +01:00 committed by geemus
parent 6b1ae6b844
commit d299ae1579
2 changed files with 30 additions and 2 deletions

View file

@ -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

View file

@ -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