diff --git a/.gitignore b/.gitignore index fc419e3..088edbf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.gem *.rbc *.swp +.byebug_history *.tmproj *~ .DS_Store diff --git a/.rspec b/.rspec index be9798c..fa2cb37 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,2 @@ --color ---format=nested \ No newline at end of file +--format=documentation \ No newline at end of file diff --git a/cxml.gemspec b/cxml.gemspec index 84dde9e..1e63296 100644 --- a/cxml.gemspec +++ b/cxml.gemspec @@ -9,9 +9,10 @@ Gem::Specification.new do |s| s.authors = ["Dan Sosedoff"] s.email = ["dan.sosedoff@gmail.com"] + 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' diff --git a/lib/cxml/punch_out_setup_request.rb b/lib/cxml/punch_out_setup_request.rb index 87e2c8e..ce7716a 100644 --- a/lib/cxml/punch_out_setup_request.rb +++ b/lib/cxml/punch_out_setup_request.rb @@ -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 diff --git a/lib/cxml/request.rb b/lib/cxml/request.rb index 2908496..df9e9e0 100644 --- a/lib/cxml/request.rb +++ b/lib/cxml/request.rb @@ -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 diff --git a/lib/cxml/version.rb b/lib/cxml/version.rb index 0f17732..e04e425 100644 --- a/lib/cxml/version.rb +++ b/lib/cxml/version.rb @@ -1,3 +1,3 @@ module CXML - VERSION = '0.2.9' + VERSION = '0.3.0' end diff --git a/spec/fixtures/punch_out_setup_request_doc_without_supplier.xml b/spec/fixtures/punch_out_setup_request_doc_without_supplier.xml new file mode 100644 index 0000000..9f89820 --- /dev/null +++ b/spec/fixtures/punch_out_setup_request_doc_without_supplier.xml @@ -0,0 +1,27 @@ + + +
+ + + punchout@test.com + + + + +punchout@test.com + + + + 88888888 {shared secret in here} IESAonlinevers1 + +
+ + demoSCAWIGP + + + http://return_to_supplier_url.com + + + + +
diff --git a/spec/punch_out_setup_request_spec.rb b/spec/punch_out_setup_request_spec.rb index 18c5ec8..e757c91 100644 --- a/spec/punch_out_setup_request_spec.rb +++ b/spec/punch_out_setup_request_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7aa2bda..00836f2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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}