[core] treat boolean values as a boolean

This commit is contained in:
Peter Meier 2011-10-03 19:30:49 +02:00
parent d48ccac0ee
commit 321783ff56
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