temando
Advanced tools
| require 'spec_helper' | ||
| describe Temando::Api::Entities::Anything do | ||
| let(:item) { valid_temando_item(:description => 'Contains hats.', :quantity => 2) } | ||
| describe ".converted_weight" do | ||
| it "formats large weights as Kilograms" do | ||
| item.weight = 10.2 | ||
| entity = Temando::Api::Entities::Anything.new(item) | ||
| entity.converted_weight.should == 11 | ||
| entity.weight_units.should == 'Kilograms' | ||
| end | ||
| it "formats medium weights as Grams" do | ||
| item.weight = 9.2 | ||
| entity = Temando::Api::Entities::Anything.new(item) | ||
| entity.converted_weight.should == 9200 | ||
| entity.weight_units.should == 'Grams' | ||
| end | ||
| it "formats small weights as Grams" do | ||
| item.weight = 0.033 | ||
| entity = Temando::Api::Entities::Anything.new(item) | ||
| entity.converted_weight.should == 33 | ||
| entity.weight_units.should == 'Grams' | ||
| end | ||
| end | ||
| end |
@@ -8,2 +8,18 @@ module Temando::Api | ||
| def weight_units | ||
| if @anything.weight < 9.5 then | ||
| 'Grams' | ||
| else | ||
| 'Kilograms' | ||
| end | ||
| end | ||
| def converted_weight | ||
| if weight_units == 'Grams' then | ||
| (@anything.weight * 1000).ceil | ||
| else | ||
| @anything.weight.ceil | ||
| end | ||
| end | ||
| def build_xml(xml) | ||
@@ -15,9 +31,11 @@ xml.anything do | ||
| xml.packaging @anything.shipping_packaging | ||
| xml.palletType @anything.pallet_type unless @anything.pallet_type.nil? | ||
| xml.palletNature @anything.pallet_nature unless @anything.pallet_nature.nil? | ||
| xml.qualifierFreightGeneralFragile(@anything.fragile ? 'Y' : 'N') | ||
| xml.distanceMeasurementType 'Centimetres' | ||
| xml.weightMeasurementType 'Kilograms' | ||
| xml.weightMeasurementType weight_units | ||
| xml.length((@anything.length.to_f * 100).ceil) | ||
| xml.width((@anything.width.to_f * 100).ceil) | ||
| xml.height((@anything.height.to_f * 100).ceil) | ||
| xml.weight @anything.weight.ceil | ||
| xml.weight converted_weight | ||
| xml.quantity @anything.quantity | ||
@@ -24,0 +42,0 @@ xml.description @anything.description |
@@ -5,2 +5,9 @@ module Temando | ||
| class GeneralGoods < Temando::Item::Base | ||
| attr_accessor :shipping_packaging, :pallet_type, :pallet_nature | ||
| def initialize(attributes={}) | ||
| @shipping_packaging = 'Parcel' | ||
| super | ||
| end | ||
| def shipping_class | ||
@@ -14,6 +21,2 @@ 'General Goods' | ||
| def shipping_packaging | ||
| 'Parcel' | ||
| end | ||
| def fragile | ||
@@ -23,3 +26,3 @@ false | ||
| end | ||
| end | ||
| end | ||
| end |
| module Temando | ||
| VERSION = "0.1.3" | ||
| VERSION = "0.1.4" | ||
| end |
@@ -21,7 +21,7 @@ <?xml version="1.0" encoding="UTF-8"?> | ||
| <distanceMeasurementType>Centimetres</distanceMeasurementType> | ||
| <weightMeasurementType>Kilograms</weightMeasurementType> | ||
| <weightMeasurementType>Grams</weightMeasurementType> | ||
| <length>10</length> | ||
| <width>10</width> | ||
| <height>10</height> | ||
| <weight>1</weight> | ||
| <weight>1000</weight> | ||
| <quantity>2</quantity> | ||
@@ -28,0 +28,0 @@ <description>Contains hats.</description> |
@@ -21,2 +21,36 @@ require 'spec_helper' | ||
| end | ||
| describe ".shipping_packaging" do | ||
| it 'defaults to "Parcel"' do | ||
| valid_item.shipping_packaging.should == 'Parcel' | ||
| end | ||
| it 'can be set and read' do | ||
| valid_item.shipping_packaging = 'Pallet' | ||
| valid_item.shipping_packaging.should == 'Pallet' | ||
| end | ||
| end | ||
| describe ".pallet_type" do | ||
| it 'defaults to nil' do | ||
| valid_item.pallet_type.should be_nil | ||
| end | ||
| it 'can be set and read' do | ||
| valid_item.pallet_type = 'Plain' | ||
| valid_item.pallet_type.should == 'Plain' | ||
| end | ||
| end | ||
| describe ".pallet_nature" do | ||
| it 'defaults to nil' do | ||
| valid_item.pallet_nature.should be_nil | ||
| end | ||
| it 'can be set and read' do | ||
| valid_item.pallet_nature = 'Not Required' | ||
| valid_item.pallet_nature.should == 'Not Required' | ||
| end | ||
| end | ||
| end |
+1
-0
@@ -25,2 +25,3 @@ # -*- encoding: utf-8 -*- | ||
| gem.add_development_dependency 'faker' | ||
| gem.add_development_dependency 'rake' | ||
| end |