You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2013/02/11 18:14:41 UTC
git commit: Previously, if you assigned nil to properties,
ent_properties would end up being "null" which is not valid JSON.
Updated Branches:
refs/heads/master 9f8b70330 -> 5e74925f4
Previously, if you assigned nil to properties, ent_properties would end up
being "null" which is not valid JSON.
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/5e74925f
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/5e74925f
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/5e74925f
Branch: refs/heads/master
Commit: 5e74925f47706d5d6aaf39e9908c01cf8fcec88f
Parents: 9f8b703
Author: David Lutterkort <lu...@redhat.com>
Authored: Mon Feb 11 18:14:26 2013 +0100
Committer: Michal fojtik <mf...@redhat.com>
Committed: Mon Feb 11 18:14:26 2013 +0100
----------------------------------------------------------------------
server/lib/db/entity.rb | 5 +++++
server/tests/cimi/db/entity_test.rb | 29 +++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/5e74925f/server/lib/db/entity.rb
----------------------------------------------------------------------
diff --git a/server/lib/db/entity.rb b/server/lib/db/entity.rb
index 08ed70b..fa8109c 100644
--- a/server/lib/db/entity.rb
+++ b/server/lib/db/entity.rb
@@ -18,6 +18,11 @@ module Deltacloud
retval
end
+ def properties=(v)
+ # Make sure @properties is always a Hash
+ @properties = v || {}
+ end
+
def before_save
self.ent_properties = properties.to_json
super
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/5e74925f/server/tests/cimi/db/entity_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/cimi/db/entity_test.rb b/server/tests/cimi/db/entity_test.rb
new file mode 100644
index 0000000..4c31b66
--- /dev/null
+++ b/server/tests/cimi/db/entity_test.rb
@@ -0,0 +1,29 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+require 'minitest/autorun'
+
+require_relative 'db_helper.rb'
+require_relative '../spec_helper.rb'
+require_relative './../collections/common.rb'
+
+describe "Deltacloud::Database::Entity" do
+ Provider = Deltacloud::Database::Provider
+ Entity = Deltacloud::Database::Entity
+ BaseModel = CIMI::Model::Base
+
+ before do
+ ENV['RACK_ENV'] = 'development'
+ @prov = Provider::lookup
+ end
+
+ it 'newly created entities have valid ent_properties' do
+ model = BaseModel.new(:id => "/base/42")
+ ent = Entity.retrieve(model)
+ ent.properties = nil
+ ent.exists?.must_equal false
+ ent.save
+
+ ent = Entity.retrieve(model)
+ ent.exists?.must_equal true
+ end
+end