Skip to content
Browse files

add basic spec for Website class

  • Loading branch information...
1 parent 63552a9 commit 9b5b84acf6b2e30006e625dcfac1a582dd5965e3 @yob committed
Showing with 50 additions and 1 deletion.
  1. +6 −0 data/website.xml
  2. +3 −1 lib/onix/website.rb
  3. +41 −0 spec/website_spec.rb
View
6 data/website.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Website>
+ <WebsiteRole>01</WebsiteRole>
+ <WebsiteLink>http://www.rainbowbooks.com.au</WebsiteLink>
+</Website>
+
View
4 lib/onix/website.rb
@@ -2,7 +2,9 @@ module ONIX
class Website
include ROXML
- xml_accessor :website_role, :from => "WebsiteRole", :as => Fixnum # should be a 2 digit num
+ xml_name "Website"
+
+ xml_accessor :website_role, :from => "WebsiteRole", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
xml_accessor :website_description, :from => "WebsiteDescription"
xml_accessor :website_link, :from => "WebsiteLink"
end
View
41 spec/website_spec.rb
@@ -0,0 +1,41 @@
+# coding: utf-8
+
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
+
+require 'onix'
+
+context "ONIX::Website" do
+
+ before(:each) do
+ data_path = File.join(File.dirname(__FILE__),"..","data")
+ file1 = File.join(data_path, "website.xml")
+ @doc = LibXML::XML::Document.file(file1)
+ @root = @doc.root
+ end
+
+ specify "should correctly convert to a string" do
+ web = ONIX::Website.from_xml(@root.to_s)
+ web.to_xml.to_s[0,9].should eql("<Website>")
+ end
+
+ specify "should provide read access to first level attibutes" do
+ web = ONIX::Website.from_xml(@root.to_s)
+
+ web.website_role.should eql(1)
+ web.website_link.should eql("http://www.rainbowbooks.com.au")
+ end
+
+ specify "should provide write access to first level attibutes" do
+ web = ONIX::Website.new
+
+ web.website_role = 2
+ web.to_xml.to_s.include?("<WebsiteRole>02</WebsiteRole>").should be_true
+
+ web.website_link = "http://www.yob.id.au"
+ web.to_xml.to_s.include?("<WebsiteLink>http://www.yob.id.au</WebsiteLink>").should be_true
+
+ end
+
+end
+
+

0 comments on commit 9b5b84a

Please sign in to comment.
Something went wrong with that request. Please try again.