Skip to content

Commit

Permalink
[patch] Change Model#attribute's :squash options to accept a String a…
Browse files Browse the repository at this point in the history
…s well as a Symbol

* Spec to test "squashed" value patch
  • Loading branch information
tokengeek authored and geemus committed Nov 16, 2010
1 parent 6b1ae6b commit d299ae1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/fog/core/attributes.rb
Expand Up @@ -73,8 +73,8 @@ def #{name}=(new_#{name})
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_data)
if new_data.is_a?(Hash)
if new_data[:#{squash}]
@#{name} = new_data[:#{squash}]
if new_data[:#{squash}] || new_data["#{squash}"]
@#{name} = new_data[:#{squash}] || new_data["#{squash}"]
else
@#{name} = [ new_data ]
end
Expand Down
28 changes: 28 additions & 0 deletions spec/core/attributes_spec.rb
@@ -0,0 +1,28 @@
require File.dirname(__FILE__) + '/../spec_helper'

class FogAttributeTestModel < Fog::Model
attribute :key_id, :aliases => "key", :squash => "id"
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

end

end

0 comments on commit d299ae1

Please sign in to comment.