# coding: utf-8
require File.dirname(__FILE__) + '/spec_helper.rb'
require 'date'
context "ONIX::APAProduct" do
before(:each) do
@data_path = File.join(File.dirname(__FILE__),"..","data")
file1 = File.join(@data_path, "product.xml")
@doc = Nokogiri::XML::Document.parse(File.read(file1))
@product_node = @doc.root
end
specify "should provide read access to attibutes" do
@product = ONIX::Product.from_xml(@product_node.to_s)
@apa = ONIX::APAProduct.new(@product)
@apa.record_reference.should eql("365-9780194351898")
@apa.notification_type.should eql(3)
@apa.product_form.should eql("BC")
@apa.number_of_pages.should eql(100)
@apa.bic_main_subject.should eql("EB")
@apa.publishing_status.should eql(4)
@apa.publication_date.should eql(Date.civil(1998,9,1))
@apa.pack_quantity.should eql(12)
end
specify "should provide write access to attibutes" do
apa = ONIX::APAProduct.new
apa.notification_type = 3
apa.to_xml.to_s.include?("03").should be_true
apa.record_reference = "365-9780194351898"
apa.to_xml.to_s.include?("365-9780194351898").should be_true
apa.product_form = "BC"
apa.to_xml.to_s.include?("BC").should be_true
apa.number_of_pages = 100
apa.to_xml.to_s.include?("100").should be_true
apa.bic_main_subject = "EB"
apa.to_xml.to_s.include?("EB").should be_true
apa.publishing_status = 4
apa.to_xml.to_s.include?("04").should be_true
apa.publication_date = Date.civil(1998,9,1)
apa.to_xml.to_s.include?("19980901").should be_true
apa.pack_quantity = 12
apa.to_xml.to_s.include?("12").should be_true
end
end
context ONIX::APAProduct, "price method" do
before(:each) do
@data_path = File.join(File.dirname(__FILE__),"..","data")
file1 = File.join(@data_path, "usd.xml")
@doc = Nokogiri::XML::Document.parse(File.read(file1))
@product_node = @doc.root
end
specify "should return the first price in the file, regardless of type" do
@product = ONIX::Product.from_xml(@product_node.to_s)
@apa = ONIX::APAProduct.new(@product)
@apa.price.should eql(BigDecimal.new("99.95"))
end
end
context ONIX::APAProduct, "rrp_exc_sales_tax method" do
before(:each) do
@data_path = File.join(File.dirname(__FILE__),"..","data")
file1 = File.join(@data_path, "usd.xml")
@doc = Nokogiri::XML::Document.parse(File.read(file1))
@product_node = @doc.root
end
specify "should return the first price in the file of type 1" do
@product = ONIX::Product.from_xml(@product_node.to_s)
@apa = ONIX::APAProduct.new(@product)
@apa.rrp_exc_sales_tax.should eql(BigDecimal.new("99.95"))
end
end