pact_broker 2.7.0.beta.2 → 2.7.0.beta.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55ed087a4bac3721c9d21d00522d4aa6af0d804b
4
- data.tar.gz: 1b6058269a9c42452b3fc0ac7321f7467ee97f62
3
+ metadata.gz: '09bb5e6f6b13f93ded89b80289de3954432e5fbe'
4
+ data.tar.gz: 4091e9ee2e13413a98dd9179bd00118b92dfa85c
5
5
  SHA512:
6
- metadata.gz: 86f0f33980f4d8be7f9d19a391f6fc5329dd2c40d99a25ad08580181c30459b5dad4c80b4fd45c5e923e6edc0b54f5d507a950185a0c20c2ec7077a20eeba1b3
7
- data.tar.gz: d29c13d0da4027ee2876759e7fcd31bc46f4819a65f935da844808bc3b06315ccbbd5dcdf33ad7c43ec28c6bd2becd32ce21148aa7408258a3d10d208ef2e877
6
+ metadata.gz: 4e12f025d4183d03cad7a7d45ebfd203357ddf63779f8cc39b359e83f30adec8eb3cc018b9d024d4e79ae435b1b847847a87f13dd5c8df5d789b15dac2c08c17
7
+ data.tar.gz: 64153bb8d9aef540cabd32fb6bdaeb1270f2d24ebdfcb17e6b558bf5b0bcb30236e8655c072396d8ef0b33aedfb87bfaee26398d6ad8365d28d8ad398050fe4f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ <a name="v2.7.0.beta.3"></a>
2
+ ### v2.7.0.beta.3 (2017-11-01)
3
+
4
+ #### Features
5
+
6
+ * **matrix**
7
+ * implement querying by latest without a tag ([3d78f79](/../../commit/3d78f79))
8
+ * update query to handle tag and latest flag ([c5c800f](/../../commit/c5c800f))
9
+ * update validation of selectors to allow tag and latest flag to be specified ([0fa33f1](/../../commit/0fa33f1))
10
+ * parse latest=true and tag=TAG in matrix query ([abcab9e](/../../commit/abcab9e))
11
+ * update validation to allow latest tag to be specified ([6da6e02](/../../commit/6da6e02))
12
+ * allow version to be specified by latest_tag ([fe498a7](/../../commit/fe498a7))
13
+
14
+ * **pacticipant**
15
+ * expose repositoryUrl in resource ([8f0f16a](/../../commit/8f0f16a))
16
+
17
+ #### Bug Fixes
18
+
19
+ * correct captialization in require ([db2e676](/../../commit/db2e676))
20
+
1
21
  <a name="v2.7.0.beta.2"></a>
2
22
  ### v2.7.0.beta.2 (2017-10-31)
3
23
 
data/RELEASING.md CHANGED
@@ -1,15 +1,5 @@
1
1
  # Releasing
2
2
 
3
- 1. Increment the version in `./lib/pact_broker/version.rb`
4
- 2. Update the `CHANGELOG.md` using:
3
+ Run
5
4
 
6
- $ bundle exec rake generate_changelog
7
-
8
- 3. Add files to git
9
-
10
- $ git add CHANGELOG.md lib/pact_broker/version.rb
11
- $ git commit -m "chore(release): version $(ruby -r ./lib/pact_broker/version.rb -e "puts PactBroker::VERSION")" && git push
12
-
13
- 3. Release:
14
-
15
- $ bundle exec rake release
5
+ script/release.sh [major|minor|patch] # default is minor
@@ -32,9 +32,9 @@ module PactBroker
32
32
 
33
33
  def from_json
34
34
  if pacticipant
35
- @pacticipant = pacticipant_service.update params.merge(name: pacticipant_name)
35
+ @pacticipant = pacticipant_service.update params_with_string_keys.merge('name' => pacticipant_name)
36
36
  else
37
- @pacticipant = pacticipant_service.create params.merge(name: pacticipant_name)
37
+ @pacticipant = pacticipant_service.create params_with_string_keys.merge('name' => pacticipant_name)
38
38
  response.headers["Location"] = pacticipant_url(base_url, pacticipant)
39
39
  end
40
40
  response.body = to_json
@@ -62,9 +62,7 @@ module PactBroker
62
62
  def pacticipant_name
63
63
  identifier_from_path[:name]
64
64
  end
65
-
66
65
  end
67
66
  end
68
-
69
67
  end
70
68
  end
@@ -32,7 +32,7 @@ module PactBroker
32
32
  end
33
33
 
34
34
  def from_json
35
- created_model = pacticipant_service.create params
35
+ created_model = pacticipant_service.create params_with_string_keys
36
36
  response.body = decorator_for(created_model).to_json(user_options: decorator_context)
37
37
  end
38
38
 
@@ -55,9 +55,7 @@ module PactBroker
55
55
  def new_model
56
56
  @new_model ||= decorator_for(PactBroker::Domain::Pacticipant.new).from_json(request.body.to_s)
57
57
  end
58
-
59
58
  end
60
59
  end
61
-
62
60
  end
63
61
  end
@@ -1,10 +1,15 @@
1
1
  require 'pact_broker/db'
2
+ require 'pact_broker/repositories/helpers'
2
3
 
3
4
  module PactBroker
4
5
 
5
6
  module Domain
6
7
  class Tag < Sequel::Model
7
8
 
9
+ dataset_module do
10
+ include PactBroker::Repositories::Helpers
11
+ end
12
+
8
13
  unrestrict_primary_key
9
14
 
10
15
  associate(:many_to_one, :version, :class => "PactBroker::Domain::Version", :key => :version_id, :primary_key => :id)
@@ -5,7 +5,14 @@ module PactBroker
5
5
  class ParseQuery
6
6
  def self.call query
7
7
  params = Rack::Utils.parse_nested_query(query)
8
- selectors = (params['q'] || []).collect{ |i| { pacticipant_name: i['pacticipant'], pacticipant_version_number: i['version'] } }
8
+ selectors = (params['q'] || []).collect do |i|
9
+ p = {}
10
+ p[:pacticipant_name] = i['pacticipant'] if i['pacticipant']
11
+ p[:pacticipant_version_number] = i['version'] if i['version']
12
+ p[:latest] = true if i['latest'] == 'true'
13
+ p[:tag] = i['tag'] if i['tag']
14
+ p
15
+ end
9
16
  options = {}
10
17
  if params.key?('success') && params['success'].is_a?(Array)
11
18
  options[:success] = params['success'].collect do | value |
@@ -37,6 +37,8 @@ module PactBroker
37
37
  # If the version is nil, it means all versions for that pacticipant are to be included
38
38
  #
39
39
  def find_all selectors
40
+ selectors = look_up_versions_for_tags(selectors)
41
+
40
42
  query = PactBroker::Pacts::LatestPactPublicationsByConsumerVersion
41
43
  .select_append(:consumer_version_number, :provider_name, :consumer_name, :provider_version_id, :provider_version_number, :success)
42
44
  .select_append(Sequel[:latest_pact_publications_by_consumer_versions][:created_at].as(:pact_created_at))
@@ -55,6 +57,29 @@ module PactBroker
55
57
  .collect(&:values)
56
58
  end
57
59
 
60
+ def look_up_versions_for_tags(selectors)
61
+ selectors.collect do | selector |
62
+ # resource validation currently stops tag being specified without latest=true
63
+
64
+ if selector[:tag] && selector[:latest]
65
+ version = version_repository.find_by_pacticpant_name_and_latest_tag(selector[:pacticipant_name], selector[:tag])
66
+ # validation in resource should ensure we always have a version
67
+ {
68
+ pacticipant_name: selector[:pacticipant_name],
69
+ pacticipant_version_number: version.number
70
+ }
71
+ elsif selector[:latest]
72
+ version = version_repository.find_latest_by_pacticpant_name(selector[:pacticipant_name])
73
+ {
74
+ pacticipant_name: selector[:pacticipant_name],
75
+ pacticipant_version_number: version.number
76
+ }
77
+ else
78
+ selector
79
+ end
80
+ end
81
+ end
82
+
58
83
  def where_consumer_and_provider_within selectors, query
59
84
  query.where{
60
85
  Sequel.&(
@@ -23,25 +23,36 @@ module PactBroker
23
23
  def validate_selectors selectors
24
24
  error_messages = []
25
25
 
26
- selectors.each do | selector |
27
- if selector[:pacticipant_name].nil? && selector[:pacticipant_version_number].nil?
26
+ selectors.each do | s |
27
+ if s[:pacticipant_name].nil? && s[:pacticipant_version_number].nil?
28
28
  error_messages << "Please specify the pacticipant name and version"
29
- elsif selector[:pacticipant_name].nil?
29
+ elsif s[:pacticipant_name].nil?
30
30
  error_messages << "Please specify the pacticipant name"
31
+ else
32
+ if s.key?(:pacticipant_version_number) && s.key?(:latest)
33
+ error_messages << "A version and latest flag cannot both be specified for #{s[:pacticipant_name]}"
34
+ end
35
+
36
+ if s.key?(:tag) && !s.key?(:latest)
37
+ error_messages << "Querying for all versions with a tag is not currently supported. The latest=true flag must be specified when a tag is given."
38
+ end
31
39
  end
32
40
  end
33
41
 
34
42
  selectors.collect{ |selector| selector[:pacticipant_name] }.compact.each do | pacticipant_name |
35
43
  unless pacticipant_service.find_pacticipant_by_name(pacticipant_name)
36
- error_messages << "Pacticipant '#{pacticipant_name}' not found"
44
+ error_messages << "Pacticipant #{pacticipant_name} not found"
37
45
  end
38
46
  end
39
47
 
40
48
  if error_messages.empty?
41
- selectors.each do | selector |
42
- if selector[:pacticipant_version_number]
43
- version = version_service.find_by_pacticipant_name_and_number(pacticipant_name: selector[:pacticipant_name], pacticipant_version_number: selector[:pacticipant_version_number])
44
- error_messages << "No pact or verification found for #{selector[:pacticipant_name]} version #{selector[:pacticipant_version_number]}" if version.nil?
49
+ selectors.each do | s |
50
+ if s[:pacticipant_version_number]
51
+ version = version_service.find_by_pacticipant_name_and_number(pacticipant_name: s[:pacticipant_name], pacticipant_version_number: s[:pacticipant_version_number])
52
+ error_messages << "No pact or verification found for #{s[:pacticipant_name]} version #{s[:pacticipant_version_number]}" if version.nil?
53
+ elsif s[:tag]
54
+ version = version_service.find_by_pacticpant_name_and_latest_tag(s[:pacticipant_name], s[:tag])
55
+ error_messages << "No version of #{s[:pacticipant_name]} found with tag #{s[:tag]}" if version.nil?
45
56
  end
46
57
  end
47
58
  end
@@ -70,13 +70,17 @@ module PactBroker
70
70
  end
71
71
 
72
72
  def self.update params
73
- pacticipant = pacticipant_repository.find_by_name(params.fetch(:name))
74
- pacticipant.update(params)
75
- pacticipant_repository.find_by_name(params.fetch(:name))
73
+ pacticipant = pacticipant_repository.find_by_name(params.fetch('name'))
74
+ PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).from_hash(params)
75
+ pacticipant.save
76
+ pacticipant_repository.find_by_name(params.fetch('name'))
76
77
  end
77
78
 
78
79
  def self.create params
79
- pacticipant_repository.create(params)
80
+ pacticipant = PactBroker::Domain::Pacticipant.new
81
+ PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).from_hash(params)
82
+ pacticipant.save
83
+ pacticipant
80
84
  end
81
85
 
82
86
  def self.delete name
@@ -14,7 +14,7 @@ module PactBroker
14
14
 
15
15
  def find args
16
16
  PactBroker::Domain::Tag
17
- .select(Sequel.qualify("tags", "name"), Sequel.qualify("tags", "version_id"), Sequel.qualify("tags", "created_at"), Sequel.qualify("tags", "updated_at"))
17
+ .select_all_qualified
18
18
  .join(:versions, {id: :version_id})
19
19
  .join(:pacticipants, {Sequel.qualify("pacticipants", "id") => Sequel.qualify("versions", "pacticipant_id")})
20
20
  .where(name_like(Sequel.qualify("tags", "name"), args.fetch(:tag_name)))
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = '2.7.0.beta.2'
2
+ VERSION = '2.7.0.beta.3'
3
3
  end
@@ -12,6 +12,26 @@ module PactBroker
12
12
  PactBroker::Domain::Version.where(number: number, pacticipant_id: pacticipant_id).single_record
13
13
  end
14
14
 
15
+ def find_by_pacticpant_name_and_latest_tag pacticipant_name, tag
16
+ PactBroker::Domain::Version
17
+ .select_all_qualified
18
+ .join(:pacticipants, {id: :pacticipant_id}, {implicit_qualifier: :versions})
19
+ .join(:tags, {version_id: :id}, {implicit_qualifier: :versions})
20
+ .where(name_like(Sequel[:tags][:name], tag))
21
+ .where(name_like(Sequel[:pacticipants][:name], pacticipant_name))
22
+ .reverse_order(:order)
23
+ .first
24
+ end
25
+
26
+ def find_latest_by_pacticpant_name pacticipant_name
27
+ PactBroker::Domain::Version
28
+ .select_all_qualified
29
+ .join(:pacticipants, {id: :pacticipant_id}, {implicit_qualifier: :versions})
30
+ .where(name_like(Sequel[:pacticipants][:name], pacticipant_name))
31
+ .reverse_order(:order)
32
+ .first
33
+ end
34
+
15
35
  def find_by_pacticipant_name_and_number pacticipant_name, number
16
36
  PactBroker::Domain::Version
17
37
  .select(Sequel[:versions][:id], Sequel[:versions][:number], Sequel[:versions][:pacticipant_id], Sequel[:versions][:order], Sequel[:versions][:created_at], Sequel[:versions][:updated_at])
@@ -11,18 +11,15 @@ module PactBroker
11
11
  version_repository.find_by_pacticipant_name_and_number params.fetch(:pacticipant_name), params.fetch(:pacticipant_version_number)
12
12
  end
13
13
 
14
+ def self.find_by_pacticpant_name_and_latest_tag(pacticipant_name, tag)
15
+ version_repository.find_by_pacticpant_name_and_latest_tag(pacticipant_name, tag)
16
+ end
17
+
14
18
  def self.delete version
15
19
  tag_repository.delete_by_version_id version.id
16
20
  pact_repository.delete_by_version_id version.id
17
21
  version_repository.delete_by_id version.id
18
22
  end
19
-
20
- def self.find_versions_by_selector selectors
21
- selectors.collect do | selector |
22
- pacticipant_name, type, number = selector.split("/")
23
- version_repository.find_by_pacticipant_name_and_number pacticipant_name, number
24
- end
25
- end
26
23
  end
27
24
  end
28
25
  end
data/pact_broker.gemspec CHANGED
@@ -51,5 +51,5 @@ Gem::Specification.new do |gem|
51
51
  gem.add_development_dependency 'database_cleaner', '~>1.6'
52
52
  gem.add_development_dependency 'pg', '~>0.21'
53
53
  gem.add_development_dependency 'conventional-changelog', '~>1.3'
54
-
54
+ gem.add_development_dependency 'bump', '~> 0.5'
55
55
  end
data/script/release.sh ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ set -e
3
+ bundle exec bump ${1:-minor} --no-commit
4
+ bundle exec rake generate_changelog
5
+ git add CHANGELOG.md lib/pact_broker/version.rb
6
+ git commit -m "chore(release): version $(ruby -r ./lib/pact_broker/version.rb -e "puts PactBroker::VERSION")" && git push
7
+ bundle exec rake release
@@ -4,7 +4,7 @@ describe "Creating a pacticipant" do
4
4
  let(:path) { "/pacticipants" }
5
5
  let(:headers) { {'CONTENT_TYPE' => 'application/json'} }
6
6
  let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
7
- let(:pacticipant_hash) { {name: 'Foo Thing'}}
7
+ let(:pacticipant_hash) { { name: 'Foo Thing' } }
8
8
 
9
9
  subject { post path, pacticipant_hash.to_json, headers; last_response }
10
10
 
@@ -1,25 +1,23 @@
1
- xdescribe "Publishing a pact" do
1
+ describe "Publishing a pact" do
2
2
 
3
- let(:request_body) { load_fixture('update_pacticipant.json') }
3
+ let(:request_body) { {'repositoryUrl' => 'http://foo'} }
4
4
  let(:path) { "/pacticipants/Some%20Consumer" }
5
5
  let(:response_body_json) { JSON.parse(subject.body) }
6
6
 
7
- subject { patch path, request_body, {'CONTENT_TYPE' => 'application/json-patch+json' }; last_response }
7
+ subject { patch path, request_body.to_json, {'CONTENT_TYPE' => 'application/json' }; last_response }
8
8
 
9
9
  context "when the pacticipant exists" do
10
+
11
+ before do
12
+ TestDataBuilder.new.create_pacticipant("Some Consumer")
13
+ end
10
14
  it "returns a 200 OK" do
11
- expect(subject.status).to be 201
15
+ puts subject.body unless subject.status == 200
16
+ expect(subject.status).to be 200
12
17
  end
13
18
 
14
19
  it "returns a json body with the updated pacticipant" do
15
- expect(subject.headers['Content-Type']).to eq "application/json"
16
- end
17
-
18
- end
19
-
20
- context "when the pacticipant does not exist" do
21
- it "returns a 404" do
22
- expect(subject.status).to be 404
20
+ expect(subject.headers['Content-Type']).to eq "application/hal+json;charset=utf-8"
23
21
  end
24
22
  end
25
23
  end
@@ -64,8 +64,6 @@ module PactBroker::Api
64
64
  end
65
65
  end
66
66
  end
67
-
68
67
  end
69
68
  end
70
-
71
69
  end
@@ -47,7 +47,7 @@ module PactBroker
47
47
 
48
48
  context "with valid JSON" do
49
49
  it "creates the pacticipant" do
50
- expect(PactBroker::Pacticipants::Service).to receive(:create).with(params)
50
+ expect(PactBroker::Pacticipants::Service).to receive(:create).with('name' => 'New Consumer')
51
51
  subject
52
52
  end
53
53
 
@@ -32,7 +32,7 @@ module PactBroker
32
32
  let(:query) { "q[][wrong]=Foo&q[][blah]=1.2.3" }
33
33
 
34
34
  it "returns nil keys or values" do
35
- expect(subject.first).to eq [{ pacticipant_name: nil, pacticipant_version_number: nil }]
35
+ expect(subject.first).to eq [{}]
36
36
  end
37
37
  end
38
38
 
@@ -73,6 +73,30 @@ module PactBroker
73
73
  expect(subject.last).to eq(success: [nil])
74
74
  end
75
75
  end
76
+
77
+ context "when latest is true" do
78
+ let(:query) { "q[][pacticipant]=Foo&q[][latest]=true" }
79
+
80
+ it "returns a selector with latest true" do
81
+ expect(subject.first).to eq [{ pacticipant_name: 'Foo', latest: true }]
82
+ end
83
+ end
84
+
85
+ context "when latest is not true" do
86
+ let(:query) { "q[][pacticipant]=Foo&q[][latest]=false" }
87
+
88
+ it "returns a selector with no latest key" do
89
+ expect(subject.first).to eq [{ pacticipant_name: 'Foo' }]
90
+ end
91
+ end
92
+
93
+ context "when there is a tag" do
94
+ let(:query) { "q[][pacticipant]=Foo&q[][tag]=prod" }
95
+
96
+ it "returns a selector with a tag" do
97
+ expect(subject.first).to eq [{ pacticipant_name: 'Foo', tag: 'prod' }]
98
+ end
99
+ end
76
100
  end
77
101
  end
78
102
  end
@@ -32,15 +32,15 @@ module PactBroker
32
32
  end
33
33
 
34
34
  it "returns an row with a blank provider_version_number" do
35
- expect(subject.first).to include consumer_name: "A",
35
+ expect(subject).to include_hash_matching consumer_name: "A",
36
36
  provider_name: "B",
37
37
  consumer_version_number: "1.2.3",
38
38
  provider_version_number: nil
39
39
 
40
- expect(subject.last).to include consumer_name: "A",
40
+ expect(subject).to include_hash_matching({consumer_name: "A",
41
41
  provider_name: "C",
42
42
  consumer_version_number: "1.2.3",
43
- provider_version_number: nil
43
+ provider_version_number: nil})
44
44
  end
45
45
 
46
46
  context "when only 2 version selectors are specified" do
@@ -219,6 +219,79 @@ module PactBroker
219
219
  end
220
220
  end
221
221
  end
222
+
223
+ context "when the latest tag is specified for a provider instead of a version" do
224
+ before do
225
+ td.create_pact_with_hierarchy("A", "1.2.3", "B")
226
+ .create_verification(provider_version: "1.0.0")
227
+ .use_provider_version("1.0.0")
228
+ .create_provider_version_tag("prod")
229
+ .create_verification(provider_version: "2.0.0", number: 2)
230
+ .use_provider_version("2.0.0")
231
+ .create_provider_version_tag("prod")
232
+ .create_verification(provider_version: "3.0.0", number: 3)
233
+ end
234
+
235
+ let(:selectors) do
236
+ [
237
+ { pacticipant_name: "A", pacticipant_version_number: "1.2.3" },
238
+ { pacticipant_name: "B", latest: true, tag: "prod" }
239
+ ]
240
+ end
241
+
242
+ subject { Repository.new.find(selectors) }
243
+
244
+ it "returns the row for the version " do
245
+ expect(subject.first).to include provider_version_number: "2.0.0"
246
+ expect(subject.size).to eq 1
247
+ end
248
+ end
249
+
250
+ context "when the latest version is specified for a provider without a tag" do
251
+ before do
252
+ td.create_pact_with_hierarchy("A", "1.2.3", "B")
253
+ .create_verification(provider_version: "1.0.0")
254
+ .use_provider_version("1.0.0")
255
+ .create_verification(provider_version: "2.0.0", number: 2)
256
+ .use_provider_version("2.0.0")
257
+ .create_verification(provider_version: "3.0.0", number: 3)
258
+ end
259
+
260
+ let(:selectors) do
261
+ [
262
+ { pacticipant_name: "A", pacticipant_version_number: "1.2.3" },
263
+ { pacticipant_name: "B", latest: true }
264
+ ]
265
+ end
266
+
267
+ subject { Repository.new.find(selectors) }
268
+
269
+ it "returns the row for the version " do
270
+ expect(subject.first).to include provider_version_number: "3.0.0"
271
+ expect(subject.size).to eq 1
272
+ end
273
+ end
274
+
275
+ context "when the latest version is specified for a provider without a tag but the latest known version for a provider does not have a verification" do
276
+ before do
277
+ td.create_pact_with_hierarchy("A", "1.2.3", "B")
278
+ .create_verification(provider_version: "1.0.0")
279
+ .create_provider_version("5.0.0")
280
+ end
281
+
282
+ let(:selectors) do
283
+ [
284
+ { pacticipant_name: "A", pacticipant_version_number: "1.2.3" },
285
+ { pacticipant_name: "B", latest: true }
286
+ ]
287
+ end
288
+
289
+ subject { Repository.new.find(selectors) }
290
+
291
+ it "returns no data - this may be confusing. Might need to re-think this logic." do
292
+ expect(subject.size).to eq 0
293
+ end
294
+ end
222
295
  end
223
296
 
224
297
  describe "#find_for_consumer_and_provider" do
@@ -36,7 +36,7 @@ module PactBroker
36
36
  let(:selectors) { [{ pacticipant_name: "Foo", pacticipant_version_number: "1" }] }
37
37
 
38
38
  it "returns error messages" do
39
- expect(subject.first).to eq "Pacticipant 'Foo' not found"
39
+ expect(subject.first).to eq "Pacticipant Foo not found"
40
40
  end
41
41
  end
42
42
 
@@ -70,6 +70,65 @@ module PactBroker
70
70
  expect(subject.first).to eq "Please specify the pacticipant name and version"
71
71
  end
72
72
  end
73
+
74
+ context "when the latest_tag is used instead of a version" do
75
+ before do
76
+ td.create_pacticipant("Foo")
77
+ .create_version("1")
78
+ .create_tag("prod")
79
+ .create_pacticipant("Bar")
80
+ .create_version("2")
81
+ end
82
+
83
+ let(:selectors) { [{ pacticipant_name: "Foo", latest_tag: "prod" }, { pacticipant_name: "Bar", pacticipant_version_number: "2" }] }
84
+
85
+ context "when there is a version for the tag" do
86
+ it "returns no error messages" do
87
+ expect(subject).to eq []
88
+ end
89
+ end
90
+
91
+ context "when there is not a version for the tag" do
92
+
93
+ let(:selectors) { [{ pacticipant_name: "Foo", latest: true, tag: "wiffle" }, { pacticipant_name: "Bar", pacticipant_version_number: "2" }] }
94
+
95
+ it "returns an error message" do
96
+ expect(subject).to eq ["No version of Foo found with tag wiffle"]
97
+ end
98
+ end
99
+ end
100
+
101
+ context "when the latest is used as well as a version" do
102
+ before do
103
+ td.create_pacticipant("Foo")
104
+ .create_version("1")
105
+ .create_tag("prod")
106
+ .create_pacticipant("Bar")
107
+ .create_version("2")
108
+ end
109
+
110
+ let(:selectors) { [{ pacticipant_name: "Foo", pacticipant_version_number: "1", latest: true }, { pacticipant_name: "Bar", pacticipant_version_number: "2" }] }
111
+
112
+ it "returns an error message" do
113
+ expect(subject).to eq ["A version and latest flag cannot both be specified for Foo"]
114
+ end
115
+ end
116
+
117
+ context "when a tag is specified without latest=true" do
118
+ before do
119
+ td.create_pacticipant("Foo")
120
+ .create_version("1")
121
+ .create_tag("prod")
122
+ .create_pacticipant("Bar")
123
+ .create_version("2")
124
+ end
125
+
126
+ let(:selectors) { [{ pacticipant_name: "Foo", tag: "1"}] }
127
+
128
+ it "returns an error message" do
129
+ expect(subject).to eq ["Querying for all versions with a tag is not currently supported. The latest=true flag must be specified when a tag is given."]
130
+ end
131
+ end
73
132
  end
74
133
  end
75
134
  end
@@ -10,6 +10,22 @@ module PactBroker
10
10
 
11
11
  subject{ Service }
12
12
 
13
+ let(:td) { TestDataBuilder.new }
14
+
15
+ describe ".update" do
16
+ before do
17
+ td.create_pacticipant("Foo")
18
+ end
19
+
20
+ let(:params) { { 'name' => 'Foo', 'repositoryUrl' => 'http://foo' } }
21
+
22
+ subject { Service.update(params) }
23
+
24
+ it "updates the repositoryUrl" do
25
+ expect(subject.repository_url).to eq 'http://foo'
26
+ end
27
+ end
28
+
13
29
  describe ".messages_for_potential_duplicate_pacticipants" do
14
30
 
15
31
  let(:base_url) { 'http://example.org' }
@@ -126,7 +142,6 @@ module PactBroker
126
142
  it "returns a list of relationships" do
127
143
  expect(subject.find_relationships).to eq([PactBroker::Domain::Relationship.create(consumer, provider, pact, verification, webhooks)])
128
144
  end
129
-
130
145
  end
131
146
 
132
147
  describe "delete" do
@@ -5,9 +5,33 @@ module PactBroker
5
5
  module Versions
6
6
  describe Repository do
7
7
 
8
+ let(:td) { TestDataBuilder.new }
8
9
  let(:pacticipant_name) { "test_pacticipant" }
9
10
  let(:version_number) { "1.2.3" }
10
11
 
12
+
13
+ describe "#find_by_pacticpant_name_and_latest_tag" do
14
+ before do
15
+ td.create_consumer("Bar")
16
+ .create_consumer_version("2.3.4")
17
+ .create_consumer_version_tag("prod")
18
+ .create_consumer("Foo")
19
+ .create_consumer_version("1.2.3")
20
+ .create_consumer_version_tag("prod")
21
+ .create_consumer_version("2.3.4")
22
+ .create_consumer_version_tag("prod")
23
+ .create_consumer_version("5.6.7")
24
+ end
25
+
26
+ subject { Repository.new.find_by_pacticpant_name_and_latest_tag("Foo", "prod") }
27
+
28
+ it "returns the most recent version that has the specified tag" do
29
+
30
+ expect(subject.number).to eq "2.3.4"
31
+ expect(subject.pacticipant.name).to eq "Foo"
32
+ end
33
+ end
34
+
11
35
  describe "#create" do
12
36
  context "when a previous version exists" do
13
37
 
@@ -4,44 +4,6 @@ module PactBroker
4
4
 
5
5
  module Versions
6
6
  describe Service do
7
-
8
- describe ".find_versions_by_selector" do
9
-
10
- context "without a version selector" do
11
- let(:selector) { "Foo" }
12
- end
13
-
14
- context "with a version selector" do
15
- before do
16
- TestDataBuilder.new
17
- .create_pacticipant("Foo")
18
- .create_version("1.2.3")
19
- .create_version("4.5.6")
20
- .create_pacticipant("Bar")
21
- .create_version("1.2.3")
22
- end
23
-
24
- let(:selector) { "Foo/version/1.2.3" }
25
-
26
- subject { Service.find_versions_by_selector [selector] }
27
-
28
- context "when the version exists" do
29
- it "returns the specfied version" do
30
- expect(subject.first.number).to eq "1.2.3"
31
- expect(subject.first.pacticipant.name).to eq "Foo"
32
- end
33
- end
34
-
35
- context "when the version does not exist" do
36
- let(:selector) { "Wiffle/version/0.0.0" }
37
-
38
- it "returns nil" do
39
- expect(subject.first).to eq nil
40
- end
41
- end
42
- end
43
- end
44
-
45
7
  describe ".delete" do
46
8
  let!(:version) do
47
9
  TestDataBuilder.new
@@ -48,6 +48,20 @@ Pact.provider_states_for "Pact Broker Client" do
48
48
  end
49
49
  end
50
50
 
51
+ provider_state "the pact for Foo version 1.2.3 has been successfully verified by Bar version 4.5.6 with tag prod, and 1.2.4 unsuccessfully by 9.9.9" do
52
+ set_up do
53
+ TestDataBuilder.new
54
+ .create_pact_with_hierarchy("Foo", "1.2.3", "Bar")
55
+ .create_verification(provider_version: "4.5.6")
56
+ .use_provider("Bar")
57
+ .use_provider_version("4.5.6")
58
+ .create_provider_version_tag("prod")
59
+ .create_consumer_version("1.2.4")
60
+ .create_pact
61
+ .create_verification(provider_version: "9.9.9", success: false)
62
+ end
63
+ end
64
+
51
65
  provider_state "the 'Pricing Service' does not exist in the pact-broker" do
52
66
  no_op
53
67
  end
@@ -41,3 +41,13 @@ RSpec::Matchers.define :be_a_404_response do
41
41
  expect(actual.status).to be 404
42
42
  end
43
43
  end
44
+
45
+ RSpec::Matchers.define :include_hash_matching do |expected|
46
+ match do |array_of_hashes|
47
+ array_of_hashes.any? { |actual| slice(actual, expected.keys) == expected }
48
+ end
49
+
50
+ def slice actual, keys
51
+ keys.each_with_object({}) { |k, hash| hash[k] = actual[k] if actual.has_key?(k) }
52
+ end
53
+ end
@@ -154,6 +154,11 @@ class TestDataBuilder
154
154
  self
155
155
  end
156
156
 
157
+ def use_provider_version version_number
158
+ @provider_version = PactBroker::Domain::Version.where(pacticipant_id: @provider.id, number: version_number).single_record
159
+ self
160
+ end
161
+
157
162
  def create_tag tag_name
158
163
  @tag = PactBroker::Domain::Tag.create(name: tag_name, version: @version)
159
164
  self
@@ -164,6 +169,11 @@ class TestDataBuilder
164
169
  self
165
170
  end
166
171
 
172
+ def create_provider_version_tag tag_name
173
+ @tag = PactBroker::Domain::Tag.create(name: tag_name, version: @provider_version)
174
+ self
175
+ end
176
+
167
177
  def create_label label_name
168
178
  @label = PactBroker::Domain::Label.create(name: label_name, pacticipant: @pacticipant)
169
179
  self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0.beta.2
4
+ version: 2.7.0.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bethany Skurrie
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-10-30 00:00:00.000000000 Z
13
+ date: 2017-11-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -430,6 +430,20 @@ dependencies:
430
430
  - - "~>"
431
431
  - !ruby/object:Gem::Version
432
432
  version: '1.3'
433
+ - !ruby/object:Gem::Dependency
434
+ name: bump
435
+ requirement: !ruby/object:Gem::Requirement
436
+ requirements:
437
+ - - "~>"
438
+ - !ruby/object:Gem::Version
439
+ version: '0.5'
440
+ type: :development
441
+ prerelease: false
442
+ version_requirements: !ruby/object:Gem::Requirement
443
+ requirements:
444
+ - - "~>"
445
+ - !ruby/object:Gem::Version
446
+ version: '0.5'
433
447
  description: A server that stores and returns pact files generated by the pact gem.
434
448
  It enables head/prod cross testing of the consumer and provider projects.
435
449
  email:
@@ -796,6 +810,7 @@ files:
796
810
  - script/publish-not-a-pact.sh
797
811
  - script/publish.sh
798
812
  - script/recreate-pg-db.sh
813
+ - script/release.sh
799
814
  - script/seed-matrix.rb
800
815
  - script/seed.rb
801
816
  - script/update-hal-browser