You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/11/16 21:34:30 UTC

[PATCH core 1/4] CIMI: Added helper methods to check serialization and inconsistencies between JSON and XML

From: Michal Fojtik <mf...@redhat.com>

---
 server/spec/spec_helper.rb |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/server/spec/spec_helper.rb b/server/spec/spec_helper.rb
index d046260..c8b41fc 100644
--- a/server/spec/spec_helper.rb
+++ b/server/spec/spec_helper.rb
@@ -90,6 +90,16 @@ class HashCmp
   end
 end
 
+def should_serialize_from_xml!(model, xml, json)
+  model.to_xml.should serialize_to xml, :fmt => :xml
+  model.to_json.should serialize_to json, :fmt => :json
+end
+
+def should_serialize_from_json!(model, xml, json)
+  model.to_xml.should serialize_to xml, :fmt => :xml
+  model.to_json.should serialize_to json, :fmt => :json
+end
+
 RSpec::Matchers.define :serialize_to do |exp, opts|
   match do |act|
     matcher(exp, act, opts[:fmt]).match?
-- 
1.7.7.3


Re: [PATCH core 1/4] CIMI: Added helper methods to check serialization and inconsistencies between JSON and XML

Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK

On 16/11/11 22:34, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> ---
>  server/spec/spec_helper.rb |   10 ++++++++++
>  1 files changed, 10 insertions(+), 0 deletions(-)
> 
> diff --git a/server/spec/spec_helper.rb b/server/spec/spec_helper.rb
> index d046260..c8b41fc 100644
> --- a/server/spec/spec_helper.rb
> +++ b/server/spec/spec_helper.rb
> @@ -90,6 +90,16 @@ class HashCmp
>    end
>  end
>  
> +def should_serialize_from_xml!(model, xml, json)
> +  model.to_xml.should serialize_to xml, :fmt => :xml
> +  model.to_json.should serialize_to json, :fmt => :json
> +end
> +
> +def should_serialize_from_json!(model, xml, json)
> +  model.to_xml.should serialize_to xml, :fmt => :xml
> +  model.to_json.should serialize_to json, :fmt => :json
> +end
> +
>  RSpec::Matchers.define :serialize_to do |exp, opts|
>    match do |act|
>      matcher(exp, act, opts[:fmt]).match?


Re: [PATCH core 1/4] CIMI: Added helper methods to check serialization and inconsistencies between JSON and XML

Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2011-11-16 at 21:34 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> ---
>  server/spec/spec_helper.rb |   10 ++++++++++
>  1 files changed, 10 insertions(+), 0 deletions(-)
> 
> diff --git a/server/spec/spec_helper.rb b/server/spec/spec_helper.rb
> index d046260..c8b41fc 100644
> --- a/server/spec/spec_helper.rb
> +++ b/server/spec/spec_helper.rb
> @@ -90,6 +90,16 @@ class HashCmp
>    end
>  end
>  
> +def should_serialize_from_xml!(model, xml, json)
> +  model.to_xml.should serialize_to xml, :fmt => :xml
> +  model.to_json.should serialize_to json, :fmt => :json
> +end
> +
> +def should_serialize_from_json!(model, xml, json)
> +  model.to_xml.should serialize_to xml, :fmt => :xml
> +  model.to_json.should serialize_to json, :fmt => :json
> +end

Aren't these two methods doing exactly the same ? What I had in mind was

        def check_serialization(model_class, xml, json)
          # Roundtrip in same format
          model_class.from_xml(xml).should serialize_to xml, :fmt
        => :xml
          model_class.from_json(json).should serialize_to json, :fmt => :json
          # Roundtrip crossing format
          model_class.from_xml(xml).should serialize_to json, :fmt
        => :json
          model_class.from_json(json).should serialize_to xml, :fmt
        => :xml
        end

David