summaryrefslogtreecommitdiffstats
path: root/spec/unit/util/monkey_patches_spec.rb
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2010-09-08 11:31:00 -0700
committerPaul Berry <paul@puppetlabs.com>2010-10-07 13:47:12 -0700
commit3c4412128a50e41380108e5a90f2656329b84492 (patch)
treea516f1f6459b366542dd9a4f116f6a7c89ba3fc0 /spec/unit/util/monkey_patches_spec.rb
parentfb9034731ddae41f1009745eb8eb1ea53aa05cfb (diff)
downloadpuppet-3c4412128a50e41380108e5a90f2656329b84492.tar.gz
puppet-3c4412128a50e41380108e5a90f2656329b84492.tar.xz
puppet-3c4412128a50e41380108e5a90f2656329b84492.zip
[#4590] SimpleGraph is slow
Rewrote SimpleGraph to use a more efficient internal representation. To preserve compatibility with older clients, graphs are still serialized to YAML using the format used by Puppet 2.6. However, a newer, more compact format can be enabled by setting "use_new_yaml_format" to true. Deserialization from YAML accepts either the old 2.6 format or the newer format. In a later release, once we no longer need to be compatible with 2.6, we will be able to switch to the new format. To make deserialization accept multiple formats, it was necessary to use the yaml_initialize method. This method is not supported in versions of Ruby prior to 1.8.3, so a monkey patch is included to add support for it to Ruby 1.8.1 and 1.8.2. Thanks to Markus Roberts for the SimpleGraph rewrite. Thanks to Jesse Wolfe for figuring out how to write the yaml_initialize monkey patch.
Diffstat (limited to 'spec/unit/util/monkey_patches_spec.rb')
-rw-r--r--spec/unit/util/monkey_patches_spec.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/unit/util/monkey_patches_spec.rb b/spec/unit/util/monkey_patches_spec.rb
index b0f61c808..049ed1044 100644
--- a/spec/unit/util/monkey_patches_spec.rb
+++ b/spec/unit/util/monkey_patches_spec.rb
@@ -5,3 +5,29 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f
require 'puppet/util/monkey_patches'
+
+describe "yaml deserialization" do
+ it "should call yaml_initialize when deserializing objects that have that method defined" do
+ class Puppet::TestYamlInitializeClass
+ attr_reader :foo
+
+ def yaml_initialize(tag, var)
+ var.should == {'foo' => 100}
+ instance_variables.should == []
+ @foo = 200
+ end
+ end
+
+ obj = YAML.load("--- !ruby/object:Puppet::TestYamlInitializeClass\n foo: 100")
+ obj.foo.should == 200
+ end
+
+ it "should not call yaml_initialize if not defined" do
+ class Puppet::TestYamlNonInitializeClass
+ attr_reader :foo
+ end
+
+ obj = YAML.load("--- !ruby/object:Puppet::TestYamlNonInitializeClass\n foo: 100")
+ obj.foo.should == 100
+ end
+end