On Mon, 2011-11-14 at 16:09 +0100, mfoj...@redhat.com wrote:
> From: Michal Fojtik <mfoj...@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mfoj...@redhat.com>
> ---

> diff --git a/server/lib/cimi/model/machine_configuration.rb 
> b/server/lib/cimi/model/machine_configuration.rb
> new file mode 100644
> index 0000000..221236c
> --- /dev/null
> +++ b/server/lib/cimi/model/machine_configuration.rb
> @@ -0,0 +1,28 @@

> +class CIMI::Model::MachineConfiguration < CIMI::Model::Base
> +
> +  scalar :memory

Model that as
        struct :memory do
                scalar :quantity
                scalar :units
        end

> +  text :cpu
> +
> +  array :disk do
> +    scalar :capacity
> +  end

That has to be _disks_; the convention is that arrays always use
pluralized names, i.e. the name that is used in JSON. In fact, the whole
exercise of the model layer is to create Ruby objects that you can talk
to as if you were in JavaScript and had just deserialized the JSON form
of the object.

One general remark about specs: we should have the following roundtrip
test for everything

        Model.from_xml(xml).to_xml.should serialize_to xml
        Model.from_json(json).to_json.should serialize_to json
        Model.from_xml(xml).to_json.should serialize_to json
        Model.from_json(json).to_xml.should serialize_to xml

The last two should help us catch inconsistencies in how we treat XML
vs. JSON (and I know that you have been writing the first two kinds of
tests)

The above four tests can be hidden in a helper

        def check_serialization(model_class, xml, json)
        
David


Reply via email to