pact_broker 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/CHANGELOG.md +16 -2
  2. data/Gemfile.lock +12 -21
  3. data/config.ru +2 -1
  4. data/db/migrations/05_add_order_column_to_version.rb +7 -0
  5. data/db/pact_broker_database.sqlite3 +0 -0
  6. data/lib/pact_broker/api.rb +23 -11
  7. data/lib/pact_broker/api/representors.rb +4 -1
  8. data/lib/pact_broker/api/representors/pact_broker_urls.rb +8 -0
  9. data/lib/pact_broker/api/representors/pact_collection_representor.rb +34 -0
  10. data/lib/pact_broker/api/representors/pact_pacticipant_representor.rb +27 -0
  11. data/lib/pact_broker/api/representors/pact_representor.rb +27 -0
  12. data/lib/pact_broker/api/representors/pacticipant_collection_representor.rb +20 -0
  13. data/lib/pact_broker/api/representors/pacticipant_empty_collection_representor.rb +33 -0
  14. data/lib/pact_broker/api/representors/representable_pact.rb +19 -0
  15. data/lib/pact_broker/api/representors/version_representor.rb +1 -0
  16. data/lib/pact_broker/models/order_versions.rb +33 -0
  17. data/lib/pact_broker/models/pact.rb +7 -2
  18. data/lib/pact_broker/models/pacticipant.rb +3 -1
  19. data/lib/pact_broker/models/version.rb +7 -1
  20. data/lib/pact_broker/repositories/pact_repository.rb +26 -5
  21. data/lib/pact_broker/resources/json_resource.rb +37 -0
  22. data/lib/pact_broker/resources/latest_pact.rb +41 -0
  23. data/lib/pact_broker/resources/latest_pacts.rb +49 -0
  24. data/lib/pact_broker/resources/pact.rb +49 -0
  25. data/lib/pact_broker/resources/pacticipant.rb +80 -0
  26. data/lib/pact_broker/resources/pacticipants.rb +41 -0
  27. data/lib/pact_broker/services/pact_service.rb +11 -9
  28. data/lib/pact_broker/version.rb +1 -1
  29. data/pact_broker.gemspec +2 -3
  30. data/spec/lib/pact_broker/api/representors/pact_collection_representor_spec.rb +23 -0
  31. data/spec/lib/pact_broker/api/representors/representable_pact_spec.rb +29 -0
  32. data/spec/lib/pact_broker/models/order_versions_spec.rb +23 -0
  33. data/spec/lib/pact_broker/repositories/pact_repository_spec.rb +39 -0
  34. data/spec/service_consumers/pact_helper.rb +2 -19
  35. data/spec/service_consumers/provider_states_for_pact_broker_client.rb +1 -48
  36. data/spec/spec_helper.rb +19 -0
  37. data/spec/support/provider_state_builder.rb +91 -0
  38. metadata +32 -29
  39. data/lib/pact_broker/api/base_api.rb +0 -40
  40. data/lib/pact_broker/api/index_api.rb +0 -23
  41. data/lib/pact_broker/api/pact_api.rb +0 -33
  42. data/lib/pact_broker/api/pacticipant_api.rb +0 -54
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'spec/support/provider_state_builder'
3
+ require 'pact_broker/api/representors/representable_pact'
4
+
5
+ module PactBroker::Api::Representors
6
+ describe RepresentablePact do
7
+ let(:pact) { ProviderStateBuilder.new.create_pact_with_hierarchy 'Consumer', '1.2.3', 'Provider' }
8
+
9
+ subject { RepresentablePact.new(pact) }
10
+
11
+ describe "initialize" do
12
+ it "creates an object with a provider with a name" do
13
+ expect(subject.provider.name).to eq 'Provider'
14
+ end
15
+
16
+ it "creates an object with a provider with a nil version" do
17
+ expect(subject.provider.version).to be_nil
18
+ end
19
+
20
+ it "creates an object with a consumer with a name" do
21
+ expect(subject.consumer.name).to eq 'Consumer'
22
+ end
23
+
24
+ it "creates an object with a consumer that has the current pact's version" do
25
+ expect(subject.consumer.version.number).to eq '1.2.3'
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'spec/support/provider_state_builder'
3
+ require 'pact_broker/models/order_versions.rb'
4
+
5
+ describe PactBroker::Models::OrderVersions do
6
+
7
+
8
+ before do
9
+ ProviderStateBuilder.new
10
+ .create_condor
11
+ .create_condor_version('1.3.0')
12
+ .create_condor_version('1.5.0')
13
+ .create_condor_version('1.4.0')
14
+ end
15
+
16
+ let(:ordered_versions) { PactBroker::Models::Version.order(:order).all.collect(&:number) }
17
+ let(:condor) { PactBroker::Models::Pacticipant.where(name: 'Condor').single_record }
18
+
19
+ it "orders the versions so they can be loaded from the database in order" do
20
+ expect(ordered_versions).to eq(['1.3.0','1.4.0', '1.5.0'])
21
+ end
22
+
23
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'spec/support/provider_state_builder'
3
+
4
+ module PactBroker
5
+ module Repositories
6
+ describe PactRepository do
7
+ describe "find_latest_pacts" do
8
+ before do
9
+ ProviderStateBuilder.new
10
+ .create_condor
11
+ .create_condor_version('1.3.0')
12
+ .create_pricing_service
13
+ .create_pact
14
+ .create_condor_version('1.4.0')
15
+ .create_pact
16
+ .create_contract_email_service
17
+ .create_contract_email_service_version('2.6.0')
18
+ .create_contract_proposal_service
19
+ .create_ces_cps_pact
20
+ .create_contract_email_service_version('2.7.0')
21
+ .create_ces_cps_pact
22
+ .create_contract_email_service_version('2.8.0') # Create a version without a pact, it shouldn't be used
23
+ end
24
+
25
+ it "finds the latest pact for each consumer/provider pair" do
26
+ pacts = PactRepository.new.find_latest_pacts
27
+
28
+ expect(pacts[0].consumer_version.pacticipant.name).to eq("Condor")
29
+ expect(pacts[0].provider.name).to eq("Pricing Service")
30
+ expect(pacts[0].consumer_version.number).to eq("1.4.0")
31
+
32
+ expect(pacts[1].consumer_version.pacticipant.name).to eq("Contract Email Service")
33
+ expect(pacts[1].provider.name).to eq("Contract Proposal Service")
34
+ expect(pacts[1].consumer_version.number).to eq("2.7.0")
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -6,31 +6,14 @@ require 'pact_broker/api'
6
6
  require 'uri'
7
7
  require_relative 'provider_states_for_pact_broker_client'
8
8
 
9
- Sequel.extension :migration
10
-
11
-
12
- RSpec.configure do | config |
13
- config.before :suite do
14
- raise "Wrong environment!!! Don't run this script!! ENV['RACK_ENV'] is #{ENV['RACK_ENV']} and RACK_ENV is #{RACK_ENV}" if ENV['RACK_ENV'] != 'test' || RACK_ENV != 'test'
15
- # puts caller.take 20
16
- end
17
-
18
- config.before :each do
19
- DB::PACT_BROKER_DB[:pacts].truncate
20
- DB::PACT_BROKER_DB[:tags].truncate
21
- DB::PACT_BROKER_DB[:versions].truncate
22
- DB::PACT_BROKER_DB[:pacticipants].truncate
23
- end
24
-
25
- end
26
-
9
+ require 'pact_broker/resources/pact'
27
10
 
28
11
  Pact.configure do | config |
29
12
  config.logger.level = Logger::DEBUG
30
13
  end
31
14
 
32
15
  Pact.service_provider "Pact Broker" do
33
- app { PactBroker::API.new }
16
+ app { PactBroker::API }
34
17
 
35
18
  # honours_pact_with "Pact Broker Client" do
36
19
  # pact_uri "../pact_broker-client/spec/pacts/pact_broker_client-pact_broker.json"
@@ -1,51 +1,4 @@
1
- require 'pact_broker/repositories'
2
-
3
- class ProviderStateBuilder
4
-
5
- include PactBroker::Repositories
6
-
7
- def create_pricing_service
8
- @pricing_service_id = pacticipant_repository.create(:name => 'Pricing Service', :repository_url => 'git@git.realestate.com.au:business-systems/pricing-service').save(raise_on_save_failure: true).id
9
- self
10
- end
11
-
12
- def create_condor
13
- @condor_id = pacticipant_repository.create(:name => 'Condor').save(raise_on_save_failure: true).id
14
- self
15
- end
16
-
17
- def create_condor_version number
18
- @condor_version_id = version_repository.create(number: number, pacticipant_id: @condor_id).id
19
- self
20
- end
21
-
22
- def create_pricing_service_version number
23
- @pricing_service_version_id = version_repository.create(number: number, pacticipant_id: @pricing_service_id).id
24
- self
25
- end
26
-
27
- def create_pact
28
- @pact_id = pact_repository.create(version_id: @condor_version_id, provider_id: @pricing_service_id, json_content: json_content).id
29
- self
30
- end
31
-
32
- private
33
-
34
- def json_content
35
- json_content = {
36
- "consumer" => {
37
- "name" => "Condor"
38
- },
39
- "provider" => {
40
- "name" => "Pricing Service"
41
- },
42
- "interactions" => []
43
- }.to_json
44
- end
45
-
46
- end
47
-
48
-
1
+ require 'spec/support/provider_state_builder'
49
2
 
50
3
  Pact.provider_states_for "Pact Broker Client" do
51
4
 
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,22 @@
1
1
  require 'simplecov' # At the top because simplecov needs to watch files being loaded
2
2
  ENV['RACK_ENV'] = 'test'
3
3
  RACK_ENV = 'test'
4
+
5
+ $: << File.expand_path("../../", __FILE__)
6
+
7
+ require 'pact_broker/db'
8
+
9
+ RSpec.configure do | config |
10
+ config.before :suite do
11
+ raise "Wrong environment!!! Don't run this script!! ENV['RACK_ENV'] is #{ENV['RACK_ENV']} and RACK_ENV is #{RACK_ENV}" if ENV['RACK_ENV'] != 'test' || RACK_ENV != 'test'
12
+ # puts caller.take 20
13
+ end
14
+
15
+ config.before :each do
16
+ DB::PACT_BROKER_DB[:pacts].truncate
17
+ DB::PACT_BROKER_DB[:tags].truncate
18
+ DB::PACT_BROKER_DB[:versions].truncate
19
+ DB::PACT_BROKER_DB[:pacticipants].truncate
20
+ end
21
+
22
+ end
@@ -0,0 +1,91 @@
1
+ require 'pact_broker/repositories'
2
+ require 'json'
3
+
4
+ class ProviderStateBuilder
5
+
6
+ include PactBroker::Repositories
7
+
8
+ def create_pricing_service
9
+ @pricing_service_id = pacticipant_repository.create(:name => 'Pricing Service', :repository_url => 'git@git.realestate.com.au:business-systems/pricing-service').save(raise_on_save_failure: true).id
10
+ self
11
+ end
12
+
13
+ def create_contract_proposal_service
14
+ @contract_proposal_service_id = pacticipant_repository.create(:name => 'Contract Proposal Service', :repository_url => 'git@git.realestate.com.au:business-systems/contract-proposal-service').save(raise_on_save_failure: true).id
15
+ self
16
+ end
17
+
18
+ def create_contract_proposal_service_version number
19
+ @contract_proposal_service_version_id = version_repository.create(number: number, pacticipant_id: @contract_proposal_service_id).id
20
+ self
21
+ end
22
+
23
+ def create_contract_email_service
24
+ @contract_email_service_id = pacticipant_repository.create(:name => 'Contract Email Service', :repository_url => 'git@git.realestate.com.au:business-systems/contract-email-service').save(raise_on_save_failure: true).id
25
+ self
26
+ end
27
+
28
+ def create_contract_email_service_version number
29
+ @contract_email_service_version_id = version_repository.create(number: number, pacticipant_id: @contract_email_service_id).id
30
+ self
31
+ end
32
+
33
+ def create_ces_cps_pact
34
+ @pact_id = pact_repository.create(version_id: @contract_email_service_version_id, provider_id: @contract_proposal_service_id, json_content: json_content).id
35
+ self
36
+ end
37
+
38
+ def create_condor
39
+ @condor_id = pacticipant_repository.create(:name => 'Condor').save(raise_on_save_failure: true).id
40
+ self
41
+ end
42
+
43
+ def create_condor_version number
44
+ @condor_version_id = version_repository.create(number: number, pacticipant_id: @condor_id).id
45
+ self
46
+ end
47
+
48
+ def create_pricing_service_version number
49
+ @pricing_service_version_id = version_repository.create(number: number, pacticipant_id: @pricing_service_id).id
50
+ self
51
+ end
52
+
53
+ def create_pact
54
+ @pact_id = pact_repository.create(version_id: @condor_version_id, provider_id: @pricing_service_id, json_content: json_content).id
55
+ self
56
+ end
57
+
58
+ def create_pact_with_hierarchy consumer_name, consumer_version, provider_name
59
+ provider = PactBroker::Models::Pacticipant.create(:name => provider_name)
60
+ consumer = PactBroker::Models::Pacticipant.create(:name => consumer_name)
61
+ version = PactBroker::Models::Version.create(:number => consumer_version, :pacticipant => consumer)
62
+ PactBroker::Models::Pact.create(:consumer_version => version, :provider => provider)
63
+ end
64
+
65
+ private
66
+
67
+ # def create_pacticipant name
68
+ # pacticipant_repository.create(:name => name)
69
+ # end
70
+
71
+ # def create_version number, pacticipant
72
+ # version_repository.create(number: number, pacticipant: pacticipant)
73
+ # end
74
+
75
+ # def create_pact version, provider
76
+ # pact_repository.create(consumer_version: version, provider: provider, json_content: json_content)
77
+ # end
78
+
79
+ def json_content
80
+ json_content = {
81
+ "consumer" => {
82
+ "name" => "Condor"
83
+ },
84
+ "provider" => {
85
+ "name" => "Pricing Service"
86
+ },
87
+ "interactions" => []
88
+ }.to_json
89
+ end
90
+
91
+ end
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: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-11-06 00:00:00.000000000 Z
14
+ date: 2013-11-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty
@@ -46,23 +46,7 @@ dependencies:
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  - !ruby/object:Gem::Dependency
49
- name: sinatra
50
- requirement: !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- type: :runtime
57
- prerelease: false
58
- version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
- requirements:
61
- - - ! '>='
62
- - !ruby/object:Gem::Version
63
- version: '0'
64
- - !ruby/object:Gem::Dependency
65
- name: sinatra-contrib
49
+ name: roar
66
50
  requirement: !ruby/object:Gem::Requirement
67
51
  none: false
68
52
  requirements:
@@ -78,7 +62,7 @@ dependencies:
78
62
  - !ruby/object:Gem::Version
79
63
  version: '0'
80
64
  - !ruby/object:Gem::Dependency
81
- name: sinatra-param
65
+ name: sequel
82
66
  requirement: !ruby/object:Gem::Requirement
83
67
  none: false
84
68
  requirements:
@@ -94,7 +78,7 @@ dependencies:
94
78
  - !ruby/object:Gem::Version
95
79
  version: '0'
96
80
  - !ruby/object:Gem::Dependency
97
- name: roar
81
+ name: sqlite3
98
82
  requirement: !ruby/object:Gem::Requirement
99
83
  none: false
100
84
  requirements:
@@ -110,7 +94,7 @@ dependencies:
110
94
  - !ruby/object:Gem::Version
111
95
  version: '0'
112
96
  - !ruby/object:Gem::Dependency
113
- name: sequel
97
+ name: webmachine
114
98
  requirement: !ruby/object:Gem::Requirement
115
99
  none: false
116
100
  requirements:
@@ -126,7 +110,7 @@ dependencies:
126
110
  - !ruby/object:Gem::Version
127
111
  version: '0'
128
112
  - !ruby/object:Gem::Dependency
129
- name: sqlite3
113
+ name: versionomy
130
114
  requirement: !ruby/object:Gem::Requirement
131
115
  none: false
132
116
  requirements:
@@ -309,21 +293,24 @@ files:
309
293
  - db/migrations/02_create_versions_table.rb
310
294
  - db/migrations/03_create_pacts_table.rb
311
295
  - db/migrations/04_create_tags_table.rb
296
+ - db/migrations/05_add_order_column_to_version.rb
312
297
  - db/pact_broker_database.sqlite3
313
298
  - lib/pact_broker.rb
314
299
  - lib/pact_broker/api.rb
315
- - lib/pact_broker/api/base_api.rb
316
- - lib/pact_broker/api/index_api.rb
317
- - lib/pact_broker/api/pact_api.rb
318
- - lib/pact_broker/api/pacticipant_api.rb
319
300
  - lib/pact_broker/api/representors.rb
320
301
  - lib/pact_broker/api/representors/pact_broker_urls.rb
302
+ - lib/pact_broker/api/representors/pact_collection_representor.rb
303
+ - lib/pact_broker/api/representors/pact_pacticipant_representor.rb
304
+ - lib/pact_broker/api/representors/pact_representor.rb
321
305
  - lib/pact_broker/api/representors/pacticipant_collection_representor.rb
306
+ - lib/pact_broker/api/representors/pacticipant_empty_collection_representor.rb
322
307
  - lib/pact_broker/api/representors/pacticipant_representor.rb
308
+ - lib/pact_broker/api/representors/representable_pact.rb
323
309
  - lib/pact_broker/api/representors/version_representor.rb
324
310
  - lib/pact_broker/db.rb
325
311
  - lib/pact_broker/logging.rb
326
312
  - lib/pact_broker/models.rb
313
+ - lib/pact_broker/models/order_versions.rb
327
314
  - lib/pact_broker/models/pact.rb
328
315
  - lib/pact_broker/models/pacticipant.rb
329
316
  - lib/pact_broker/models/tag.rb
@@ -332,6 +319,12 @@ files:
332
319
  - lib/pact_broker/repositories/pact_repository.rb
333
320
  - lib/pact_broker/repositories/pacticipant_repository.rb
334
321
  - lib/pact_broker/repositories/version_repository.rb
322
+ - lib/pact_broker/resources/json_resource.rb
323
+ - lib/pact_broker/resources/latest_pact.rb
324
+ - lib/pact_broker/resources/latest_pacts.rb
325
+ - lib/pact_broker/resources/pact.rb
326
+ - lib/pact_broker/resources/pacticipant.rb
327
+ - lib/pact_broker/resources/pacticipants.rb
335
328
  - lib/pact_broker/services.rb
336
329
  - lib/pact_broker/services/pact_service.rb
337
330
  - lib/pact_broker/services/pacticipant_service.rb
@@ -341,9 +334,14 @@ files:
341
334
  - lib/pact_broker/version.rb
342
335
  - pact_broker.gemspec
343
336
  - pact_broker_client-pact_broker.json
337
+ - spec/lib/pact_broker/api/representors/pact_collection_representor_spec.rb
338
+ - spec/lib/pact_broker/api/representors/representable_pact_spec.rb
339
+ - spec/lib/pact_broker/models/order_versions_spec.rb
340
+ - spec/lib/pact_broker/repositories/pact_repository_spec.rb
344
341
  - spec/service_consumers/pact_helper.rb
345
342
  - spec/service_consumers/provider_states_for_pact_broker_client.rb
346
343
  - spec/spec_helper.rb
344
+ - spec/support/provider_state_builder.rb
347
345
  - tasks/db.rake
348
346
  - tasks/pact.rake
349
347
  - tasks/rspec.rake
@@ -362,7 +360,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
362
360
  version: '0'
363
361
  segments:
364
362
  - 0
365
- hash: -1203595073411525094
363
+ hash: -4108477113553903119
366
364
  required_rubygems_version: !ruby/object:Gem::Requirement
367
365
  none: false
368
366
  requirements:
@@ -371,7 +369,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
371
369
  version: '0'
372
370
  segments:
373
371
  - 0
374
- hash: -1203595073411525094
372
+ hash: -4108477113553903119
375
373
  requirements: []
376
374
  rubyforge_project:
377
375
  rubygems_version: 1.8.23
@@ -379,6 +377,11 @@ signing_key:
379
377
  specification_version: 3
380
378
  summary: See description
381
379
  test_files:
380
+ - spec/lib/pact_broker/api/representors/pact_collection_representor_spec.rb
381
+ - spec/lib/pact_broker/api/representors/representable_pact_spec.rb
382
+ - spec/lib/pact_broker/models/order_versions_spec.rb
383
+ - spec/lib/pact_broker/repositories/pact_repository_spec.rb
382
384
  - spec/service_consumers/pact_helper.rb
383
385
  - spec/service_consumers/provider_states_for_pact_broker_client.rb
384
386
  - spec/spec_helper.rb
387
+ - spec/support/provider_state_builder.rb