spec/dynamoid/persistence_spec.rb in dynamoid-0.2.0 vs spec/dynamoid/persistence_spec.rb in dynamoid-0.3.0
- old
+ new
@@ -78,15 +78,39 @@
@subscription = Subscription.create(:length => 10)
@magazine = @subscription.magazine.create
@subscription.send(:dump)[:magazine_ids].should == Set[@magazine.id]
end
+
+ it 'handles nil attributes properly' do
+ Address.undump(nil).should be_a(Hash)
+ end
+
+ it 'dumps and undump a serialized field' do
+ @address.options = (hash = {:x => [1, 2], "foobar" => 3.14})
+ Address.undump(@address.send(:dump))[:options].should == hash
+ end
+
+ it 'loads a hash into a serialized field' do
+ hash = {foo: :bar}
+ Address.new(options: hash).options.should == hash
+ end
it 'loads attributes from a hash' do
@time = DateTime.now
@hash = {:name => 'Josh', :created_at => @time.to_f}
User.undump(@hash)[:name].should == 'Josh'
User.undump(@hash)[:created_at].to_f == @time.to_f
+ end
+
+ it 'tracks previous changes on save or update' do
+ @address.city = 'Chicago'
+ @address.save
+
+ @address.city = 'San Francisco'
+ @address.save
+
+ @address.city_was.should == 'Chicago'
end
end