Sha256: c4c787549407a17e470edd399166a7a836cfcc97c6a2b8d20b73ad0712ab6f27

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

# coding: utf-8

require File.dirname(__FILE__) + '/spec_helper.rb'

describe ONIX::ProductIdentifier do

  before(:each) do
    data_path = File.join(File.dirname(__FILE__),"..","data")
    file1    = File.join(data_path, "product_identifier.xml")
    @doc     = Nokogiri::XML::Document.parse(File.read(file1))
    @root = @doc.root
  end

  it "should correctly convert to a string" do
    id = ONIX::ProductIdentifier.from_xml(@root.to_s)
    id.to_xml.to_s[0,19].should eql("<ProductIdentifier>")
  end

  it "should provide read access to first level attributes" do
    id = ONIX::ProductIdentifier.from_xml(@root.to_s)

    id.product_id_type.should eql(2)
    id.id_value.should eql("0858198363")
  end

  it "should provide write access to first level attributes" do
    id = ONIX::ProductIdentifier.new(:product_id_type => 1, :id_value => "TESTING")
    id.to_xml.to_s.include?("<ProductIDType>01</ProductIDType>").should be_true
    id.to_xml.to_s.include?("<IDValue>TESTING</IDValue>").should be_true

    id.product_id_type = 2
    id.to_xml.to_s.include?("<ProductIDType>02</ProductIDType>").should be_true

    id.id_value = "James"
    id.to_xml.to_s.include?("<IDValue>James</IDValue>").should be_true
  end
  
  it "should raise error when writing invalid product_id_type" do
    id = ONIX::ProductIdentifier.new
    lambda {id.product_id_type = 999}.should raise_error
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
milkfarm-onix-0.8.13 spec/product_identifier_spec.rb
milkfarm-onix-0.8.12 spec/product_identifier_spec.rb
milkfarm-onix-0.8.11 spec/product_identifier_spec.rb
milkfarm-onix-0.8.10 spec/product_identifier_spec.rb