Permalink
Browse files

added basic specs for Publisher class

  • Loading branch information...
1 parent 133fab7 commit 8dd31afa89e79f1dbb14509ce0c559e226891ee5 @yob committed Feb 27, 2009
Showing with 47 additions and 2 deletions.
  1. +5 −0 data/publisher.xml
  2. +4 −2 lib/onix/publisher.rb
  3. +38 −0 spec/publisher_spec.rb
View
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Publisher>
+ <PublishingRole>01</PublishingRole>
+ <PublisherName>Desbooks Publishing</PublisherName>
+</Publisher>
View
@@ -2,8 +2,10 @@ module ONIX
class Publisher
include ROXML
- xml_accessor :publishing_role, :from => "PublishingRole", :as => Fixnum # should be a 2 digit num
- xml_accessor :name_code_type, :from => "NameCodeType", :as => Fixnum # should be a 2 digit num
+ xml_name "Publisher"
+
+ xml_accessor :publishing_role, :from => "PublishingRole", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
+ xml_accessor :name_code_type, :from => "NameCodeType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
xml_accessor :name_code_type_name, :from => "NameCodeTypeName"
xml_accessor :name_code_type_value, :from => "NameCodeTypeValue"
xml_accessor :publisher_name, :from => "PublisherName"
View
@@ -0,0 +1,38 @@
+# coding: utf-8
+
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
+
+require 'onix'
+
+context "ONIX::Publisher" do
+
+ before(:each) do
+ data_path = File.join(File.dirname(__FILE__),"..","data")
+ file1 = File.join(data_path, "publisher.xml")
+ @doc = LibXML::XML::Document.file(file1)
+ @root = @doc.root
+ end
+
+ specify "should correctly convert to a string" do
+ pub = ONIX::Publisher.from_xml(@root.to_s)
+ pub.to_xml.to_s[0,11].should eql("<Publisher>")
+ end
+
+ specify "should provide read access to first level attibutes" do
+ pub = ONIX::Publisher.from_xml(@root.to_s)
+ pub.publishing_role.should eql(1)
+ pub.publisher_name.should eql("Desbooks Publishing")
+ end
+
+ specify "should provide write access to first level attibutes" do
+ pub = ONIX::Publisher.new
+
+ pub.publisher_name = "Paulist Press"
+ pub.to_xml.to_s.include?("<PublisherName>Paulist Press</PublisherName>").should be_true
+
+ pub.publishing_role = 2
+ pub.to_xml.to_s.include?("<PublishingRole>02</PublishingRole>").should be_true
+ end
+
+end
+

0 comments on commit 8dd31af

Please sign in to comment.