Permalink
Browse files

add basic spec for Measure class

  • Loading branch information...
1 parent 51606f0 commit dcf284e613715fd4c7ba47bcf5e67e963e15443b @yob committed Feb 27, 2009
Showing with 52 additions and 1 deletion.
  1. +6 −0 data/measure.xml
  2. +3 −1 lib/onix/measure.rb
  3. +43 −0 spec/measure_spec.rb
View
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Measure>
+ <MeasureTypeCode>01</MeasureTypeCode>
+ <Measurement>210</Measurement>
+ <MeasureUnitCode>mm</MeasureUnitCode>
+</Measure>
View
@@ -2,7 +2,9 @@ module ONIX
class Measure
include ROXML
- xml_accessor :measure_type_code, :from => "MeasureTypeCode", :as => Fixnum # should be a 2 digit num
+ xml_name "Measure"
+
+ xml_accessor :measure_type_code, :from => "MeasureTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
xml_accessor :measurement, :from => "Measurement", :as => BigDecimal
xml_accessor :measure_unit_code, :from => "MeasureUnitCode"
end
View
@@ -0,0 +1,43 @@
+# coding: utf-8
+
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
+
+require 'onix'
+
+context "ONIX::Measure" do
+
+ before(:each) do
+ data_path = File.join(File.dirname(__FILE__),"..","data")
+ file1 = File.join(data_path, "measure.xml")
+ @doc = LibXML::XML::Document.file(file1)
+ @root = @doc.root
+ end
+
+ specify "should correctly convert to a string" do
+ m = ONIX::Measure.from_xml(@root.to_s)
+ m.to_xml.to_s[0,9].should eql("<Measure>")
+ end
+
+ specify "should provide read access to first level attibutes" do
+ m = ONIX::Measure.from_xml(@root.to_s)
+
+ m.measure_type_code.should eql(1)
+ m.measurement.should eql(210)
+ m.measure_unit_code.should eql("mm")
+ end
+
+ specify "should provide write access to first level attibutes" do
+ m = ONIX::Measure.new
+
+ m.measure_type_code = 1
+ m.to_xml.to_s.include?("<MeasureTypeCode>01</MeasureTypeCode>").should be_true
+
+ m.measurement = 300
+ m.to_xml.to_s.include?("<Measurement>300</Measurement>").should be_true
+
+ m.measure_unit_code = "mm"
+ m.to_xml.to_s.include?("<MeasureUnitCode>mm</MeasureUnitCode>").should be_true
+ end
+
+end
+

0 comments on commit dcf284e

Please sign in to comment.