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

[core] fix attributes to properly accomodate aliases

This commit is contained in:
geemus 2010-12-16 11:25:31 -08:00
parent d5a4b0180c
commit a5d65fc26e
2 changed files with 7 additions and 7 deletions

View file

@ -132,12 +132,12 @@ module Fog
def merge_attributes(new_attributes = {})
for key, value in new_attributes
unless self.class.ignored_attributes.include?(key)
if aliased_key = self.class.aliases[key.to_sym]
if aliased_key = self.class.aliases[key]
send("#{aliased_key}=", value)
elsif (public_methods | private_methods).detect {|method| ["#{key}=", :"#{key}="].include?(method)}
send("#{key}=", value)
else
attributes[key.to_sym] = value
attributes[key] = value
end
end
end

View file

@ -1,5 +1,5 @@
class FogAttributeTestModel < Fog::Model
attribute :key, :aliases => :keys, :squash => "id"
attribute :key, :aliases => 'keys', :squash => "id"
attribute :time, :type => :time
end
@ -9,13 +9,13 @@ Shindo.tests('Fog::Attributes', 'core') do
tests('squash') do
tests(':keys => {:id => "value"}').returns('value') do
@model.merge_attributes(:keys => {:id => "value"})
tests('"keys" => {:id => "value"}').returns('value') do
@model.merge_attributes("keys" => {:id => "value"})
@model.key
end
tests(':keys => {"id" => "value"}').returns('value') do
@model.merge_attributes(:keys => {'id' => "value"})
tests('"keys" => {"id" => "value"}').returns('value') do
@model.merge_attributes("keys" => {'id' => "value"})
@model.key
end