Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.gem
*.rbc
*.swp
.byebug_history
*.tmproj
*~
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--color
--format=nested
--format=documentation
5 changes: 3 additions & 2 deletions cxml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Gem::Specification.new do |s|
s.authors = ["Dan Sosedoff"]
s.email = ["[email protected]"]

s.add_development_dependency 'byebug'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '~> 2.13'
s.add_development_dependency 'simplecov', '~> 0.7'
s.add_development_dependency 'rspec', '~> 3.13'
s.add_development_dependency 'simplecov', '~> 0.22'

s.add_dependency 'nokogiri'
s.add_dependency 'xml-simple'
Expand Down
12 changes: 5 additions & 7 deletions lib/cxml/punch_out_setup_request.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
module CXML
class PunchOutSetupRequest

attr_accessor :browser_form_post_url
attr_accessor :supplier_setup_url
attr_accessor :buyer_cookie

def initialize(data={})
if data.kind_of?(Hash) && !data.empty?
@browser_form_post_url = data['BrowserFormPost']['URL']
@supplier_setup_url = data['SupplierSetup']['URL']
@buyer_cookie = data['BuyerCookie']
end
return unless data.is_a?(Hash) && data.any?

@browser_form_post_url = data['BrowserFormPost']['URL']
@supplier_setup_url = data['SupplierSetup']['URL'] if data['SupplierSetup']
@buyer_cookie = data['BuyerCookie']
end

def response_return_url
browser_form_post_url.blank? ? '' : browser_form_post_url.squish
end

end
end
3 changes: 2 additions & 1 deletion lib/cxml/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def initialize(data={})
@id = data['id']
@deployment_mode = data['deploymentMode']
@punch_out_setup_request = CXML::PunchOutSetupRequest.new(data['PunchOutSetupRequest'])
@order_request = CXML::OrderRequest.new(data['OrderRequest']) if data['OrderRequest'].present?
order_request_data = data['OrderRequest']
@order_request = CXML::OrderRequest.new(order_request_data) if order_request_data && !order_request_data.empty?
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/cxml/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CXML
VERSION = '0.2.9'
VERSION = '0.3.0'
end
27 changes: 27 additions & 0 deletions spec/fixtures/punch_out_setup_request_doc_without_supplier.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<cXML payloadID="demoSCAWIG@IESAonline" xml:lang="en-UK" timestamp="2007-04-30T15:52:54+00:00">
<Header>
<From>
<Credential domain="DUNS">
<Identity>[email protected]</Identity>
</Credential>
</From>
<To>
<Credential domain="DUNS">
<Identity>[email protected]</Identity>
</Credential>
</To>
<Sender>
<Credential domain="IESAnetworkUserID"> <Identity>88888888</Identity> <SharedSecret>{shared secret in here}</SharedSecret> </Credential> <UserAgent>IESAonlinevers1</UserAgent>
</Sender>
</Header>
<Request deploymentMode="production">
<PunchOutSetupRequest operation="create"> <BuyerCookie>demoSCAWIGP</BuyerCookie>
<BrowserFormPost>
<URL>
http://return_to_supplier_url.com
</URL>
</BrowserFormPost>
</PunchOutSetupRequest>
</Request>
</cXML>
36 changes: 24 additions & 12 deletions spec/punch_out_setup_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@

describe CXML::PunchOutSetupRequest do

it { should respond_to :browser_form_post_url }
it { should respond_to :supplier_setup_url }
it { is_expected.to respond_to(:browser_form_post_url) }
it { is_expected.to respond_to(:supplier_setup_url) }

describe '#initialize' do
context "when the request data comes with a SupplierSetup block" do
let(:parser) { CXML::Parser.new }
let(:data) { parser.parse(fixture('punch_out_setup_request_doc.xml')) }
let(:doc) { CXML::Document.new(data) }
let(:request) { doc.request }
let(:punch_out_setup_request) { request.punch_out_setup_request }

let(:parser) { CXML::Parser.new }
let(:data) { parser.parse(fixture('punch_out_setup_request_doc.xml')) }
let(:doc) { CXML::Document.new(data) }
let(:request) { doc.request }
let(:punch_out_setup_request) { request.punch_out_setup_request }
it "sets the mandatory attributes including the SupplierSetup" do
expect(punch_out_setup_request.browser_form_post_url).not_to be_nil
expect(punch_out_setup_request.supplier_setup_url).not_to be_nil
end
end

context "when the request data comes without a SupplierSetup block" do
let(:parser) { CXML::Parser.new }
let(:data) { parser.parse(fixture('punch_out_setup_request_doc_without_supplier.xml')) }
let(:doc) { CXML::Document.new(data) }
let(:request) { doc.request }
let(:punch_out_setup_request) { request.punch_out_setup_request }

describe '#initialize' do
it "sets the mandatory attributes" do
punch_out_setup_request.browser_form_post_url.should_not be_nil
punch_out_setup_request.supplier_setup_url.should_not be_nil
it "sets the mandatory attributes without the SupplierSetup" do
expect(punch_out_setup_request.browser_form_post_url).not_to be_nil
expect(punch_out_setup_request.supplier_setup_url).to be_nil
end
end
end

end
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
$:.unshift File.expand_path("../..", __FILE__)

require 'byebug'
require 'cxml'
require 'ruby-debug'
require 'simplecov'

Dir["./spec/support/**/*.rb"].sort.each { |f| require f}

Expand Down