Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

basic specs for ProductIdentifier class

  • Loading branch information...
commit 133fab7e230d66e54cf38c687c06b7ae816757c1 1 parent 15e6497
@yob authored
View
5 data/product_identifier.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ProductIdentifier>
+ <ProductIDType>02</ProductIDType>
+ <IDValue>0858198363</IDValue>
+</ProductIdentifier>
View
4 lib/onix/product_identifier.rb
@@ -2,7 +2,9 @@ module ONIX
class ProductIdentifier
include ROXML
- xml_accessor :product_id_type, :from => "ProductIDType", :as => Fixnum # should be a 2 digit num
+ xml_name "ProductIdentifier"
+
+ xml_accessor :product_id_type, :from => "ProductIDType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
xml_accessor :id_value, :from => "IDValue"
end
end
View
40 spec/product_identifier_spec.rb
@@ -0,0 +1,40 @@
+# coding: utf-8
+
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
+
+require 'onix'
+
+context "ONIX::ProductIdentifier" do
+
+ before(:each) do
+ data_path = File.join(File.dirname(__FILE__),"..","data")
+ file1 = File.join(data_path, "product_identifier.xml")
+ @doc = LibXML::XML::Document.file(file1)
+ @root = @doc.root
+ end
+
+ specify "should correctly convert to a string" do
+ id = ONIX::ProductIdentifier.from_xml(@root.to_s)
+ id.to_xml.to_s[0,19].should eql("<ProductIdentifier>")
+ end
+
+ specify "should provide read access to first level attibutes" do
+ id = ONIX::ProductIdentifier.from_xml(@root.to_s)
+
+ id.product_id_type.should eql(2)
+ id.id_value.should eql("0858198363")
+ end
+
+ specify "should provide write access to first level attibutes" do
+ id = ONIX::ProductIdentifier.new
+
+ id.product_id_type = 2
+ id.to_xml.to_s.include?("<ProductIDType>02</ProductIDType>").should be_true
+
+ id.id_value = "James"
+ id.to_xml.to_s.include?("<IDValue>James</IDValue>").should be_true
+
+ end
+
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.