pact_broker 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/lib/db.rb +1 -1
  4. data/lib/pact_broker/api/decorators/basic_pacticipant_decorator.rb +1 -1
  5. data/lib/pact_broker/api/decorators/pact_details_decorator.rb +2 -2
  6. data/lib/pact_broker/api/decorators/pact_pacticipant_decorator.rb +1 -1
  7. data/lib/pact_broker/api/decorators/pacticipant_collection_decorator.rb +2 -2
  8. data/lib/pact_broker/api/decorators/pacticipant_decorator.rb +1 -1
  9. data/lib/pact_broker/api/decorators/webhook_decorator.rb +2 -2
  10. data/lib/pact_broker/api/resources/pacticipant.rb +1 -1
  11. data/lib/pact_broker/api/resources/pacticipants.rb +2 -2
  12. data/lib/pact_broker/api.rb +1 -1
  13. data/lib/pact_broker/app.rb +10 -1
  14. data/lib/pact_broker/configuration.rb +3 -0
  15. data/lib/pact_broker/db.rb +6 -1
  16. data/lib/pact_broker/diagnostic/app.rb +37 -0
  17. data/lib/pact_broker/diagnostic/resources/dependencies.rb +65 -0
  18. data/lib/pact_broker/diagnostic/resources/heartbeat.rb +30 -0
  19. data/lib/pact_broker/{functions → pacticipants}/find_potential_duplicate_pacticipant_names.rb +1 -5
  20. data/lib/pact_broker/{services/pact_service.rb → pacts/service.rb} +5 -5
  21. data/lib/pact_broker/{functions → relationships}/groupify.rb +2 -2
  22. data/lib/pact_broker/services/group_service.rb +2 -2
  23. data/lib/pact_broker/services/pacticipant_service.rb +2 -2
  24. data/lib/pact_broker/services.rb +4 -2
  25. data/lib/pact_broker/version.rb +1 -1
  26. data/pact_broker.gemspec +1 -1
  27. data/spec/integration/app_spec.rb +18 -0
  28. data/spec/lib/pact_broker/api/decorators/pacticipant_collection_decorator_spec.rb +2 -2
  29. data/spec/lib/pact_broker/api/decorators/pacticipant_decorator_spec.rb +2 -2
  30. data/spec/lib/pact_broker/api/resources/latest_pact_spec.rb +2 -2
  31. data/spec/lib/pact_broker/api/resources/pact_spec.rb +1 -1
  32. data/spec/lib/pact_broker/api/resources/pacticipants_spec.rb +1 -1
  33. data/spec/lib/pact_broker/diagnostic/resources/dependencies_spec.rb +85 -0
  34. data/spec/lib/pact_broker/diagnostic/resources/heartbeat_spec.rb +35 -0
  35. data/spec/lib/pact_broker/{functions → pacticipants}/find_potential_duplicate_pacticipant_names_spec.rb +2 -2
  36. data/spec/lib/pact_broker/pacts/create_formatted_diff_spec.rb +0 -1
  37. data/spec/lib/pact_broker/{services/pact_service_spec.rb → pacts/service_spec.rb} +5 -5
  38. data/spec/lib/pact_broker/{functions → relationships}/groupify_spec.rb +2 -2
  39. data/spec/lib/pact_broker/services/group_service_spec.rb +2 -2
  40. data/spec/lib/pact_broker/services/pacticipant_service_spec.rb +2 -2
  41. data/spec/service_consumers/provider_states_for_pact_broker_client.rb +1 -1
  42. data/spec/support/database_cleaner.rb +1 -1
  43. metadata +20 -14
  44. data/lib/pact_broker/repositories/pact_content.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90724c609e603dd08b1bc686cbc8c46eeff7c030
4
- data.tar.gz: b0b359476aea99b3738b802e8433441544d2add8
3
+ metadata.gz: 17b10186ffac951ca6a1d81ca4c4941b378d8e72
4
+ data.tar.gz: 8cfabd6ed5d782788096d445ae46e098679d0fcd
5
5
  SHA512:
6
- metadata.gz: e027014136c6782da4f3ba31b0d3779b0bb2d55fff9f91ad8378d1644a3facf94630e129140f81c1ea61e628e616e0da4cd14d55c56c290e464bb53989835418
7
- data.tar.gz: dbd9391992584cc6fddde02a8de3b15a5799b8a267db22947b3b48b50aa25a1e88d117c9b22a35d84a01a7260b4163843f3bdf010c696b223a747aaa47fe9eda
6
+ metadata.gz: 758286a2af8b8d56f12763e6b2a4c5f156186ed95a2f37ed4e30b24a8c2d79903fcdd54444317a3cef9fd67811cd5d8c9fed66e950aa9d5244e87b0949d0025b
7
+ data.tar.gz: c6db590d2225a0738a0b0dd9c8c1582ef1f887905990b383951537a9df23fdc5f1158c75de76242978d4c01689b66bce1f723f5c2f28438561cc5c5a24dbc3fb
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@ Do this to generate your change history
2
2
 
3
3
  $ git log --pretty=format:' * %h - %s (%an, %ad)'
4
4
 
5
+ #### 1.5.0 (2015-02-20)
6
+
7
+ * b848ce3 - Added healthcheck endpoint for database dependency. /diagnostic/status/dependencies (Beth, Fri Feb 20 09:41:16 2015 +1100)
8
+ * 56ea4a6 - Added heartbeat endpoint for monitoring. /diagnostic/status/heartbeat (Beth, Fri Feb 20 08:49:51 2015 +1100)
9
+ * dbdb4fb - Upgraded webmachine gem to 1.3.1 (Beth, Wed Feb 11 21:49:55 2015 +1100)
10
+ * 111f088 - Added validation to ensure that the encoding for the database connection is set to UTF8. This is required to ensure the pact_version_content_sha foreign key works. (Beth, Wed Feb 11 20:03:34 2015 +1100)
11
+
5
12
  #### 1.4.0 (2015-01-20)
6
13
 
7
14
  * d740fb0 - Removed pact-versions rel from pact resource. Pact versions resource is not implemented yet. (Beth, Tue Jan 20 09:20:52 2015 +1100)
data/lib/db.rb CHANGED
@@ -25,7 +25,7 @@ module DB
25
25
  # pool, as noted in the documentation for the extension.
26
26
  #
27
27
  def self.connect db_credentials
28
- con = Sequel.connect(db_credentials.merge(:logger => logger, :pool_class => Sequel::ThreadedConnectionPool))
28
+ con = Sequel.connect(db_credentials.merge(:logger => logger, :pool_class => Sequel::ThreadedConnectionPool, :encoding => 'utf8'))
29
29
  con.extension(:connection_validator)
30
30
  con.pool.connection_validation_timeout = -1 #Check the connection on every request
31
31
  con.timezone = :utc
@@ -6,7 +6,7 @@ module PactBroker
6
6
 
7
7
  module Decorators
8
8
 
9
- class BasicPacticipantRepresenter < BaseDecorator
9
+ class BasicPacticipantDecorator < BaseDecorator
10
10
 
11
11
  property :name
12
12
 
@@ -9,8 +9,8 @@ module PactBroker
9
9
 
10
10
  class PactDetailsDecorator < BaseDecorator
11
11
 
12
- property :consumer, :extend => PactBroker::Api::Decorators::PactPacticipantRepresenter, :embedded => true
13
- property :provider, :extend => PactBroker::Api::Decorators::PactPacticipantRepresenter, :embedded => true
12
+ property :consumer, :extend => PactBroker::Api::Decorators::PactPacticipantDecorator, :embedded => true
13
+ property :provider, :extend => PactBroker::Api::Decorators::PactPacticipantDecorator, :embedded => true
14
14
 
15
15
  link :self do | options |
16
16
  pact_url(options[:base_url], represented)
@@ -9,7 +9,7 @@ module PactBroker
9
9
 
10
10
  module Decorators
11
11
 
12
- class PactPacticipantRepresenter < BaseDecorator
12
+ class PactPacticipantDecorator < BaseDecorator
13
13
 
14
14
  property :name
15
15
  property :repository_url
@@ -8,9 +8,9 @@ module PactBroker
8
8
 
9
9
  module Decorators
10
10
 
11
- class PacticipantCollectionRepresenter < BaseDecorator
11
+ class PacticipantCollectionDecorator < BaseDecorator
12
12
 
13
- collection :entries, :as => :pacticipants, :class => PactBroker::Domain::Pacticipant, :extend => PactBroker::Api::Decorators::PacticipantRepresenter
13
+ collection :entries, :as => :pacticipants, :class => PactBroker::Domain::Pacticipant, :extend => PactBroker::Api::Decorators::PacticipantDecorator
14
14
 
15
15
  link :self do | options |
16
16
  pacticipants_url options[:base_url]
@@ -8,7 +8,7 @@ module PactBroker
8
8
 
9
9
  module Decorators
10
10
 
11
- class PacticipantRepresenter < BaseDecorator
11
+ class PacticipantDecorator < BaseDecorator
12
12
 
13
13
  property :name
14
14
  property :repository_url, as: :repositoryUrl
@@ -13,8 +13,8 @@ module PactBroker
13
13
 
14
14
  include Timestamps
15
15
 
16
- property :consumer, :extend => PactBroker::Api::Decorators::BasicPacticipantRepresenter, :embedded => true, writeable: false
17
- property :provider, :extend => PactBroker::Api::Decorators::BasicPacticipantRepresenter, :embedded => true, writeable: false
16
+ property :consumer, :extend => PactBroker::Api::Decorators::BasicPacticipantDecorator, :embedded => true, writeable: false
17
+ property :provider, :extend => PactBroker::Api::Decorators::BasicPacticipantDecorator, :embedded => true, writeable: false
18
18
 
19
19
  link :self do | options |
20
20
  {
@@ -50,7 +50,7 @@ module PactBroker
50
50
  end
51
51
 
52
52
  def to_json
53
- PactBroker::Api::Decorators::PacticipantRepresenter.new(pacticipant).to_json(base_url: base_url)
53
+ PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).to_json(base_url: base_url)
54
54
  end
55
55
 
56
56
  private
@@ -45,11 +45,11 @@ module PactBroker
45
45
  end
46
46
 
47
47
  def generate_json pacticipants
48
- PactBroker::Api::Decorators::PacticipantCollectionRepresenter.new(pacticipants).to_json(base_url: base_url)
48
+ PactBroker::Api::Decorators::PacticipantCollectionDecorator.new(pacticipants).to_json(base_url: base_url)
49
49
  end
50
50
 
51
51
  def decorator_for model
52
- PactBroker::Api::Decorators::PacticipantRepresenter.new(model)
52
+ PactBroker::Api::Decorators::PacticipantDecorator.new(model)
53
53
  end
54
54
 
55
55
  def new_model
@@ -24,7 +24,7 @@ module PactBroker
24
24
  API ||= begin
25
25
  pact_api = Webmachine::Application.new do |app|
26
26
  app.routes do
27
- add(['trace', '*'], Webmachine::Trace::TraceResource) unless ENV['RACK_ENV'] == 'production'
27
+ add(['trace', :*], Webmachine::Trace::TraceResource) unless ENV['RACK_ENV'] == 'production'
28
28
  # Support both /pact and /pacts
29
29
  # /pact will be deprecated
30
30
  # Todo, rename /version/ to /versions
@@ -31,6 +31,7 @@ module PactBroker
31
31
  PactBroker.logger = configuration.logger
32
32
  PactBroker::DB.connection = configuration.database_connection
33
33
  PactBroker::DB.connection.timezone = :utc
34
+ PactBroker::DB.validate_connection_config if configuration.validate_database_connection_config
34
35
 
35
36
  if configuration.auto_migrate_db
36
37
  logger.info "Migrating database"
@@ -59,7 +60,15 @@ module PactBroker
59
60
  logger.info "Mounting PactBroker::API"
60
61
  require 'pact_broker/api'
61
62
 
62
- apps = [PactBroker::UI::App.new, PactBroker::API]
63
+ apps = []
64
+
65
+ if configuration.enable_diagnostic_endpoints
66
+ require 'pact_broker/diagnostic/app'
67
+ apps << PactBroker::Diagnostic::App.new
68
+ end
69
+
70
+ apps << PactBroker::UI::App.new
71
+ apps << PactBroker::API
63
72
 
64
73
  @app.map "/" do
65
74
  run Rack::Cascade.new(apps)
@@ -7,6 +7,7 @@ module PactBroker
7
7
  class Configuration
8
8
 
9
9
  attr_accessor :log_dir, :database_connection, :auto_migrate_db, :use_hal_browser, :html_pact_renderer
10
+ attr_accessor :validate_database_connection_config, :enable_diagnostic_endpoints
10
11
  attr_writer :logger
11
12
 
12
13
  def logger
@@ -19,6 +20,8 @@ module PactBroker
19
20
  config.auto_migrate_db = true
20
21
  config.use_hal_browser = true
21
22
  config.html_pact_renderer = default_html_pact_render
23
+ config.validate_database_connection_config = true
24
+ config.enable_diagnostic_endpoints = true
22
25
  config
23
26
  end
24
27
 
@@ -1,4 +1,5 @@
1
1
  require 'sequel'
2
+ require 'pact_broker/db/validate_encoding'
2
3
 
3
4
  Sequel.datetime_class = DateTime
4
5
 
@@ -19,5 +20,9 @@ module PactBroker
19
20
  Sequel.extension :migration
20
21
  Sequel::Migrator.run(database_connection, PactBroker::DB::MIGRATIONS_DIR)
21
22
  end
23
+
24
+ def self.validate_connection_config
25
+ PactBroker::DB::ValidateEncoding.(connection)
26
+ end
22
27
  end
23
- end
28
+ end
@@ -0,0 +1,37 @@
1
+ require 'pact_broker/diagnostic/resources/heartbeat'
2
+ require 'pact_broker/diagnostic/resources/dependencies'
3
+ require 'webmachine/adapters/rack'
4
+
5
+ module PactBroker
6
+ module Diagnostic
7
+
8
+ class App
9
+ def initialize
10
+ @app = build_diagnostic_app
11
+ end
12
+
13
+ def call env
14
+ if env['PATH_INFO'].start_with? "/diagnostic/"
15
+ @app.call(env)
16
+ else
17
+ [404, {}, []]
18
+ end
19
+ end
20
+
21
+ def build_diagnostic_app
22
+ app = Webmachine::Application.new do |app|
23
+ app.routes do
24
+ add ['diagnostic','status','heartbeat'], Diagnostic::Resources::Heartbeat
25
+ add ['diagnostic','status','dependencies'], Diagnostic::Resources::Dependencies
26
+ end
27
+ end
28
+
29
+ app.configure do |config|
30
+ config.adapter = :Rack
31
+ end
32
+
33
+ app.adapter
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,65 @@
1
+ require 'webmachine'
2
+ require 'pact_broker/db'
3
+ require 'pact_broker/logging'
4
+
5
+ module PactBroker
6
+ module Diagnostic
7
+ module Resources
8
+ class Dependencies < Webmachine::Resource
9
+
10
+ include Logging
11
+
12
+ def initialize
13
+ @return_status = 200
14
+ end
15
+
16
+ def allowed_methods
17
+ ["GET"]
18
+ end
19
+
20
+ def content_types_provided
21
+ [["application/hal+json", :to_json]]
22
+ end
23
+
24
+ def to_json
25
+ ok, report = database_connectivity_status
26
+ response.body = {
27
+ "database" => report,
28
+ "_links" => {
29
+ "self" => {
30
+ "href" => request.uri.to_s
31
+ }
32
+ }
33
+ }.to_json
34
+
35
+ ok ? 200 : 500
36
+ end
37
+
38
+ private
39
+
40
+ def database_connectivity_status
41
+ begin
42
+ valid = valid_database_connection?
43
+ return valid, { "ok" => valid }
44
+ rescue => e
45
+ logger.error "#{e.class} - #{e.message}\n#{e.backtrace.join("\n")}"
46
+ report = {
47
+ "ok" => false,
48
+ "error" => {
49
+ "message" => "#{e.class} - #{e.message}"
50
+ }
51
+ }
52
+ return false, report
53
+ end
54
+ end
55
+
56
+ def valid_database_connection?
57
+ connection = PactBroker::DB.connection
58
+ connection.synchronize do |synchronized_connection|
59
+ connection.valid_connection? synchronized_connection
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,30 @@
1
+ require 'webmachine'
2
+
3
+ module PactBroker
4
+ module Diagnostic
5
+ module Resources
6
+ class Heartbeat < Webmachine::Resource
7
+
8
+ def allowed_methods
9
+ ["GET"]
10
+ end
11
+
12
+ def content_types_provided
13
+ [["application/hal+json", :to_json]]
14
+ end
15
+
16
+ def to_json
17
+ {
18
+ "ok" => true,
19
+ "_links" => {
20
+ "self" => {
21
+ "href" => request.uri.to_s
22
+ }
23
+ }
24
+ }.to_json
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,12 +1,8 @@
1
1
  require 'pact_broker/domain/group'
2
2
 
3
- =begin
4
-
5
- =end
6
-
7
3
  module PactBroker
8
4
 
9
- module Functions
5
+ module Pacticipants
10
6
 
11
7
  class FindPotentialDuplicatePacticipantNames
12
8
 
@@ -1,14 +1,14 @@
1
1
  require 'pact_broker/repositories'
2
+ require 'pact_broker/services'
2
3
 
3
4
  module PactBroker
4
-
5
- module Services
6
- module PactService
5
+ module Pacts
6
+ module Service
7
7
 
8
8
  extend self
9
9
 
10
- extend Repositories
11
- extend Services
10
+ extend PactBroker::Repositories
11
+ extend PactBroker::Services
12
12
 
13
13
  def find_latest_pact params
14
14
  pact_repository.find_latest_pact(params[:consumer_name], params[:provider_name], params[:tag])
@@ -6,7 +6,7 @@ require 'pact_broker/domain/group'
6
6
 
7
7
  module PactBroker
8
8
 
9
- module Functions
9
+ module Relationships
10
10
 
11
11
  class Groupify
12
12
 
@@ -36,4 +36,4 @@ module PactBroker
36
36
  end
37
37
 
38
38
  end
39
- end
39
+ end
@@ -1,5 +1,5 @@
1
1
  require 'pact_broker/repositories'
2
- require 'pact_broker/functions/groupify'
2
+ require 'pact_broker/relationships/groupify'
3
3
 
4
4
  module PactBroker
5
5
 
@@ -16,7 +16,7 @@ module PactBroker
16
16
  end
17
17
 
18
18
  def groups
19
- Functions::Groupify.call pacticipant_service.find_relationships
19
+ Relationships::Groupify.call pacticipant_service.find_relationships
20
20
  end
21
21
 
22
22
  end
@@ -2,7 +2,7 @@ require 'pact_broker/repositories'
2
2
  require 'pact_broker/logging'
3
3
  require 'pact_broker/messages'
4
4
  require 'pact_broker/domain/relationship'
5
- require 'pact_broker/functions/find_potential_duplicate_pacticipant_names'
5
+ require 'pact_broker/pacticipants/find_potential_duplicate_pacticipant_names'
6
6
 
7
7
  module PactBroker
8
8
 
@@ -25,7 +25,7 @@ module PactBroker
25
25
  end
26
26
 
27
27
  def self.find_potential_duplicate_pacticipants pacticipant_name
28
- PactBroker::Functions::FindPotentialDuplicatePacticipantNames
28
+ PactBroker::Pacticipants::FindPotentialDuplicatePacticipantNames
29
29
  .call(pacticipant_name, pacticipant_names).tap { | names|
30
30
  if names.any?
31
31
  logger.info "The following potential duplicate pacticipants were found for #{pacticipant_name}: #{names.join(", ")}"
@@ -1,4 +1,3 @@
1
- require 'pact_broker/services/pact_service'
2
1
  require 'pact_broker/services/pacticipant_service'
3
2
  require 'pact_broker/services/tag_service'
4
3
  require 'pact_broker/services/group_service'
@@ -7,8 +6,11 @@ require 'pact_broker/services/version_service'
7
6
 
8
7
  module PactBroker
9
8
  module Services
9
+
10
10
  def pact_service
11
- PactService
11
+ # TODO work out how to fix circular dependency
12
+ require 'pact_broker/pacts/service'
13
+ Pacts::Service
12
14
  end
13
15
 
14
16
  def pacticipant_service
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = '1.4.0'
2
+ VERSION = '1.5.0'
3
3
  end
data/pact_broker.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
25
25
  gem.add_runtime_dependency 'roar', '~> 1.0.0.beta2'
26
26
  gem.add_runtime_dependency 'reform', '~> 1.0'
27
27
  gem.add_runtime_dependency 'sequel', '~> 4.12'
28
- gem.add_runtime_dependency 'webmachine', '1.2'
28
+ gem.add_runtime_dependency 'webmachine', '1.3.1'
29
29
  gem.add_runtime_dependency 'versionomy', '~> 0.4'
30
30
  gem.add_runtime_dependency 'rack'
31
31
  gem.add_runtime_dependency 'redcarpet', '~>3.1'
@@ -12,12 +12,14 @@ module PactBroker
12
12
 
13
13
  let(:hal_browser_enabled) { true }
14
14
  let(:group_url) { '/groups/Some%20Consumer' }
15
+ let(:enable_diagnostic_endpoints) { false }
15
16
 
16
17
  let(:app) do
17
18
  app = PactBroker::App.new do | config |
18
19
  config.auto_migrate_db = false
19
20
  config.use_hal_browser = hal_browser_enabled
20
21
  config.database_connection = ::DB::PACT_BROKER_DB
22
+ config.enable_diagnostic_endpoints = enable_diagnostic_endpoints
21
23
  end
22
24
  end
23
25
 
@@ -163,5 +165,21 @@ module PactBroker
163
165
  end
164
166
 
165
167
  end
168
+
169
+ context "when the diagnostic endpoints are enabled" do
170
+ let(:enable_diagnostic_endpoints) { true }
171
+
172
+ it "returns a 200 to /diagnostic/status/heartbeat" do
173
+ get "/diagnostic/status/heartbeat"
174
+ expect(last_response.status).to eq 200
175
+ end
176
+ end
177
+
178
+ context "when the diagnostic endpoints are not enabled" do
179
+ it "returns a 404 to /diagnostic/status/heartbeat" do
180
+ get "/diagnostic/status/heartbeat"
181
+ expect(last_response.status).to eq 404
182
+ end
183
+ end
166
184
  end
167
185
  end
@@ -8,9 +8,9 @@ module PactBroker
8
8
 
9
9
  module Decorators
10
10
 
11
- describe PacticipantCollectionRepresenter do
11
+ describe PacticipantCollectionDecorator do
12
12
 
13
- subject { JSON.parse PacticipantCollectionRepresenter.new(pacticipants).to_json, symbolize_names: true }
13
+ subject { JSON.parse PacticipantCollectionDecorator.new(pacticipants).to_json, symbolize_names: true }
14
14
 
15
15
  context "with no pacticipants" do
16
16
  let(:pacticipants) { [] }
@@ -8,13 +8,13 @@ module PactBroker
8
8
 
9
9
  module Decorators
10
10
 
11
- describe PacticipantRepresenter do
11
+ describe PacticipantDecorator do
12
12
 
13
13
  let(:created_at) { Time.new(2014, 3, 4) }
14
14
  let(:updated_at) { Time.new(2014, 3, 5) }
15
15
  let(:pacticipant) { PactBroker::Domain::Pacticipant.new(name: 'Name', updated_at: updated_at, created_at: created_at)}
16
16
 
17
- subject { JSON.parse PacticipantRepresenter.new(pacticipant).to_json, symbolize_names: true }
17
+ subject { JSON.parse PacticipantDecorator.new(pacticipant).to_json, symbolize_names: true }
18
18
 
19
19
  it "includes timestamps" do
20
20
  expect(subject[:createdAt]).to eq created_at.xmlschema
@@ -22,14 +22,14 @@ module PactBroker::Api
22
22
  let(:pact_id_params) { {:provider_name=>"provider_name", :consumer_name=>"consumer_name"} }
23
23
 
24
24
  before do
25
- allow(PactBroker::Services::PactService).to receive(:find_latest_pact).and_return(pact)
25
+ allow(PactBroker::Pacts::Service).to receive(:find_latest_pact).and_return(pact)
26
26
  allow(PactBroker.configuration.html_pact_renderer).to receive(:call).and_return(html)
27
27
  end
28
28
 
29
29
  subject { get "/pacts/provider/provider_name/consumer/consumer_name/latest",{}, {'HTTP_ACCEPT' => "text/html"} }
30
30
 
31
31
  it "find the pact" do
32
- expect(PactBroker::Services::PactService).to receive(:find_latest_pact).with(pact_id_params)
32
+ expect(PactBroker::Pacts::Service).to receive(:find_latest_pact).with(pact_id_params)
33
33
  subject
34
34
  end
35
35
 
@@ -83,7 +83,7 @@ module PactBroker::Api
83
83
  subject { delete "/pacts/provider/Provider/consumer/Consumer/version/1.2", json, {'CONTENT_TYPE' => "application/json"} ; last_response }
84
84
 
85
85
  let(:pact) { double('pact') }
86
- let(:pact_service) { PactBroker::Services::PactService }
86
+ let(:pact_service) { PactBroker::Pacts::Service }
87
87
  let(:response) { subject; last_response }
88
88
 
89
89
  before do
@@ -14,7 +14,7 @@ module PactBroker
14
14
  let(:created_model) { instance_double(model_class) }
15
15
  let(:errors) { [] }
16
16
  let(:model_class) { PactBroker::Domain::Pacticipant }
17
- let(:decorator_class) { PactBroker::Api::Decorators::PacticipantRepresenter }
17
+ let(:decorator_class) { PactBroker::Api::Decorators::PacticipantDecorator }
18
18
  let(:decorator) { instance_double(decorator_class, to_json: response_json, from_json: model) }
19
19
  let(:response_json) { {some: 'json'}.to_json }
20
20
 
@@ -0,0 +1,85 @@
1
+ require 'pact_broker/diagnostic/app'
2
+ require 'rack/test'
3
+
4
+ module PactBroker
5
+ module Diagnostic
6
+ module Resources
7
+ describe Dependencies do
8
+
9
+ describe "GET /diagnostic/status/dependencies" do
10
+
11
+ include Rack::Test::Methods
12
+
13
+ let(:app) { PactBroker::Diagnostic::App.new }
14
+ let(:parsed_response_body) { JSON.parse(subject.body) }
15
+
16
+ subject { get "/diagnostic/status/dependencies"; last_response }
17
+
18
+ it "returns application/hal+json" do
19
+ expect(subject.headers['Content-Type']).to eq "application/hal+json"
20
+ end
21
+
22
+ it "returns a link to itself" do
23
+ expect(parsed_response_body['_links']['self']['href']).to eq "http://example.org/diagnostic/status/dependencies"
24
+ end
25
+
26
+ context "when we can connect to the database" do
27
+ before do
28
+ allow(PactBroker::DB.connection).to receive(:valid_connection?).and_return(true)
29
+ end
30
+
31
+ it "returns a 200 response" do
32
+ expect(subject.status).to eq 200
33
+ end
34
+
35
+ it "indicates that the database connectivity is OK" do
36
+ expect(parsed_response_body['database']['ok']).to be true
37
+ end
38
+ end
39
+
40
+ context "when we can't connect to the database" do
41
+ before do
42
+ allow(PactBroker::DB.connection).to receive(:valid_connection?).and_return(false)
43
+ end
44
+
45
+ it "returns a 500 response" do
46
+ expect(subject.status).to eq 500
47
+ end
48
+
49
+ it "indicates that the database connectivity is not OK" do
50
+ expect(parsed_response_body['database']['ok']).to be false
51
+ end
52
+ end
53
+
54
+ context "when there is an exception valiating the database connection" do
55
+
56
+ class TestError < StandardError; end
57
+
58
+ before do
59
+ allow(PactBroker::DB.connection).to receive(:valid_connection?).and_raise(TestError.new("a message"))
60
+ end
61
+
62
+ it "returns a 500 response" do
63
+ expect(subject.status).to eq 500
64
+ end
65
+
66
+ it "indicates that the database connectivity is not OK" do
67
+ expect(parsed_response_body['database']['ok']).to be false
68
+ end
69
+
70
+ it "includes an error message" do
71
+ expect(parsed_response_body['database']['error']['message']).to eq "PactBroker::Diagnostic::Resources::TestError - a message"
72
+ end
73
+
74
+ it "logs the error" do
75
+ logger = double('Logger')
76
+ allow_any_instance_of(PactBroker::Diagnostic::Resources::Dependencies).to receive(:logger).and_return(logger)
77
+ expect(logger).to receive(:error).with(/TestError.*a message/)
78
+ subject
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,35 @@
1
+ require 'pact_broker/diagnostic/resources/heartbeat'
2
+ require 'pact_broker/diagnostic/app'
3
+ require 'rack/test'
4
+
5
+ module PactBroker
6
+ module Diagnostic
7
+ module Resources
8
+ describe Heartbeat do
9
+
10
+ include Rack::Test::Methods
11
+
12
+ let(:app) { PactBroker::Diagnostic::App.new }
13
+
14
+ describe "GET /diagnostic/status/heartbeat" do
15
+
16
+ let(:parsed_response_body) { JSON.parse(subject.body) }
17
+
18
+ subject { get "/diagnostic/status/heartbeat"; last_response }
19
+
20
+ it "returns a 200" do
21
+ expect(subject.status).to eq 200
22
+ end
23
+
24
+ it "returns application/hal+json" do
25
+ expect(subject.headers['Content-Type']).to eq "application/hal+json"
26
+ end
27
+
28
+ it "returns a link to itself" do
29
+ expect(parsed_response_body['_links']['self']['href']).to eq "http://example.org/diagnostic/status/heartbeat"
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
- require 'pact_broker/functions/find_potential_duplicate_pacticipant_names'
2
+ require 'pact_broker/pacticipants/find_potential_duplicate_pacticipant_names'
3
3
 
4
4
  module PactBroker
5
5
 
6
- module Functions
6
+ module Pacticipants
7
7
 
8
8
  describe FindPotentialDuplicatePacticipantNames do
9
9
 
@@ -19,7 +19,6 @@ module PactBroker
19
19
  subject { CreateFormattedDiff.call(pact_content_version_2, pact_content_version_1) }
20
20
 
21
21
  it "returns the formatted diff" do
22
- puts subject
23
22
  expect(subject).to include 'interactions'
24
23
  expect(subject).to match /\-.*post/
25
24
  expect(subject).to match /\+.*get/
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
- require 'pact_broker/services/pact_service'
2
+ require 'pact_broker/pacts/service'
3
3
 
4
4
  module PactBroker
5
5
 
6
- module Services
7
- module PactService
6
+ module Pacts
7
+ module Service
8
8
 
9
9
  describe "find_distinct_pacts_between" do
10
10
  let(:pact_1) { double('pact 1', json_content: 'content 1')}
@@ -18,7 +18,7 @@ module PactBroker
18
18
  allow_any_instance_of(Pacts::Repository).to receive(:find_all_pacts_between).and_return(all_pacts)
19
19
  end
20
20
 
21
- subject { PactService.find_distinct_pacts_between 'consumer', :and => 'provider' }
21
+ subject { Service.find_distinct_pacts_between 'consumer', :and => 'provider' }
22
22
 
23
23
  it "returns the distinct pacts" do
24
24
  expect(subject).to eq [pact_4, pact_2, pact_1]
@@ -35,7 +35,7 @@ module PactBroker
35
35
  allow_any_instance_of(Pacts::Repository).to receive(:find_previous_pact).and_return(previous_pact)
36
36
  end
37
37
 
38
- subject { PactService.pact_has_changed_since_previous_version? pact }
38
+ subject { Service.pact_has_changed_since_previous_version? pact }
39
39
 
40
40
  context "when a previous pact is found" do
41
41
  let(:previous_pact) { instance_double(PactBroker::Domain::Pact, json_content: previous_json_content)}
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
- require 'pact_broker/functions/groupify'
2
+ require 'pact_broker/relationships/groupify'
3
3
  require 'pact_broker/domain/relationship'
4
4
 
5
5
  module PactBroker
6
6
 
7
- module Functions
7
+ module Relationships
8
8
 
9
9
  describe Groupify do
10
10
 
@@ -28,7 +28,7 @@ module PactBroker
28
28
 
29
29
  before do
30
30
  allow(PacticipantService).to receive(:find_relationships).and_return(relationship_list)
31
- allow(Functions::Groupify).to receive(:call).and_return(groups)
31
+ allow(Relationships::Groupify).to receive(:call).and_return(groups)
32
32
  end
33
33
 
34
34
  it "retrieves a list of the relationships" do
@@ -37,7 +37,7 @@ module PactBroker
37
37
  end
38
38
 
39
39
  it "turns the relationships into groups" do
40
- expect(Functions::Groupify).to receive(:call).with(relationship_list)
40
+ expect(Relationships::Groupify).to receive(:call).with(relationship_list)
41
41
  subject
42
42
  end
43
43
 
@@ -63,7 +63,7 @@ module PactBroker
63
63
  let(:pacticipant_repository) { instance_double(PactBroker::Repositories::PacticipantRepository)}
64
64
 
65
65
  before do
66
- allow(PactBroker::Functions::FindPotentialDuplicatePacticipantNames).to receive(:call).and_return(duplicates)
66
+ allow(PactBroker::Pacticipants::FindPotentialDuplicatePacticipantNames).to receive(:call).and_return(duplicates)
67
67
  allow(PactBroker::Repositories::PacticipantRepository).to receive(:new).and_return(pacticipant_repository)
68
68
  allow(pacticipant_repository).to receive(:pacticipant_names).and_return(pacticipant_names)
69
69
  allow(pacticipant_repository).to receive(:find_by_name).with("Fred").and_return(fred)
@@ -76,7 +76,7 @@ module PactBroker
76
76
  end
77
77
 
78
78
  it "calculates the duplicates" do
79
- expect(PactBroker::Functions::FindPotentialDuplicatePacticipantNames).to receive(:call).with(pacticipant_name, pacticipant_names)
79
+ expect(PactBroker::Pacticipants::FindPotentialDuplicatePacticipantNames).to receive(:call).with(pacticipant_name, pacticipant_names)
80
80
  subject.find_potential_duplicate_pacticipants pacticipant_name
81
81
  end
82
82
 
@@ -14,7 +14,7 @@ Pact.provider_states_for "Pact Broker Client" do
14
14
 
15
15
  provider_state "an error occurs while publishing a pact" do
16
16
  set_up do
17
- allow(PactBroker::Services::PactService).to receive(:create_or_update_pact).and_raise("an error")
17
+ allow(PactBroker::Pacts::Service).to receive(:create_or_update_pact).and_raise("an error")
18
18
  end
19
19
  end
20
20
 
@@ -15,4 +15,4 @@ RSpec.configure do |config|
15
15
  config.after(:each) do
16
16
  DatabaseCleaner.clean if defined?(::DB)
17
17
  end
18
- end
18
+ 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: 1.4.0
4
+ version: 1.5.0
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: 2015-01-19 00:00:00.000000000 Z
13
+ date: 2015-02-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -88,14 +88,14 @@ dependencies:
88
88
  requirements:
89
89
  - - '='
90
90
  - !ruby/object:Gem::Version
91
- version: '1.2'
91
+ version: 1.3.1
92
92
  type: :runtime
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - '='
97
97
  - !ruby/object:Gem::Version
98
- version: '1.2'
98
+ version: 1.3.1
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: versionomy
101
101
  requirement: !ruby/object:Gem::Requirement
@@ -448,6 +448,9 @@ files:
448
448
  - lib/pact_broker/date_helper.rb
449
449
  - lib/pact_broker/db.rb
450
450
  - lib/pact_broker/db/validate_encoding.rb
451
+ - lib/pact_broker/diagnostic/app.rb
452
+ - lib/pact_broker/diagnostic/resources/dependencies.rb
453
+ - lib/pact_broker/diagnostic/resources/heartbeat.rb
451
454
  - lib/pact_broker/doc/controllers/app.rb
452
455
  - lib/pact_broker/doc/views/consumer.markdown
453
456
  - lib/pact_broker/doc/views/diff-previous-distinct.markdown
@@ -474,12 +477,11 @@ files:
474
477
  - lib/pact_broker/domain/webhook_execution_result.rb
475
478
  - lib/pact_broker/domain/webhook_request.rb
476
479
  - lib/pact_broker/domain/webhook_request_header.rb
477
- - lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb
478
- - lib/pact_broker/functions/groupify.rb
479
480
  - lib/pact_broker/json.rb
480
481
  - lib/pact_broker/locale/en.yml
481
482
  - lib/pact_broker/logging.rb
482
483
  - lib/pact_broker/messages.rb
484
+ - lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
483
485
  - lib/pact_broker/pacts/all_pacts.rb
484
486
  - lib/pact_broker/pacts/create_formatted_diff.rb
485
487
  - lib/pact_broker/pacts/database_model.rb
@@ -488,9 +490,10 @@ files:
488
490
  - lib/pact_broker/pacts/pact_params.rb
489
491
  - lib/pact_broker/pacts/pact_version_content.rb
490
492
  - lib/pact_broker/pacts/repository.rb
493
+ - lib/pact_broker/pacts/service.rb
491
494
  - lib/pact_broker/project_root.rb
495
+ - lib/pact_broker/relationships/groupify.rb
492
496
  - lib/pact_broker/repositories.rb
493
- - lib/pact_broker/repositories/pact_content.rb
494
497
  - lib/pact_broker/repositories/pacticipant_repository.rb
495
498
  - lib/pact_broker/repositories/tag_repository.rb
496
499
  - lib/pact_broker/repositories/version_repository.rb
@@ -498,7 +501,6 @@ files:
498
501
  - lib/pact_broker/repositories/webhook_repository.rb
499
502
  - lib/pact_broker/services.rb
500
503
  - lib/pact_broker/services/group_service.rb
501
- - lib/pact_broker/services/pact_service.rb
502
504
  - lib/pact_broker/services/pacticipant_service.rb
503
505
  - lib/pact_broker/services/tag_service.rb
504
506
  - lib/pact_broker/services/version_service.rb
@@ -599,25 +601,27 @@ files:
599
601
  - spec/lib/pact_broker/api/resources/webhooks_spec.rb
600
602
  - spec/lib/pact_broker/configuration_spec.rb
601
603
  - spec/lib/pact_broker/db/validate_encoding_spec.rb
604
+ - spec/lib/pact_broker/diagnostic/resources/dependencies_spec.rb
605
+ - spec/lib/pact_broker/diagnostic/resources/heartbeat_spec.rb
602
606
  - spec/lib/pact_broker/doc/controllers/app_spec.rb
603
607
  - spec/lib/pact_broker/domain/group_spec.rb
604
608
  - spec/lib/pact_broker/domain/order_versions_spec.rb
605
609
  - spec/lib/pact_broker/domain/pacticipant_spec.rb
606
610
  - spec/lib/pact_broker/domain/webhook_request_spec.rb
607
611
  - spec/lib/pact_broker/domain/webhook_spec.rb
608
- - spec/lib/pact_broker/functions/find_potential_duplicate_pacticipant_names_spec.rb
609
- - spec/lib/pact_broker/functions/groupify_spec.rb
610
612
  - spec/lib/pact_broker/messages_spec.rb
613
+ - spec/lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names_spec.rb
611
614
  - spec/lib/pact_broker/pacts/create_formatted_diff_spec.rb
612
615
  - spec/lib/pact_broker/pacts/diff_spec.rb
613
616
  - spec/lib/pact_broker/pacts/pact_params_spec.rb
614
617
  - spec/lib/pact_broker/pacts/repository_spec.rb
618
+ - spec/lib/pact_broker/pacts/service_spec.rb
619
+ - spec/lib/pact_broker/relationships/groupify_spec.rb
615
620
  - spec/lib/pact_broker/repositories/pacticipant_repository_spec.rb
616
621
  - spec/lib/pact_broker/repositories/tag_repository_spec.rb
617
622
  - spec/lib/pact_broker/repositories/version_repository_spec.rb
618
623
  - spec/lib/pact_broker/repositories/webhook_repository_spec.rb
619
624
  - spec/lib/pact_broker/services/group_service_spec.rb
620
- - spec/lib/pact_broker/services/pact_service_spec.rb
621
625
  - spec/lib/pact_broker/services/pacticipant_service_spec.rb
622
626
  - spec/lib/pact_broker/services/tag_service_spec.rb
623
627
  - spec/lib/pact_broker/services/webhook_service_spec.rb
@@ -747,25 +751,27 @@ test_files:
747
751
  - spec/lib/pact_broker/api/resources/webhooks_spec.rb
748
752
  - spec/lib/pact_broker/configuration_spec.rb
749
753
  - spec/lib/pact_broker/db/validate_encoding_spec.rb
754
+ - spec/lib/pact_broker/diagnostic/resources/dependencies_spec.rb
755
+ - spec/lib/pact_broker/diagnostic/resources/heartbeat_spec.rb
750
756
  - spec/lib/pact_broker/doc/controllers/app_spec.rb
751
757
  - spec/lib/pact_broker/domain/group_spec.rb
752
758
  - spec/lib/pact_broker/domain/order_versions_spec.rb
753
759
  - spec/lib/pact_broker/domain/pacticipant_spec.rb
754
760
  - spec/lib/pact_broker/domain/webhook_request_spec.rb
755
761
  - spec/lib/pact_broker/domain/webhook_spec.rb
756
- - spec/lib/pact_broker/functions/find_potential_duplicate_pacticipant_names_spec.rb
757
- - spec/lib/pact_broker/functions/groupify_spec.rb
758
762
  - spec/lib/pact_broker/messages_spec.rb
763
+ - spec/lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names_spec.rb
759
764
  - spec/lib/pact_broker/pacts/create_formatted_diff_spec.rb
760
765
  - spec/lib/pact_broker/pacts/diff_spec.rb
761
766
  - spec/lib/pact_broker/pacts/pact_params_spec.rb
762
767
  - spec/lib/pact_broker/pacts/repository_spec.rb
768
+ - spec/lib/pact_broker/pacts/service_spec.rb
769
+ - spec/lib/pact_broker/relationships/groupify_spec.rb
763
770
  - spec/lib/pact_broker/repositories/pacticipant_repository_spec.rb
764
771
  - spec/lib/pact_broker/repositories/tag_repository_spec.rb
765
772
  - spec/lib/pact_broker/repositories/version_repository_spec.rb
766
773
  - spec/lib/pact_broker/repositories/webhook_repository_spec.rb
767
774
  - spec/lib/pact_broker/services/group_service_spec.rb
768
- - spec/lib/pact_broker/services/pact_service_spec.rb
769
775
  - spec/lib/pact_broker/services/pacticipant_service_spec.rb
770
776
  - spec/lib/pact_broker/services/tag_service_spec.rb
771
777
  - spec/lib/pact_broker/services/webhook_service_spec.rb
File without changes