deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [2/8] git commit: Tests: Fixed failing tests when using DataMapper
Date Fri, 30 Nov 2012 08:48:24 GMT
Tests: Fixed failing tests when using DataMapper

DataMapper for (currently) unknown reason break Rack::Test.
This patch will disable persistence layer for tests.


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/a9212ed4
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/a9212ed4
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/a9212ed4

Branch: refs/heads/master
Commit: a9212ed4eff820576f63f9e6640a39fb83065c88
Parents: 6ffe667
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Thu Nov 29 15:24:22 2012 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Fri Nov 30 09:46:50 2012 +0100

----------------------------------------------------------------------
 server/lib/db.rb |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9212ed4/server/lib/db.rb
----------------------------------------------------------------------
diff --git a/server/lib/db.rb b/server/lib/db.rb
index db98709..ac6d913 100644
--- a/server/lib/db.rb
+++ b/server/lib/db.rb
@@ -1,10 +1,21 @@
 module Deltacloud
 
-  require 'data_mapper'
+  def self.test_environment?
+    ENV['RACK_ENV'] == 'test'
+  end
 
-  require_relative './db/provider'
-  require_relative './db/entity'
-  require_relative './db/machine_template'
+  module Database
+    def test_environment?
+      Deltacloud.test_environment?
+    end
+  end
+
+  unless test_environment?
+    require 'data_mapper'
+    require_relative './db/provider'
+    require_relative './db/entity'
+    require_relative './db/machine_template'
+  end
 
   DATABASE_LOCATION = ENV['DATABASE_LOCATION'] || "/var/tmp/deltacloud-mock-#{ENV['USER']}/db.sqlite"
 
@@ -20,16 +31,19 @@ module Deltacloud
       include Deltacloud::Database
 
       def store_attributes_for(model, values={})
+        return if test_environment?
         return if model.nil? or values.empty?
         current_db.entities.first_or_create(:be_kind => model.to_entity, :be_id =>
model.id).update(values)
       end
 
       def load_attributes_for(model)
+        return {} if test_environment?
         entity = get_entity(model)
         entity.nil? ? {} : entity.to_hash
       end
 
       def delete_attributes_for(model)
+        return if test_environment?
         get_entity(model).destroy
       end
 
@@ -53,4 +67,4 @@ module Deltacloud
 
 end
 
-Deltacloud::initialize_database
+Deltacloud::initialize_database unless Deltacloud.test_environment?


Mime
View raw message