Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added basic spec for Imprint class

  • Loading branch information...
commit 63552a9fc333c8d8b6c65ed583b0a7bc9de5289e 1 parent 7bd597c
@yob authored
Showing with 47 additions and 1 deletion.
  1. +5 −0 data/imprint.xml
  2. +3 −1 lib/onix/imprint.rb
  3. +39 −0 spec/imprint_spec.rb
View
5 data/imprint.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Imprint>
+ <ImprintName>Oxford University Press UK</ImprintName>
+</Imprint>
+
View
4 lib/onix/imprint.rb
@@ -2,7 +2,9 @@ module ONIX
class Imprint
include ROXML
- xml_accessor :name_code_type, :from => "NameCodeType", :as => Fixnum # should be a 2 digit num
+ xml_name "Imprint"
+
+ 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_value, :from => "NameCodeValue"
xml_accessor :imprint_name, :from => "ImprintName"
View
39 spec/imprint_spec.rb
@@ -0,0 +1,39 @@
+# coding: utf-8
+
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
+
+require 'onix'
+
+context "ONIX::Imprint" do
+
+ before(:each) do
+ data_path = File.join(File.dirname(__FILE__),"..","data")
+ file1 = File.join(data_path, "imprint.xml")
+ @doc = LibXML::XML::Document.file(file1)
+ @root = @doc.root
+ end
+
+ specify "should correctly convert to a string" do
+ imp = ONIX::Imprint.from_xml(@root.to_s)
+ imp.to_xml.to_s[0,9].should eql("<Imprint>")
+ end
+
+ specify "should provide read access to first level attibutes" do
+ imp = ONIX::Imprint.from_xml(@root.to_s)
+
+ imp.imprint_name.should eql("Oxford University Press UK")
+ end
+
+ specify "should provide write access to first level attibutes" do
+ imp = ONIX::Imprint.new
+
+ imp.imprint_name = "Paulist Press"
+ imp.to_xml.to_s.include?("<ImprintName>Paulist Press</ImprintName>").should be_true
+
+ imp.name_code_type = 1
+ imp.to_xml.to_s.include?("<NameCodeType>01</NameCodeType>").should be_true
+
+ end
+
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.