Skip to content

Commit

Permalink
add basic spec for Website class
Browse files Browse the repository at this point in the history
  • Loading branch information
yob committed Feb 26, 2009
1 parent 63552a9 commit 9b5b84a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
6 changes: 6 additions & 0 deletions 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>

4 changes: 3 additions & 1 deletion lib/onix/website.rb
Expand Up @@ -2,7 +2,9 @@ module ONIX
class Website class Website
include ROXML 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_description, :from => "WebsiteDescription"
xml_accessor :website_link, :from => "WebsiteLink" xml_accessor :website_link, :from => "WebsiteLink"
end end
Expand Down
41 changes: 41 additions & 0 deletions 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.