Permalink
Browse files

add basic specs for OtherText class

  • Loading branch information...
1 parent b74e4d6 commit c482d66983e51b5a969fcb61d2c1981e478f4fc5 @yob committed Feb 27, 2009
Showing with 49 additions and 2 deletions.
  1. +5 −0 data/other_text.xml
  2. +4 −2 lib/onix/other_text.rb
  3. +40 −0 spec/other_text_spec.rb
View
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<OtherText>
+ <TextTypeCode>02</TextTypeCode>
+ <Text>A woman on a quest to find out the truth about her family, a mysterious Victorian authoress, a book of dark fairytales and a long-hidden secret - another addictive and compulsively readable mystery/romance from the author of the international bestseller The Shifting Fog.</Text>
+</OtherText>
View
@@ -2,10 +2,12 @@ module ONIX
class OtherText
include ROXML
- xml_accessor :text_type_code, :from => "TextTypeCode", :as => Fixnum # should be a 2 digit num
+ xml_name "OtherText"
+
+ xml_accessor :text_type_code, :from => "TextTypeCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
xml_accessor :text_format, :from => "TextFormat"
xml_accessor :text, :from => "Text"
- xml_accessor :text_link_type, :from => "TextLinkType", :as => Fixnum # should be a 2 digit num
+ xml_accessor :text_link_type, :from => "TextLinkType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
xml_accessor :text_link, :from => "TextLink"
xml_accessor :text_author, :from => "TextAuthor"
end
View
@@ -0,0 +1,40 @@
+# coding: utf-8
+
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
+
+require 'onix'
+
+context "ONIX::OtherText" do
+
+ before(:each) do
+ data_path = File.join(File.dirname(__FILE__),"..","data")
+ file1 = File.join(data_path, "other_text.xml")
+ @doc = LibXML::XML::Document.file(file1)
+ @root = @doc.root
+ end
+
+ specify "should correctly convert to a string" do
+ ot = ONIX::OtherText.from_xml(@root.to_s)
+ ot.to_xml.to_s[0,11].should eql("<OtherText>")
+ end
+
+ specify "should provide read access to first level attibutes" do
+ ot = ONIX::OtherText.from_xml(@root.to_s)
+
+ ot.text_type_code.should eql(2)
+ ot.text[0,7].should eql("A woman")
+ end
+
+ specify "should provide write access to first level attibutes" do
+ ot = ONIX::OtherText.new
+
+ ot.text_type_code = 2
+ ot.to_xml.to_s.include?("<TextTypeCode>02</TextTypeCode>").should be_true
+
+ ot.text = "James Healy"
+ ot.to_xml.to_s.include?("<Text>James Healy</Text>").should be_true
+
+ end
+
+end
+

0 comments on commit c482d66

Please sign in to comment.