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

Merge pull request #536 from duritong/attributes

[core] treat boolean values as a boolean
This commit is contained in:
Wesley Beary 2011-10-03 11:52:48 -07:00
commit 1c4c199f1f
2 changed files with 31 additions and 2 deletions

View file

@ -25,9 +25,9 @@ module Fog
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = case new_#{name}
when 'true'
when true,'true'
true
when 'false'
when false,'false'
false
end
end

View file

@ -1,6 +1,7 @@
class FogAttributeTestModel < Fog::Model
attribute :key, :aliases => 'keys', :squash => "id"
attribute :time, :type => :time
attribute :bool, :type => :boolean
end
Shindo.tests('Fog::Attributes', 'core') do
@ -51,4 +52,32 @@ Shindo.tests('Fog::Attributes', 'core') do
end
tests(':type => :boolean') do
tests(':bool => "true"').returns(true) do
@model.merge_attributes(:bool => 'true')
@model.bool
end
tests(':bool => true').returns(true) do
@model.merge_attributes(:bool => true)
@model.bool
end
tests(':bool => "false"').returns(false) do
@model.merge_attributes(:bool => 'false')
@model.bool
end
tests(':bool => false').returns(false) do
@model.merge_attributes(:bool => false)
@model.bool
end
tests(':bool => "foo"').returns(nil) do
@model.merge_attributes(:bool => "foo")
@model.bool
end
end
end