pact_broker 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +13 -5
  2. data/.gitignore +2 -0
  3. data/CHANGELOG.md +5 -0
  4. data/README.md +2 -1
  5. data/Rakefile +1 -3
  6. data/db/migrations/07_increase_json_content_length.rb +6 -1
  7. data/db/migrations/08_create_latest_pact_view.rb +7 -5
  8. data/db/migrations/14_add_timestamps_to_pact_views.rb +28 -0
  9. data/lib/pact_broker/api.rb +0 -4
  10. data/lib/pact_broker/api/decorators/latest_pact_decorator.rb +4 -1
  11. data/lib/pact_broker/api/decorators/pact_decorator.rb +2 -2
  12. data/lib/pact_broker/api/decorators/pact_version_decorator.rb +3 -4
  13. data/lib/pact_broker/api/decorators/pact_versions_decorator.rb +4 -4
  14. data/lib/pact_broker/api/decorators/pacticipant_decorator.rb +3 -2
  15. data/lib/pact_broker/api/decorators/tag_decorator.rb +2 -2
  16. data/lib/pact_broker/api/decorators/timestamps.rb +24 -0
  17. data/lib/pact_broker/api/decorators/webhook_decorator.rb +2 -2
  18. data/lib/pact_broker/api/decorators/webhooks_decorator.rb +4 -4
  19. data/lib/pact_broker/api/renderers/html_pact_renderer.rb +16 -4
  20. data/lib/pact_broker/api/resources/base_resource.rb +0 -1
  21. data/lib/pact_broker/api/resources/group.rb +11 -6
  22. data/lib/pact_broker/api/resources/index.rb +5 -6
  23. data/lib/pact_broker/api/resources/latest_pact.rb +8 -5
  24. data/lib/pact_broker/api/resources/latest_pacts.rb +3 -3
  25. data/lib/pact_broker/api/resources/pact.rb +9 -5
  26. data/lib/pact_broker/api/resources/pact_webhooks.rb +9 -5
  27. data/lib/pact_broker/api/resources/pacticipant.rb +10 -5
  28. data/lib/pact_broker/api/resources/relationships.rb +3 -3
  29. data/lib/pact_broker/api/resources/tag.rb +8 -7
  30. data/lib/pact_broker/api/resources/webhook.rb +1 -1
  31. data/lib/pact_broker/api/resources/webhook_execution.rb +1 -1
  32. data/lib/pact_broker/app.rb +8 -57
  33. data/lib/pact_broker/logging.rb +1 -0
  34. data/lib/pact_broker/models/pact.rb +6 -8
  35. data/lib/pact_broker/repositories/pact.rb +29 -0
  36. data/lib/pact_broker/repositories/pact_content.rb +0 -0
  37. data/lib/pact_broker/repositories/pact_repository.rb +66 -21
  38. data/lib/pact_broker/repositories/tag_repository.rb +1 -1
  39. data/lib/pact_broker/repositories/version_repository.rb +2 -1
  40. data/lib/pact_broker/services/pact_service.rb +14 -16
  41. data/lib/pact_broker/ui.rb +2 -0
  42. data/lib/pact_broker/ui/app.rb +81 -0
  43. data/lib/pact_broker/ui/controllers/groups.rb +1 -1
  44. data/lib/pact_broker/version.rb +1 -1
  45. data/lib/rack/pact_broker/convert_file_extension_to_accept_header.rb +44 -0
  46. data/pact_broker.gemspec +1 -0
  47. data/public/javascripts/highlight.pack.js +1 -0
  48. data/public/stylesheets/github-json.css +127 -0
  49. data/public/stylesheets/pact.css +4 -0
  50. data/spec/fixtures/consumer-provider.json +21 -0
  51. data/spec/integration/app_spec.rb +165 -0
  52. data/spec/integration/endpoints/pact_put_spec.rb +43 -0
  53. data/spec/lib/pact_broker/api/decorators/latest_pact_decorator_spec.rb +42 -0
  54. data/spec/lib/pact_broker/api/decorators/pact_version_decorator_spec.rb +5 -0
  55. data/spec/lib/pact_broker/api/decorators/pacticipant_decorator_spec.rb +2 -1
  56. data/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +9 -2
  57. data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +14 -3
  58. data/spec/lib/pact_broker/repositories/pact_repository_spec.rb +88 -4
  59. data/spec/lib/pact_broker/repositories/tag_repository_spec.rb +2 -0
  60. data/spec/lib/pact_broker/repositories/version_repository_spec.rb +20 -2
  61. data/spec/lib/pact_broker/services/pacticipant_service_spec.rb +1 -1
  62. data/spec/service_consumers/pact_helper.rb +2 -17
  63. data/spec/spec_helper.rb +4 -22
  64. data/spec/support/database_cleaner.rb +18 -0
  65. data/spec/support/fixture_helpers.rb +10 -0
  66. data/spec/support/provider_state_builder.rb +4 -15
  67. metadata +82 -47
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: eab6ba50f1698c583aa2c5ea2499134dccdf26fe
4
- data.tar.gz: 90c46d03810fdaba756c7d10528193636913a159
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzNkZTQzNTE1OWIzZDNlYmQ0Y2IzODEyZmRkYzhjZWI0YjIwMDIxMg==
5
+ data.tar.gz: !binary |-
6
+ N2QwYjkzYzk0YWQ1NjFkODVkZjIyOGJiYThhMzEwYzRlNGIxM2RkNw==
5
7
  SHA512:
6
- metadata.gz: 71d627be7fcefa1d267b9e6347bd473aea3fe9b204a2d3235b9a0df7f03701f45ff764a9e235300b3b813ba19027f9bb5b3cca18261e5a2461d8cdf134a142af
7
- data.tar.gz: 45bebda0fb63072a4fc33c082b1990b1a0ae941e04858624a733aa94a7aab9c51ab6b8bd8a965b350c1128987590ddb4f5fc489ed1bc6e4dfcac68346c5799c8
8
+ metadata.gz: !binary |-
9
+ NzlkN2YyYzI4YWM1OTNmNWVmN2RkYTcwMjU1ZWJiNGI2OGE2NDFjYmZmNTY0
10
+ MmE3Yzc1NGVmZDA0YmQ2YjJlYjZhODIwODAxOGRhYTgxZGI1MTZmODRlOGY5
11
+ ZGYyMDRiNzBkN2MzMmIxOWI4ZTI4MDM1MDIwNmFiNTU5N2I0ZTk=
12
+ data.tar.gz: !binary |-
13
+ MDNkNzJkNjgwYzI2ZjdiOGM2NTNhZmJiMDBmNWZjNWVjZTVmM2VlYTQyOTI4
14
+ NzEwN2JjYzUxYWViMzJiZGI1NzQwYTkyNTJjZTM2NGI1Y2FmNjE4OWVhYTUx
15
+ NTA1NDgyYjYxZDQyNDE4NGEyYWY3Yzc5M2VlYWJiYjBjNjRiYmY=
data/.gitignore CHANGED
@@ -26,3 +26,5 @@ _yardoc
26
26
 
27
27
  *.sqlite
28
28
  Gemfile.lock
29
+
30
+ bethtest/
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@ Do this to generate your change history
2
2
 
3
3
  $ git log --pretty=format:' * %h - %s (%an, %ad)'
4
4
 
5
+ #### 1.3.0 (2014-10-14)
6
+
7
+ * ed08811 - Converted raw SQL create view statements to Sequel so they will run on Postgres (Beth, Sat Oct 11 22:07:37 2014 +1100)
8
+ * 457edf4 - Added syntax highlighting to JSON in autogenerated HTML docs. (Beth, Wed Sep 24 22:12:14 2014 +1000)
9
+
5
10
  #### 1.2.0 (2014-09-22)
6
11
 
7
12
  * 0ccde50 - Made webhook creation code more Webmachiney. (Beth, Tue Sep 16 10:07:56 2014 +1000)
data/README.md CHANGED
@@ -18,7 +18,8 @@ See the [wiki](https://github.com/bethesque/pact_broker/wiki) for documentation.
18
18
 
19
19
  ## Usage
20
20
 
21
- * Create a database using a product that is supported by the Sequel gem (listed on this page http://sequel.jeremyevans.net/rdoc/files/README_rdoc.html). At time of writing, Sequel has adapters for: ADO, Amalgalite, CUBRID, DataObjects, DB2, DBI, Firebird, IBM_DB, Informix, JDBC, MySQL, Mysql2, ODBC, OpenBase, Oracle, PostgreSQL, SQLAnywhere, SQLite3, Swift, and TinyTDS
21
+ * Create a database using a product that is supported by the Sequel gem (listed on this page http://sequel.jeremyevans.net/rdoc/files/README_rdoc.html). At time of writing, Sequel has adapters for: ADO, Amalgalite, CUBRID, DataObjects, DB2, DBI, Firebird, IBM_DB, Informix, JDBC, MySQL, Mysql2, ODBC, OpenBase, Oracle, PostgreSQL, SQLAnywhere, SQLite3, Swift, and TinyTDS.
22
+ * __Note:__ It is recommended to use __PostgreSQL__ as it will support JSON search features that are planned in a future release.
22
23
  * Install ruby 1.9.3 or later
23
24
  * Copy the [example](/example) directory to your workstation.
24
25
  * Modify the config.ru and Gemfile as desired (eg. choose database driver gem, set your database credentials)
data/Rakefile CHANGED
@@ -10,13 +10,11 @@ rescue Bundler::BundlerError => e
10
10
  $stderr.puts "Run `bundle install` to install missing gems"
11
11
  exit e.status_code
12
12
  end
13
- require 'rake'
14
-
15
13
 
16
14
  FileList['lib/tasks/**/*.rake'].each { |task| load "#{Dir.pwd}/#{task}" }
17
15
  FileList['tasks/**/*.rake'].each { |task| load "#{Dir.pwd}/#{task}" }
18
16
 
19
- task :default => ['db:prepare:test', :boot, :spec]
17
+ task :default => ['db:prepare:test', :boot, :spec, 'pact:verify']
20
18
 
21
19
  task :boot do
22
20
  require File.join(File.dirname(__FILE__), 'config/boot')
@@ -1,7 +1,12 @@
1
1
  Sequel.migration do
2
2
  change do
3
3
  alter_table(:pacts) do
4
- set_column_type(:json_content, :mediumtext)
4
+ if Sequel::Model.db.adapter_scheme == :postgres
5
+ set_column_type(:json_content, :text)
6
+ else
7
+ # Assume mysql
8
+ set_column_type(:json_content, :mediumtext)
9
+ end
5
10
  end
6
11
  end
7
12
  end
@@ -1,11 +1,13 @@
1
1
  Sequel.migration do
2
2
  change do
3
3
  create_view(:all_pacts,
4
- "select pact.id, c.id as consumer_id, c.name as consumer_name, cv.number as consumer_version_number, cv.`order` as consumer_version_order, p.id as provider_id, p.name as provider_name, pact.json_content
5
- from pacts pact
6
- join versions cv on pact.version_id = cv.id
7
- join pacticipants c on cv.pacticipant_id = c.id
8
- join pacticipants p on pact.provider_id = p.id")
4
+ Sequel::Model.db[:pacts].select(:pacts__id, :c__id___consumer_id, :c__name___consumer_name,
5
+ :cv__number___consumer_version_number, :cv__order___consumer_version_order,
6
+ :p__id___provider_id, :p__name___provider_name,
7
+ :pacts__json_content).
8
+ join(:versions, {:id => :version_id}, {:table_alias => :cv, implicit_qualifier: :pacts}).
9
+ join(:pacticipants, {:id => :pacticipant_id}, {:table_alias => :c, implicit_qualifier: :cv}).
10
+ join(:pacticipants, {:id => :provider_id}, {:table_alias => :p, implicit_qualifier: :pacts}))
9
11
 
10
12
  create_view(:latest_pact_consumer_version_orders,
11
13
  "select provider_id, consumer_id, max(consumer_version_order) as latest_consumer_version_order
@@ -0,0 +1,28 @@
1
+ Sequel.migration do
2
+ change do
3
+ create_or_replace_view(:all_pacts,
4
+ Sequel::Model.db[:pacts].select(:pacts__id, :c__id___consumer_id, :c__name___consumer_name,
5
+ :cv__number___consumer_version_number, :cv__order___consumer_version_order,
6
+ :p__id___provider_id, :p__name___provider_name,
7
+ :pacts__json_content, :pacts__created_at, :pacts__updated_at).
8
+ join(:versions, {:id => :version_id}, {:table_alias => :cv, implicit_qualifier: :pacts}).
9
+ join(:pacticipants, {:id => :pacticipant_id}, {:table_alias => :c, implicit_qualifier: :cv}).
10
+ join(:pacticipants, {:id => :provider_id}, {:table_alias => :p, implicit_qualifier: :pacts}))
11
+
12
+ create_or_replace_view(:latest_pact_consumer_version_orders,
13
+ "select provider_id, consumer_id, max(consumer_version_order) as latest_consumer_version_order
14
+ from all_pacts
15
+ group by provider_id, consumer_id"
16
+ )
17
+
18
+ create_or_replace_view(:latest_pacts,
19
+ "select ap.*
20
+ from all_pacts ap
21
+ inner join latest_pact_consumer_version_orders lp
22
+ on ap.consumer_id = lp.consumer_id
23
+ and ap.provider_id = lp.provider_id
24
+ and ap.consumer_version_order = latest_consumer_version_order"
25
+ )
26
+ end
27
+ end
28
+
@@ -35,10 +35,6 @@ module PactBroker
35
35
  add ['pacticipants', :pacticipant_name, 'versions', :pacticipant_version_number, 'tags', :tag_name], Api::Resources::Tag
36
36
  add ['relationships'], Api::Resources::Relationships
37
37
  add ['groups', :pacticipant_name], Api::Resources::Group
38
- # If the HTML and the CSV resources are both requested by the browser,
39
- # Chrome gets confused by the content types, and when you click back, it tries to load the CSV
40
- # instead of the HTML page. So we have to give it a different URL.
41
- add ['groups', :pacticipant_name, 'csv'], Api::Resources::Group
42
38
  add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name ], Api::Resources::PactWebhooks
43
39
  add ['webhooks', :uuid ], Api::Resources::Webhook
44
40
  add ['webhooks', :uuid, 'execute' ], Api::Resources::WebhookExecution
@@ -1,4 +1,5 @@
1
1
  require_relative 'pact_details_decorator'
2
+ require 'pact_broker/api/decorators/timestamps'
2
3
 
3
4
  module PactBroker
4
5
 
@@ -8,6 +9,8 @@ module PactBroker
8
9
 
9
10
  class LatestPactDecorator < PactDetailsDecorator
10
11
 
12
+ include Timestamps
13
+
11
14
  links :self do | options |
12
15
  [
13
16
  {
@@ -21,4 +24,4 @@ module PactBroker
21
24
  end
22
25
  end
23
26
  end
24
- end
27
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative 'base_decorator'
2
2
  require 'pact_broker/json'
3
+ require 'pact_broker/api/decorators/timestamps'
3
4
 
4
5
  module PactBroker
5
6
 
@@ -9,8 +10,7 @@ module PactBroker
9
10
 
10
11
  class PactDecorator < BaseDecorator
11
12
 
12
- property :createdAt, getter: lambda { |_| created_at.xmlschema }, writeable: false
13
- property :updatedAt, getter: lambda { |_| updated_at.xmlschema }, writeable: false
13
+ include Timestamps
14
14
 
15
15
  def to_hash(options = {})
16
16
  ::JSON.parse(represented.json_content, PACT_PARSING_OPTIONS).merge super
@@ -1,5 +1,6 @@
1
1
  require_relative 'base_decorator'
2
2
  require_relative 'pact_pacticipant_decorator'
3
+ require 'pact_broker/api/decorators/timestamps'
3
4
 
4
5
  module PactBroker
5
6
 
@@ -18,16 +19,14 @@ module PactBroker
18
19
 
19
20
  class PactVersionDecorator < BaseDecorator
20
21
 
21
-
22
- property :createdAt, getter: lambda { |_| created_at.to_time.localtime.xmlschema }, writeable: false
23
- property :updatedAt, getter: lambda { |_| updated_at.to_time.localtime.xmlschema }, writeable: false
22
+ include Timestamps
24
23
 
25
24
  property :consumer_version, as: :consumerVersion, embedded: true, decorator: EmbeddedVersionDecorator
26
25
 
27
26
 
28
27
  link :self do | options |
29
28
  {
30
- href: pact_url(options.base_url, represented),
29
+ href: pact_url(options[:base_url], represented),
31
30
  title: represented.name
32
31
  }
33
32
 
@@ -14,21 +14,21 @@ module PactBroker
14
14
 
15
15
  link :self do | context |
16
16
  {
17
- href: context.resource_url,
17
+ href: context[:resource_url],
18
18
  title: "All versions of the pact between #{context[:consumer_name]} and #{context[:provider_name]}"
19
19
  }
20
20
  end
21
21
 
22
22
  link :consumer do | context |
23
23
  {
24
- href: pacticipant_url(context.base_url, OpenStruct.new(name: context[:consumer_name])),
24
+ href: pacticipant_url(context[:base_url], OpenStruct.new(name: context[:consumer_name])),
25
25
  title: context[:consumer_name]
26
26
  }
27
27
  end
28
28
 
29
29
  link :provider do | context |
30
30
  {
31
- href: pacticipant_url(context.base_url, OpenStruct.new(name: context[:provider_name])),
31
+ href: pacticipant_url(context[:base_url], OpenStruct.new(name: context[:provider_name])),
32
32
  title: context[:provider_name]
33
33
  }
34
34
  end
@@ -36,7 +36,7 @@ module PactBroker
36
36
  links :'pact-versions' do | context |
37
37
  represented.collect do | pact |
38
38
  {
39
- :href => pact_url(context.base_url, pact),
39
+ :href => pact_url(context[:base_url], pact),
40
40
  :title => pact.version_and_updated_date
41
41
  }
42
42
  end
@@ -1,5 +1,6 @@
1
1
  require_relative 'base_decorator'
2
2
  require_relative 'version_decorator'
3
+ require 'pact_broker/api/decorators/timestamps'
3
4
 
4
5
  module PactBroker
5
6
 
@@ -13,8 +14,8 @@ module PactBroker
13
14
  property :repository_url, as: :repositoryUrl
14
15
 
15
16
  property :latest_version, as: :'latest-version', :class => PactBroker::Models::Version, :extend => PactBroker::Api::Decorators::VersionRepresenter, :embedded => true, writeable: false
16
- property :createdAt, getter: lambda { |_| created_at.xmlschema }, writeable: false
17
- property :updatedAt, getter: lambda { |_| updated_at.xmlschema }, writeable: false
17
+
18
+ include Timestamps
18
19
 
19
20
  link :self do | options |
20
21
  pacticipant_url(options[:base_url], represented)
@@ -1,5 +1,6 @@
1
1
  require_relative 'base_decorator'
2
2
  require_relative 'pact_pacticipant_decorator'
3
+ require_relative 'timestamps'
3
4
 
4
5
  module PactBroker
5
6
 
@@ -9,8 +10,7 @@ module PactBroker
9
10
 
10
11
  class TagDecorator < BaseDecorator
11
12
 
12
- property :createdAt, getter: lambda { |_| created_at ? created_at.xmlschema : nil }
13
- property :updatedAt, getter: lambda { |_| updated_at ? updated_at.xmlschema : nil }
13
+ include Timestamps
14
14
 
15
15
  link :self do | options |
16
16
  tag_url(options[:base_url], represented)
@@ -0,0 +1,24 @@
1
+ require 'roar/representer/json'
2
+
3
+ module PactBroker
4
+
5
+ module Api
6
+
7
+ module Decorators
8
+
9
+ module Timestamps
10
+
11
+ include Roar::Representer::JSON
12
+
13
+ property :optional_updated_at, as: :updatedAt, exec_context: :decorator, writeable: false
14
+ property :createdAt, getter: lambda { |_| created_at.xmlschema }, writeable: false
15
+
16
+ def optional_updated_at
17
+ if represented.updated_at != represented.created_at
18
+ represented.updated_at.xmlschema
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative 'base_decorator'
2
2
  require 'pact_broker/api/decorators/webhook_request_decorator'
3
+ require 'pact_broker/api/decorators/timestamps'
3
4
  require 'pact_broker/models/webhook_request'
4
5
  require 'pact_broker/api/decorators/basic_pacticipant_decorator'
5
6
 
@@ -10,8 +11,7 @@ module PactBroker
10
11
 
11
12
  property :request, :class => PactBroker::Models::WebhookRequest, :extend => WebhookRequestDecorator
12
13
 
13
- property :createdAt, getter: lambda { |_| created_at.xmlschema }, writeable: false
14
- property :updatedAt, getter: lambda { |_| updated_at.xmlschema }, writeable: false
14
+ include Timestamps
15
15
 
16
16
  property :consumer, :extend => PactBroker::Api::Decorators::BasicPacticipantRepresenter, :embedded => true, writeable: false
17
17
  property :provider, :extend => PactBroker::Api::Decorators::BasicPacticipantRepresenter, :embedded => true, writeable: false
@@ -9,8 +9,8 @@ module PactBroker
9
9
 
10
10
  link :'pb:self' do | context |
11
11
  {
12
- title: context.resource_title,
13
- href: context.resource_url
12
+ title: context[:resource_title],
13
+ href: context[:resource_url]
14
14
  }
15
15
  end
16
16
 
@@ -19,7 +19,7 @@ module PactBroker
19
19
  {
20
20
  title: webhook.description,
21
21
  name: webhook.request_description,
22
- href: webhook_url(webhook.uuid, context.base_url)
22
+ href: webhook_url(webhook.uuid, context[:base_url])
23
23
  }
24
24
  end
25
25
  end
@@ -27,7 +27,7 @@ module PactBroker
27
27
  curies do | context |
28
28
  [{
29
29
  name: :pb,
30
- href: context.base_url + '/doc/webhooks',
30
+ href: context[:base_url] + '/doc/webhooks',
31
31
  }]
32
32
  end
33
33
 
@@ -19,14 +19,22 @@ module PactBroker
19
19
  end
20
20
 
21
21
  def call
22
- "<html><head>#{head}</head><body>#{pact_metadata}#{html}</body></html>"
22
+ "<html>
23
+ <head>#{head}</head>
24
+ <body>
25
+ #{pact_metadata}#{html}
26
+ </body>
27
+ </html>"
23
28
  end
24
29
 
25
30
  private
26
31
 
27
32
  def head
28
- '<link rel="stylesheet" type="text/css" href="/stylesheets/github.css">' + "\n" +
29
- '<link rel="stylesheet" type="text/css" href="/stylesheets/pact.css">'
33
+ "<link rel='stylesheet' type='text/css' href='/stylesheets/github.css'>
34
+ <link rel='stylesheet' type='text/css' href='/stylesheets/pact.css'>
35
+ <link rel='stylesheet' type='text/css' href='/stylesheets/github-json.css'>
36
+ <script src='/javascripts/highlight.pack.js'></script>
37
+ <script>hljs.initHighlightingOnLoad();</script>"
30
38
  end
31
39
 
32
40
  def pact_metadata
@@ -38,7 +46,7 @@ module PactBroker
38
46
  </li>
39
47
  <li>
40
48
  <span class='name'>Date published:</span>
41
- <span class='value'>#{@pact.updated_at.to_time.localtime.to_datetime.strftime("%d/%m/%Y %l:%M%p %:z")}</span>
49
+ <span class='value'>#{published_date}</span>
42
50
  </li>
43
51
  <li>
44
52
  <a href=\"#{json_url}\">View in HAL Browser</a>
@@ -47,6 +55,10 @@ module PactBroker
47
55
  </div>"
48
56
  end
49
57
 
58
+ def published_date
59
+ @pact.updated_at.to_time.localtime.to_datetime.strftime("%d/%m/%Y %l:%M%p %:z")
60
+ end
61
+
50
62
  def json_url
51
63
  PactBroker::Api::PactBrokerUrls.hal_browser_url pact_url
52
64
  end
@@ -36,7 +36,6 @@ module PactBroker
36
36
  end
37
37
  end
38
38
 
39
- # This should be called base_url
40
39
  def base_url
41
40
  request.uri.to_s.gsub(/#{request.uri.path}$/,'')
42
41
  end
@@ -16,21 +16,26 @@ module PactBroker
16
16
  ["GET"]
17
17
  end
18
18
 
19
- def to_csv
20
- generate_csv(group_service.find_group_containing @pacticipant)
19
+ def resource_exists?
20
+ pacticipant
21
21
  end
22
22
 
23
- def generate_csv group
23
+ def to_csv
24
24
  PactBroker::Api::Decorators::RelationshipsCsvDecorator.new(group).to_csv
25
25
  end
26
26
 
27
+ private
28
+
27
29
  def pacticipant_name
28
30
  identifier_from_path[:pacticipant_name]
29
31
  end
30
32
 
31
- def resource_exists?
32
- @pacticipant = pacticipant_service.find_pacticipant_by_name(pacticipant_name)
33
- @pacticipant != nil
33
+ def pacticipant
34
+ @pacticipant ||= pacticipant_service.find_pacticipant_by_name(pacticipant_name)
35
+ end
36
+
37
+ def group
38
+ @group ||= group_service.find_group_containing pacticipant
34
39
  end
35
40
 
36
41
  end
@@ -15,37 +15,36 @@ module PactBroker
15
15
  ["GET"]
16
16
  end
17
17
 
18
- # TODO change to use request.base_url to avoid params getting included!!!
19
18
  def to_json
20
19
  {
21
20
  _links: {
22
21
  'pb:self' =>
23
22
  {
24
- href: request.uri.to_s,
23
+ href: base_url,
25
24
  title: 'The Pact Broker index page',
26
25
  templated: false
27
26
  },
28
27
  'pb:latest-pacts' =>
29
28
  {
30
- href: request.uri.to_s + 'pacts/latest',
29
+ href: base_url + '/pacts/latest',
31
30
  title: 'Retrieve latest pacts',
32
31
  templated: false
33
32
  },
34
33
  'pb:pacticipants' =>
35
34
  {
36
- href: request.uri.to_s + 'pacticipants',
35
+ href: base_url + '/pacticipants',
37
36
  title: 'Retrieve pacticipants',
38
37
  templated: false
39
38
  },
40
39
  'pb:webhooks' =>
41
40
  {
42
- href: request.uri.to_s + 'webhooks',
41
+ href: base_url + '/webhooks',
43
42
  title: 'Webhooks',
44
43
  templated: false
45
44
  },'curies' =>
46
45
  [{
47
46
  name: 'pb',
48
- href: request.uri.to_s + 'doc/{rel}',
47
+ href: base_url + '/doc/{rel}',
49
48
  templated: true
50
49
  }]
51
50
  }