diff options
| author | Markus Roberts <Markus@reality.com> | 2009-10-09 15:23:19 -0700 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-10-17 12:23:33 +1100 |
| commit | bca3b70437666a8b840af032cab20fc1ea4f18a2 (patch) | |
| tree | 0cde5cd7b39fc5a5e41b636d1f55a7ed71d6518b /spec/unit/network | |
| parent | ce46be5773656f68eddc7edd6212e283b46f9320 (diff) | |
Bundling of pure ruby json lib as "pson"
Bundeling and renaming the pure ruby json library to addresses a
number of cross version serliaization bugs (#2615, et al).
This patch adds a subset of the files from the json_pure gem to
lib/puppet/external/pson (renamed to avoid conflicts with rails) so
that we will always have a known-good erialization format available.
The pure ruby json gem as distibuted defers to the compiled version
if it is installed. This is problematic in some circumstances so the
files that have been brought over have been modified to always and
only use the bundled version.
It's a large patch, so here's a breakdown of the change categories:
The majority of the lines are only marginally interesting:
* The json lib itself (in lib/puppet/external/pson) make up the bulk
of the lines.
* Renaming of json to pson make up the second largest group.
Somewhat more interesting are the following, which can be located by
searching the diffs for the indicated strings:
* Adjusting tests to reflect the changes
* Changing the encoding/decoding behavior so that nested structures
(e.g. resources) don't serialize as escaped strings. This should
make it much easier to process the results with external tools, if
needed. Search for "to_pson" and "to_pson_data_hash"
* Cleaning up the envelope/metadata
* Now provides a document_type (as opposed to a ruby class name) by
using a symple registration scheme instead of constant lookup
(search for "document_type")
* Added an api_version (search for "api_version")
* Added a hash for document metadata (search for "metadata")
* Removing the yaml monkeypatch and instead disabling yaml serialization
on ruby 1.8.1 in favor of pson (search for "yaml")
* Cleaning up the json/rails feature interaction (they're now totally
independent) (search for "feature")
Diffstat (limited to 'spec/unit/network')
| -rwxr-xr-x | spec/unit/network/formats.rb | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/spec/unit/network/formats.rb b/spec/unit/network/formats.rb index c766f55f0..de2e0afe3 100755 --- a/spec/unit/network/formats.rb +++ b/spec/unit/network/formats.rb @@ -4,13 +4,13 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/network/formats' -class JsonTest +class PsonTest attr_accessor :string def ==(other) string == other.string end - def self.from_json(data) + def self.from_pson(data) new(data) end @@ -18,11 +18,11 @@ class JsonTest @string = string end - def to_json(*args) + def to_pson(*args) { - 'json_class' => self.class.name, + 'type' => self.class.name, 'data' => @string - }.to_json(*args) + }.to_pson(*args) end end @@ -173,76 +173,76 @@ describe "Puppet Network Format" do end end - it "should include a json format" do - Puppet::Network::FormatHandler.format(:json).should_not be_nil + it "should include a pson format" do + Puppet::Network::FormatHandler.format(:pson).should_not be_nil end - describe "json" do - confine "Missing 'json' library" => Puppet.features.json? + describe "pson" do + confine "Missing 'pson' library" => Puppet.features.pson? before do - @json = Puppet::Network::FormatHandler.format(:json) + @pson = Puppet::Network::FormatHandler.format(:pson) end - it "should have its mime type set to text/json" do - Puppet::Network::FormatHandler.format(:json).mime.should == "text/json" + it "should have its mime type set to text/pson" do + Puppet::Network::FormatHandler.format(:pson).mime.should == "text/pson" end it "should require the :render_method" do - Puppet::Network::FormatHandler.format(:json).required_methods.should be_include(:render_method) + Puppet::Network::FormatHandler.format(:pson).required_methods.should be_include(:render_method) end it "should require the :intern_method" do - Puppet::Network::FormatHandler.format(:json).required_methods.should be_include(:intern_method) + Puppet::Network::FormatHandler.format(:pson).required_methods.should be_include(:intern_method) end it "should have a weight of 10" do - @json.weight.should == 10 + @pson.weight.should == 10 end describe "when supported" do - it "should render by calling 'to_json' on the instance" do - instance = JsonTest.new("foo") - instance.expects(:to_json).returns "foo" - @json.render(instance).should == "foo" + it "should render by calling 'to_pson' on the instance" do + instance = PsonTest.new("foo") + instance.expects(:to_pson).returns "foo" + @pson.render(instance).should == "foo" end - it "should render multiple instances by calling 'to_json' on the array" do + it "should render multiple instances by calling 'to_pson' on the array" do instances = [mock('instance')] - instances.expects(:to_json).returns "foo" + instances.expects(:to_pson).returns "foo" - @json.render_multiple(instances).should == "foo" + @pson.render_multiple(instances).should == "foo" end - it "should intern by calling 'JSON.parse' on the text and then using from_json to convert the data into an instance" do + it "should intern by calling 'PSON.parse' on the text and then using from_pson to convert the data into an instance" do text = "foo" - JSON.expects(:parse).with("foo").returns("json_class" => "JsonTest", "data" => "foo") - JsonTest.expects(:from_json).with("foo").returns "parsed_json" - @json.intern(JsonTest, text).should == "parsed_json" + PSON.expects(:parse).with("foo").returns("type" => "PsonTest", "data" => "foo") + PsonTest.expects(:from_pson).with("foo").returns "parsed_pson" + @pson.intern(PsonTest, text).should == "parsed_pson" end - it "should not render twice if 'JSON.parse' creates the appropriate instance" do + it "should not render twice if 'PSON.parse' creates the appropriate instance" do text = "foo" - instance = JsonTest.new("foo") - JSON.expects(:parse).with("foo").returns(instance) - JsonTest.expects(:from_json).never - @json.intern(JsonTest, text).should equal(instance) + instance = PsonTest.new("foo") + PSON.expects(:parse).with("foo").returns(instance) + PsonTest.expects(:from_pson).never + @pson.intern(PsonTest, text).should equal(instance) end - it "should intern by calling 'JSON.parse' on the text and then using from_json to convert the actual into an instance if the json has no class/data separation" do + it "should intern by calling 'PSON.parse' on the text and then using from_pson to convert the actual into an instance if the pson has no class/data separation" do text = "foo" - JSON.expects(:parse).with("foo").returns("foo") - JsonTest.expects(:from_json).with("foo").returns "parsed_json" - @json.intern(JsonTest, text).should == "parsed_json" + PSON.expects(:parse).with("foo").returns("foo") + PsonTest.expects(:from_pson).with("foo").returns "parsed_pson" + @pson.intern(PsonTest, text).should == "parsed_pson" end it "should intern multiples by parsing the text and using 'class.intern' on each resulting data structure" do text = "foo" - JSON.expects(:parse).with("foo").returns ["bar", "baz"] - JsonTest.expects(:from_json).with("bar").returns "BAR" - JsonTest.expects(:from_json).with("baz").returns "BAZ" - @json.intern_multiple(JsonTest, text).should == %w{BAR BAZ} + PSON.expects(:parse).with("foo").returns ["bar", "baz"] + PsonTest.expects(:from_pson).with("bar").returns "BAR" + PsonTest.expects(:from_pson).with("baz").returns "BAZ" + @pson.intern_multiple(PsonTest, text).should == %w{BAR BAZ} end end end |
