Skip to content

Commit

Permalink
Merge 85ce8f9 into ccc12c3
Browse files Browse the repository at this point in the history
  • Loading branch information
plribeiro3000 committed Aug 14, 2014
2 parents ccc12c3 + 85ce8f9 commit bc00f9d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 1 addition & 2 deletions lib/fog/core/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ def associations
end

def all_attributes
all_attributes = self.class.attributes.inject({}) do |hash, attribute|
self.class.attributes.inject({}) do |hash, attribute|
hash[attribute] = send(attribute)
hash
end
self.class.new(all_attributes).attributes
end

def dup
Expand Down
12 changes: 7 additions & 5 deletions spec/fog_attribute_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,15 @@ class FogMultipleAssociationsModel < Fog::Model
describe "on a persisted object" do
it "should return all attributes without default values" do
model.merge_attributes( :id => 2, :float => 3.2, :integer => 55555555 )
assert model.persisted?
assert_equal model.all_attributes, { :id => 2,
:key => nil,
:time => nil,
:bool => nil,
:float => 3.2,
:integer => 55555555,
:string => '',
:timestamp => Time.at(0),
:string => nil,
:timestamp => nil,
:array => [],
:default => nil,
:another_default => nil }
Expand All @@ -359,15 +360,16 @@ class FogMultipleAssociationsModel < Fog::Model

describe "on a new object" do
it "should return all attributes including default values for empty attributes" do
model.merge_attributes( :id => nil, :float => 3.2, :integer => 55555555 )
model.merge_attributes( :float => 3.2, :integer => 55555555 )
refute model.persisted?
assert_equal model.all_attributes, { :id => nil,
:key => nil,
:time => nil,
:bool => nil,
:float => 3.2,
:integer => 55555555,
:string => '',
:timestamp => Time.at(0),
:string => nil,
:timestamp => nil,
:array => [],
:default => 'default_value',
:another_default => false }
Expand Down

0 comments on commit bc00f9d

Please sign in to comment.