Please review pull request #538: Don't stub the database in Puppet::Rails tests. opened by (daniel-pittman)

Description:

The tests for the Puppet::Rails::Host and other Rails interface class stubbed
out parts of rails, in a way that confused things later on and ended up
breaking unrelated tests ... but only when they were invoked in a very
particular order.

Thankfully, just using a scratch database is both cheap and easy here, and
makes this all just work. So, do that instead.

Signed-off-by: Daniel Pittman [email protected]

  • Opened: Wed Feb 29 01:44:16 UTC 2012
  • Based on: puppetlabs:2.7.x (2768b9cf3e386cf0e7188533f1af998e3e975928)
  • Requested merge: daniel-pittman:maint/2.7.x/test-failure-after-activerecord-cleanup (01c8623c2b5d630491b063c9ecbe514ac66cf3f5)

Diff follows:

diff --git a/spec/unit/rails/host_spec.rb b/spec/unit/rails/host_spec.rb
index 98541c0..f82dfda 100755
--- a/spec/unit/rails/host_spec.rb
+++ b/spec/unit/rails/host_spec.rb
@@ -3,16 +3,10 @@
 
 require 'puppet/node/environment'
 
-describe "Puppet::Rails::Host", :if => Puppet.features.rails? do
-  def column(name, type)
-    ActiveRecord::ConnectionAdapters::Column.new(name, nil, type, false)
-  end
-
+describe "Puppet::Rails::Host", :if => can_use_scratch_database? do
   before do
     require 'puppet/rails/host'
-
-    # Stub this so we don't need access to the DB.
-    Puppet::Rails::Host.stubs(:columns).returns([column("name", "string"), column("environment", "string"), column("ip", "string")])
+    setup_scratch_database
 
     @node = Puppet::Node.new("foo")
     @node.environment = "production"
@@ -96,7 +90,7 @@ def column(name, type)
 
   describe "when merging catalog resources and database resources" do
     before :each do
-      Puppet.settings.stubs(:[]).with(:thin_storeconfigs).returns(false)
+      Puppet[:thin_storeconfigs] = false
       @resource1 = stub_everything 'res1'
       @resource2 = stub_everything 'res2'
       @resources = [ @resource1, @resource2 ]
@@ -131,7 +125,7 @@ def column(name, type)
     end
 
     it "should compare only exported resources in thin_storeconfigs mode" do
-      Puppet.settings.stubs(:[]).with(:thin_storeconfigs).returns(true)
+      Puppet[:thin_storeconfigs] = true
       @resource1.stubs(:exported?).returns(true)
 
       @host.expects(:compare_to_catalog).with(@dbresources, [ @resource1 ])
@@ -142,7 +136,7 @@ def column(name, type)
 
   describe "when searching the database for host resources" do
     before :each do
-      Puppet.settings.stubs(:[]).with(:thin_storeconfigs).returns(false)
+      Puppet[:thin_storeconfigs] = false
       @resource1 = stub_everything 'res1', :id => 1
       @resource2 = stub_everything 'res2', :id => 2
       @resources = [ @resource1, @resource2 ]
@@ -159,7 +153,7 @@ def column(name, type)
     end
 
     it "should return a hash keyed by id of only exported resources in thin_storeconfigs mode" do
-      Puppet.settings.stubs(:[]).with(:thin_storeconfigs).returns(true)
+      Puppet[:thin_storeconfigs] = true
       @dbresources.expects(:find).with { |*h| h[1][:conditions] == { :exported => true } }.returns([])
 
       @host.find_resources
diff --git a/spec/unit/rails/param_value_spec.rb b/spec/unit/rails/param_value_spec.rb
index 7f00862..e7f4328 100755
--- a/spec/unit/rails/param_value_spec.rb
+++ b/spec/unit/rails/param_value_spec.rb
@@ -2,18 +2,13 @@
 require 'spec_helper'
 require 'puppet/rails'
 
-describe "Puppet::Rails::ParamValue", :if => Puppet.features.rails? do
-  def column(name, type)
-    ActiveRecord::ConnectionAdapters::Column.new(name, nil, type, false)
-  end
-
+describe "Puppet::Rails::ParamValue", :if => can_use_scratch_database? do
   before do
     require 'puppet/rails/param_value'
-
-    name = stub 'param_name', :name => "foo"
+    setup_scratch_database
 
     # Stub this so we don't need access to the DB.
-    Puppet::Rails::ParamValue.stubs(:columns).returns([column("value", "string")])
+    name = stub 'param_name', :name => "foo"
     Puppet::Rails::ParamName.stubs(:find_or_create_by_name).returns(name)
   end
 
diff --git a/spec/unit/rails/resource_spec.rb b/spec/unit/rails/resource_spec.rb
index 22e5267..4202df4 100755
--- a/spec/unit/rails/resource_spec.rb
+++ b/spec/unit/rails/resource_spec.rb
@@ -2,16 +2,10 @@
 require 'spec_helper'
 require 'puppet/rails'
 
-describe "Puppet::Rails::Resource", :if => Puppet.features.rails? do
-  def column(name, type)
-    ActiveRecord::ConnectionAdapters::Column.new(name, nil, type, false)
-  end
-
+describe "Puppet::Rails::Resource", :if => can_use_scratch_database? do
   before do
     require 'puppet/rails/resource'
-
-    # Stub this so we don't need access to the DB.
-    Puppet::Rails::Resource.stubs(:columns).returns([column("title", "string"), column("restype", "string"), column("exported", "boolean")])
+    setup_scratch_database
   end
 
   describe "when creating initial resource arguments" do

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to