mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[core] treat boolean values as a boolean
This commit is contained in:
parent
d48ccac0ee
commit
321783ff56
2 changed files with 31 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue