more attributes spec to tests, fix attribute names

This commit is contained in:
geemus 2010-12-15 14:05:55 -08:00
parent b756990173
commit b689650666
3 changed files with 47 additions and 54 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]
if aliased_key = self.class.aliases[key.to_sym]
send("#{aliased_key}=", value)
elsif (public_methods | private_methods).detect {|method| ["#{key}=", :"#{key}="].include?(method)}
send("#{key}=", value)
else
attributes[key] = value
attributes[key.to_sym] = value
end
end
end

View File

@ -1,52 +0,0 @@
require File.dirname(__FILE__) + '/../spec_helper'
class FogAttributeTestModel < Fog::Model
attribute :key_id, :aliases => "key", :squash => "id"
attribute :time, :type => :time
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
describe "when merging a time field" do
it "should accept nil as a suitable setting" do
data = {"time" => nil}
model = FogAttributeTestModel.new
model.merge_attributes(data)
model.time.should be_nil
end
it "should accept empty string as a suitable setting" do
data = {"time" => ""}
model = FogAttributeTestModel.new
model.merge_attributes(data)
model.time.should == ""
end
it "should parse strings to get a Datetime" do
test_time = Time.parse("2010-11-12T13:14:15")
data = {"time" => test_time.to_s}
model = FogAttributeTestModel.new
model.merge_attributes(data)
model.time.should == test_time
end
end
end
end

View File

@ -0,0 +1,45 @@
class FogAttributeTestModel < Fog::Model
attribute :key, :aliases => :keys, :squash => "id"
attribute :time, :type => :time
end
Shindo.tests('Fog::Attributes', 'core') do
@model = FogAttributeTestModel.new
tests('squash') do
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"})
@model.key
end
end
tests(':type => :time') do
@time = Time.now
tests(':time => nil').returns(nil) do
@model.merge_attributes(:time => nil)
@model.time
end
tests(':time => ""').returns('') do
@model.merge_attributes(:time => '')
@model.time
end
tests(':time => "#{@time.to_s}"').returns(Time.parse(@time.to_s)) do
@model.merge_attributes(:time => @time.to_s)
@model.time
end
end
end