Skip to content

Instantly share code, notes, and snippets.

@ahawkins
Created January 18, 2011 00:13
Show Gist options
  • Save ahawkins/783761 to your computer and use it in GitHub Desktop.
Save ahawkins/783761 to your computer and use it in GitHub Desktop.
require 'spec_helper'
require 'nokogiri'
xml = <<-xml
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<result type="Doc.Get" howmany="1" Documents="1" Page="1/1">
<contact row="1">
<OPCO>49 Sonera / Sonera</OPCO>
<CLAS>MP</CLAS>
<RWID>V49C0449950636</RWID>
<HILE>1</HILE>
<NALA>Ahonen Mikael</NALA>
<ADDR>Mikonaktu 15 A</ADDR>
<LOCA>44260</LOCA>
<COCO>Helsinki</COCO>
<PHNU>044 9950636</PHNU>
<HILE>2</HILE>
<NALA>AHONEN MIKAEL</NALA>
<ADDR>Soidinmentie 15</ADDR>
<EMAD>[email protected]</EMAD>
<WWWA>www.radiumcrm.com</WWWA>
</contact>
</result>
xml
TEST_DOC = Nokogiri::XML.parse(xml).remove_namespaces!.at_xpath('//contact')
describe Lookup::Gateways::Finland::NumeroNetti::Contact do
subject do
Lookup::Gateways::Finland::NumeroNetti::Contact.new TEST_DOC
end
it "should had a reader for RWID" do
subject.record_id.should eql('V49C0449950636')
end
describe "When the NALA field looks like a name" do
it "should use it to for the name" do
subject.name.should eql('Mikael Ahonen')
end
it "should say there is no company" do
subject.company.should be_nil
end
end
describe "When the NALA field looks like a company" do
subject do
xml = <<-xml
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<result type="Doc.Get" howmany="1" Documents="1" Page="1/1">
<contact row="1">
<NALA>RadiumCRM</NALA>
</contact>
</result>
xml
doc = Nokogiri::XML.parse(xml).remove_namespaces!.at_xpath('//contact')
Lookup::Gateways::Finland::NumeroNetti::Contact.new doc
end
it "should say the company" do
subject.company.should eql('RadiumCRM')
end
it "should say there is no name" do
subject.name.should be_nil
end
end
it "should have a reader for city" do
subject.city.should eql('Helsinki')
end
it "should have a reader for address" do
subject.address.should eql('Mikonaktu 15 A')
end
it "should have a reader for the zip code" do
subject.zip_code.should eql('44260')
end
it "should have a reader for the phone" do
subject.phone.should eql('044 9950636')
end
it "should have a reader for the email" do
subject.email.should eql('[email protected]')
end
it "should have a reader for the website" do
subject.website.should eql('www.radiumcrm.com')
end
it "should be able to provite a hash of its attributes" do
expected_attributes = {
:record_id => 'V49C0449950636',
:name => 'Mikael Ahonen',
:city => 'Helsinki',
:address => 'Mikonaktu 15 A',
:zip_code => '44260',
:phone => '044 9950636',
:email => '[email protected]',
:website => 'www.radiumcrm.com'
}
subject.attributes.should eql(expected_attributes)
end
it "should be equal if the record_id id is the same" do
xml = <<-xml
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<result type="Doc.Get" howmany="1" Documents="1" Page="1/1">
<contact row="1">
<RWID>V49C0449950636</RWID>
</contact>
</result>
xml
doc = Nokogiri::XML.parse(xml).remove_namespaces!.at_xpath('//contact')
other = Lookup::Gateways::Finland::NumeroNetti::Contact.new doc
subject.should eql(other)
subject.should == other
end
it "should not be equal if the record id is different" do
xml = <<-xml
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<result type="Doc.Get" howmany="1" Documents="1" Page="1/1">
<contact row="1">
<RWID>950636</RWID>
</contact>
</result>
xml
doc = Nokogiri::XML.parse(xml).remove_namespaces!.at_xpath('//contact')
other = Lookup::Gateways::Finland::NumeroNetti::Contact.new doc
subject.should_not eql(other)
subject.should_not == other
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment