Skip to content

Commit

Permalink
basic specs for ProductIdentifier class
Browse files Browse the repository at this point in the history
  • Loading branch information
yob committed Feb 27, 2009
1 parent 15e6497 commit 133fab7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions data/product_identifier.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ProductIdentifier>
<ProductIDType>02</ProductIDType>
<IDValue>0858198363</IDValue>
</ProductIdentifier>
4 changes: 3 additions & 1 deletion lib/onix/product_identifier.rb
Expand Up @@ -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
40 changes: 40 additions & 0 deletions 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

0 comments on commit 133fab7

Please sign in to comment.