Skip to content

Commit

Permalink
fix: do not parse the provider version as a semantic version when ord…
Browse files Browse the repository at this point in the history
…er_versions_by_date is true

fixes: #329
  • Loading branch information
bethesque committed Jun 17, 2020
1 parent e2c424c commit bf30024
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/pact_broker/api/contracts/verification_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions spec/lib/pact_broker/api/contracts/verification_contract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bf30024

Please sign in to comment.