diff --git a/lib/pact_broker/api/contracts/verification_contract.rb b/lib/pact_broker/api/contracts/verification_contract.rb index 4813b6d8c..5311c463e 100644 --- a/lib/pact_broker/api/contracts/verification_contract.rb +++ b/lib/pact_broker/api/contracts/verification_contract.rb @@ -25,6 +25,8 @@ def valid_url? url end def valid_version_number?(value) + return true if PactBroker.configuration.order_versions_by_date + parsed_version_number = PactBroker.configuration.version_parser.call(value) !!parsed_version_number end diff --git a/spec/lib/pact_broker/api/contracts/verification_contract_spec.rb b/spec/lib/pact_broker/api/contracts/verification_contract_spec.rb index 741aa9f9d..c107a80ef 100644 --- a/spec/lib/pact_broker/api/contracts/verification_contract_spec.rb +++ b/spec/lib/pact_broker/api/contracts/verification_contract_spec.rb @@ -15,6 +15,7 @@ module Contracts let(:success) { true } let(:provider_version) { "4.5.6" } let(:build_url) { 'http://foo' } + let(:order_versions_by_date) { false } def modify hash, options hash.delete(options.fetch(:without)) @@ -24,6 +25,7 @@ def modify hash, options describe "errors" do before do + allow(PactBroker.configuration).to receive(:order_versions_by_date).and_return(order_versions_by_date) subject.validate(params) end @@ -85,10 +87,22 @@ def modify hash, options end end - context "when the providerApplicationVersion is not a semantic version" do - let(:provider_version) { "#" } - it "has an error" do - expect(subject.errors[:provider_version]).to include(match("#.*cannot be parsed")) + context "when order_versions_by_date is true" do + let(:order_versions_by_date) { true } + + context "when the providerApplicationVersion is not a semantic version" do + let(:provider_version) { "#" } + its(:errors) { is_expected.to be_empty } + end + end + + context "when order_versions_by_date is false" do + context "when the providerApplicationVersion is not a semantic version" do + let(:provider_version) { "#" } + + it "has an error" do + expect(subject.errors[:provider_version]).to include(match("#.*cannot be parsed")) + end end end end