Calling this method caused storeconfigs not to run.

ActiveRecord::Base.allow_concurrency was deprecated in Rails 2.2.  We
support activerecord 2.1 and higher, so we still need to call this
method for 2.1.  I factored out the code that determines our
activerecord version to a method in util so that the code was easier to
read and test.

Signed-off-by: Matt Robinson <[email protected]>
---
 lib/puppet/feature/rails.rb |    4 +---
 lib/puppet/rails.rb         |    6 +++---
 lib/puppet/util.rb          |    8 ++++++++
 spec/unit/rails_spec.rb     |   14 ++++++++++----
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/lib/puppet/feature/rails.rb b/lib/puppet/feature/rails.rb
index 2763b06..74ed09a 100644
--- a/lib/puppet/feature/rails.rb
+++ b/lib/puppet/feature/rails.rb
@@ -24,9 +24,7 @@ Puppet.features.add(:rails) do
     end
   end
 
-  if ! (defined?(::ActiveRecord) and defined?(::ActiveRecord::VERSION) and 
defined?(::ActiveRecord::VERSION::MAJOR) and 
defined?(::ActiveRecord::VERSION::MINOR))
-    false
-  elsif ! (([::ActiveRecord::VERSION::MAJOR, 
::ActiveRecord::VERSION::MINOR].join('.').to_f) >= 2.1)
+  unless (Puppet::Util.activerecord_version >= 2.1)
     Puppet.info "ActiveRecord 2.1 or later required for StoreConfigs"
     false
   else
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb
index 6bf5d4a..c2d492f 100644
--- a/lib/puppet/rails.rb
+++ b/lib/puppet/rails.rb
@@ -2,6 +2,7 @@
 
 require 'facter'
 require 'puppet'
+require 'logger'
 
 module Puppet::Rails
   TIME_DEBUG = true
@@ -22,9 +23,8 @@ module Puppet::Rails
       ActiveRecord::Base.logger.level = Logger::DEBUG
     end
 
-    if (([::ActiveRecord::VERSION::MAJOR, 
::ActiveRecord::VERSION::MINOR].join('.').to_f) >= 2.1)
-      ActiveRecord::Base.allow_concurrency = true
-    end
+    # As of ActiveRecord 2.2 allow_concurrency has been deprecated and no 
longer has any effect.
+    ActiveRecord::Base.allow_concurrency = true if 
Puppet::Util.activerecord_version < 2.2
 
     ActiveRecord::Base.verify_active_connections!
 
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index bb41270..f2eaf0d 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -20,6 +20,14 @@ module Util
   # Create a hash to store the different sync objects.
   @@syncresources = {}
 
+  def self.activerecord_version
+    if (defined?(::ActiveRecord) and defined?(::ActiveRecord::VERSION) and 
defined?(::ActiveRecord::VERSION::MAJOR) and 
defined?(::ActiveRecord::VERSION::MINOR))
+      ([::ActiveRecord::VERSION::MAJOR, 
::ActiveRecord::VERSION::MINOR].join('.').to_f)
+    else
+      0
+    end
+  end
+
   # Return the sync object associated with a given resource.
   def self.sync(resource)
     @@syncresources[resource] ||= Sync.new
diff --git a/spec/unit/rails_spec.rb b/spec/unit/rails_spec.rb
index 13c5a8a..01e822f 100755
--- a/spec/unit/rails_spec.rb
+++ b/spec/unit/rails_spec.rb
@@ -47,14 +47,20 @@ describe Puppet::Rails, "when initializing any connection" 
do
     Puppet::Rails.connect
   end
 
-  describe "on ActiveRecord 2.1.x" do
-    confine("ActiveRecord 2.1.x") { ([::ActiveRecord::VERSION::MAJOR, 
::ActiveRecord::VERSION::MINOR].join('.').to_f) >= 2.1 }
-
-    it "should set ActiveRecord::Base.allow_concurrency" do
+  describe "ActiveRecord Version" do
+    it "should set ActiveRecord::Base.allow_concurrency if ActiveRecord is 
2.1" do
+      Puppet::Util.stubs(:activerecord_version).returns(2.1)
       ActiveRecord::Base.expects(:allow_concurrency=).with(true)
 
       Puppet::Rails.connect
     end
+
+    it "should not set ActiveRecord::Base.allow_concurrency if ActiveRecord is 
>= 2.2" do
+      Puppet::Util.stubs(:activerecord_version).returns(2.2)
+      ActiveRecord::Base.expects(:allow_concurrency=).never
+
+      Puppet::Rails.connect
+    end
   end
 
   it "should call ActiveRecord::Base.verify_active_connections!" do
-- 
1.7.1

-- 
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