From 09cdcc58bdd07222c9a10c44a1a0013b5e49c4c5 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 9 Sep 2020 15:43:53 +1000 Subject: [PATCH] chore: update policy names --- lib/pact_broker/api/resources/all_webhooks.rb | 5 ----- lib/pact_broker/api/resources/can_i_deploy.rb | 4 ---- .../api/resources/default_base_resource.rb | 9 +++++++++ lib/pact_broker/api/resources/error_test.rb | 6 ++++-- lib/pact_broker/api/resources/group.rb | 4 ---- lib/pact_broker/api/resources/integration.rb | 4 ---- lib/pact_broker/api/resources/integrations.rb | 4 ---- lib/pact_broker/api/resources/label.rb | 8 -------- lib/pact_broker/api/resources/latest_pact.rb | 6 +----- lib/pact_broker/api/resources/latest_pacts.rb | 6 +----- ...atest_verifications_for_consumer_version.rb | 4 ---- lib/pact_broker/api/resources/matrix.rb | 4 ++++ .../matrix_for_consumer_and_provider.rb | 4 ++++ lib/pact_broker/api/resources/metrics.rb | 4 ++++ lib/pact_broker/api/resources/pact.rb | 12 ++++-------- .../api/resources/pact_content_diff.rb | 4 ++++ .../api/resources/pact_triggered_webhooks.rb | 6 +++++- lib/pact_broker/api/resources/pact_versions.rb | 6 +++++- lib/pact_broker/api/resources/pact_webhooks.rb | 6 +++++- .../api/resources/pact_webhooks_status.rb | 6 +++++- lib/pact_broker/api/resources/pacticipant.rb | 14 +++++--------- lib/pact_broker/api/resources/pacticipants.rb | 4 ---- .../api/resources/pacticipants_for_label.rb | 4 ++++ .../previous_distinct_pact_version.rb | 13 ++++--------- .../api/resources/provider_pacts.rb | 6 +----- lib/pact_broker/api/resources/relationships.rb | 6 ++++-- lib/pact_broker/api/resources/tag.rb | 10 +++++----- .../api/resources/tagged_pact_versions.rb | 7 +++++-- .../api/resources/triggered_webhook_logs.rb | 12 +++++++----- lib/pact_broker/api/resources/verification.rb | 10 +++++----- .../verification_triggered_webhooks.rb | 18 ++++++------------ lib/pact_broker/api/resources/verifications.rb | 10 +++++----- lib/pact_broker/api/resources/version.rb | 10 +++++----- lib/pact_broker/api/resources/versions.rb | 7 +++++-- lib/pact_broker/api/resources/webhook.rb | 4 ++++ .../api/resources/webhook_execution.rb | 4 ++++ lib/pact_broker/api/resources/webhooks.rb | 6 +++++- .../resources/default_base_resource_spec.rb | 16 +++++++++++----- .../verification_triggered_webhooks_spec.rb | 1 - 39 files changed, 140 insertions(+), 134 deletions(-) diff --git a/lib/pact_broker/api/resources/all_webhooks.rb b/lib/pact_broker/api/resources/all_webhooks.rb index 62d6918ce..10b8504d0 100644 --- a/lib/pact_broker/api/resources/all_webhooks.rb +++ b/lib/pact_broker/api/resources/all_webhooks.rb @@ -49,11 +49,6 @@ def policy_name :'webhooks::webooks' end - def policy_record - # Note: consumer and provider not yet set on new webhook - request.post? ? webhook : webhooks - end - private def validation_errors? webhook diff --git a/lib/pact_broker/api/resources/can_i_deploy.rb b/lib/pact_broker/api/resources/can_i_deploy.rb index 1288b0ff6..511aea209 100644 --- a/lib/pact_broker/api/resources/can_i_deploy.rb +++ b/lib/pact_broker/api/resources/can_i_deploy.rb @@ -25,10 +25,6 @@ def policy_name :'matrix::can_i_deploy' end - def policy_record - selectors - end - private attr_reader :query_params, :selectors, :options diff --git a/lib/pact_broker/api/resources/default_base_resource.rb b/lib/pact_broker/api/resources/default_base_resource.rb index b393e3764..8bc146a32 100644 --- a/lib/pact_broker/api/resources/default_base_resource.rb +++ b/lib/pact_broker/api/resources/default_base_resource.rb @@ -202,6 +202,15 @@ def pact @pact ||= pact_service.find_pact(pact_params) end + # Not necessarily an existing integration + def integration + if consumer_specified? && provider_specified? + OpenStruct.new(consumer: consumer, provider: provider) + else + nil + end + end + def database_connector request.env["pactbroker.database_connector"] end diff --git a/lib/pact_broker/api/resources/error_test.rb b/lib/pact_broker/api/resources/error_test.rb index d64e2e0f9..7c5eb7e47 100644 --- a/lib/pact_broker/api/resources/error_test.rb +++ b/lib/pact_broker/api/resources/error_test.rb @@ -4,9 +4,7 @@ module PactBroker module Api module Resources - class ErrorTest < BaseResource - def content_types_provided [ ["application/hal+json", :to_json] @@ -24,6 +22,10 @@ def to_json def process_post raise PactBroker::TestError.new("Don't panic. This is a test API error.") end + + def policy_name + :'default' + end end end end diff --git a/lib/pact_broker/api/resources/group.rb b/lib/pact_broker/api/resources/group.rb index b63267204..e0725c59d 100644 --- a/lib/pact_broker/api/resources/group.rb +++ b/lib/pact_broker/api/resources/group.rb @@ -26,10 +26,6 @@ def policy_name :'groups::group' end - def policy_record - pacticipant - end - private def group diff --git a/lib/pact_broker/api/resources/integration.rb b/lib/pact_broker/api/resources/integration.rb index 353741b7a..0ee5bef69 100644 --- a/lib/pact_broker/api/resources/integration.rb +++ b/lib/pact_broker/api/resources/integration.rb @@ -21,10 +21,6 @@ def policy_name :'integrations::integration' end - def policy_resource - integration - end - def integration @integration ||= OpenStruct.new(consumer: consumer, provider: provider) end diff --git a/lib/pact_broker/api/resources/integrations.rb b/lib/pact_broker/api/resources/integrations.rb index 0218b4024..36376e6d7 100644 --- a/lib/pact_broker/api/resources/integrations.rb +++ b/lib/pact_broker/api/resources/integrations.rb @@ -37,10 +37,6 @@ def delete_resource def policy_name :'integrations::integrations' end - - def policy_resource - integrations - end end end end diff --git a/lib/pact_broker/api/resources/label.rb b/lib/pact_broker/api/resources/label.rb index 2d28d8e9c..2f7caa190 100644 --- a/lib/pact_broker/api/resources/label.rb +++ b/lib/pact_broker/api/resources/label.rb @@ -30,18 +30,10 @@ def resource_exists? !!label end - def resource_object - label - end - def policy_name :'labels::label' end - def policy_record - label - end - def to_json PactBroker::Api::Decorators::LabelDecorator.new(label).to_json(decorator_options) end diff --git a/lib/pact_broker/api/resources/latest_pact.rb b/lib/pact_broker/api/resources/latest_pact.rb index 7a9362823..a670afc04 100644 --- a/lib/pact_broker/api/resources/latest_pact.rb +++ b/lib/pact_broker/api/resources/latest_pact.rb @@ -25,11 +25,7 @@ def resource_exists? end def policy_name - :'pacts:pact' - end - - def policy_record - pact + :'pacts::pact' end def to_json diff --git a/lib/pact_broker/api/resources/latest_pacts.rb b/lib/pact_broker/api/resources/latest_pacts.rb index 30b33ed4b..b3848ada0 100644 --- a/lib/pact_broker/api/resources/latest_pacts.rb +++ b/lib/pact_broker/api/resources/latest_pacts.rb @@ -22,11 +22,7 @@ def pacts end def policy_name - :'pacts:pacts' - end - - def policy_record - pacts + :'pacts::pacts' end end end diff --git a/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb b/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb index 213800b21..366cb6eb7 100644 --- a/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +++ b/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb @@ -30,10 +30,6 @@ def policy_name :'verifications::verifications' end - def policy_record - version - end - private def version diff --git a/lib/pact_broker/api/resources/matrix.rb b/lib/pact_broker/api/resources/matrix.rb index 602af0a4a..bc513eb09 100644 --- a/lib/pact_broker/api/resources/matrix.rb +++ b/lib/pact_broker/api/resources/matrix.rb @@ -43,6 +43,10 @@ def to_text PactBroker::Api::Decorators::MatrixTextDecorator.new(results).to_text(decorator_options) end + def policy_name + :'matrix::matrix' + end + def results @results ||= matrix_service.find(selectors, options) end diff --git a/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb b/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb index 535db3671..d2a085500 100644 --- a/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +++ b/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb @@ -27,6 +27,10 @@ def to_json PactBroker::Api::Decorators::MatrixDecorator.new(results).to_json(decorator_options) end + def policy_name + :'matrix::matrix' + end + private attr_reader :options diff --git a/lib/pact_broker/api/resources/metrics.rb b/lib/pact_broker/api/resources/metrics.rb index 59e97f580..b3584d8f7 100644 --- a/lib/pact_broker/api/resources/metrics.rb +++ b/lib/pact_broker/api/resources/metrics.rb @@ -15,6 +15,10 @@ def allowed_methods def to_json metrics_service.metrics.to_json end + + def policy_name + :'metrics::metrics' + end end end end diff --git a/lib/pact_broker/api/resources/pact.rb b/lib/pact_broker/api/resources/pact.rb index ee9499916..c87f1980e 100644 --- a/lib/pact_broker/api/resources/pact.rb +++ b/lib/pact_broker/api/resources/pact.rb @@ -53,14 +53,6 @@ def resource_exists? !!pact end - def resource_object - pact - end - - def policy_resource - pact - end - def from_json response_code = pact ? 200 : 201 @@ -96,6 +88,10 @@ def delete_resource true end + def policy_name + :'pacts::pact' + end + private def pact diff --git a/lib/pact_broker/api/resources/pact_content_diff.rb b/lib/pact_broker/api/resources/pact_content_diff.rb index c2b2788a4..a3e2b4d5b 100644 --- a/lib/pact_broker/api/resources/pact_content_diff.rb +++ b/lib/pact_broker/api/resources/pact_content_diff.rb @@ -31,6 +31,10 @@ def pact_params @pact_params ||= PactBroker::Pacts::PactParams.from_path_info identifier_from_path end + def policy_name + :'pacts::pact' + end + def comparison_pact_params if identifier_from_path[:comparison_consumer_version_number] || identifier_from_path[:comparison_pact_version_sha] comparison_identifier_from_path = identifier_from_path.merge( diff --git a/lib/pact_broker/api/resources/pact_triggered_webhooks.rb b/lib/pact_broker/api/resources/pact_triggered_webhooks.rb index 0b1420307..3afc45579 100644 --- a/lib/pact_broker/api/resources/pact_triggered_webhooks.rb +++ b/lib/pact_broker/api/resources/pact_triggered_webhooks.rb @@ -21,10 +21,14 @@ def to_json Decorators::TriggeredWebhooksDecorator.new(triggered_webhooks).to_json(decorator_options(resource_title: resource_title)) end + def policy_name + :'webhooks::webhooks' + end + private def triggered_webhooks - webhook_service.find_triggered_webhooks_for_pact(pact) + @webhooks ||= webhook_service.find_triggered_webhooks_for_pact(pact) end def resource_title diff --git a/lib/pact_broker/api/resources/pact_versions.rb b/lib/pact_broker/api/resources/pact_versions.rb index f9182d82f..de734d520 100644 --- a/lib/pact_broker/api/resources/pact_versions.rb +++ b/lib/pact_broker/api/resources/pact_versions.rb @@ -23,13 +23,17 @@ def to_json end def pacts - pact_service.find_all_pact_versions_between consumer_name, :and => provider_name + @pacts ||= pact_service.find_all_pact_versions_between consumer_name, :and => provider_name end def delete_resource pact_service.delete_all_pact_publications_between(consumer_name, and: provider_name) true end + + def policy_name + :'pacts::pacts' + end end end end diff --git a/lib/pact_broker/api/resources/pact_webhooks.rb b/lib/pact_broker/api/resources/pact_webhooks.rb index da7b952d1..1e0acd80e 100644 --- a/lib/pact_broker/api/resources/pact_webhooks.rb +++ b/lib/pact_broker/api/resources/pact_webhooks.rb @@ -59,10 +59,14 @@ def to_json Decorators::WebhooksDecorator.new(webhooks).to_json(user_options: decorator_context(resource_title: 'Pact webhooks')) end + def policy_name + :'webhooks::webhooks' + end + private def webhooks - webhook_service.find_by_consumer_and_provider consumer, provider + @webhooks ||= webhook_service.find_by_consumer_and_provider consumer, provider end def webhook diff --git a/lib/pact_broker/api/resources/pact_webhooks_status.rb b/lib/pact_broker/api/resources/pact_webhooks_status.rb index dfd64ef89..875c38391 100644 --- a/lib/pact_broker/api/resources/pact_webhooks_status.rb +++ b/lib/pact_broker/api/resources/pact_webhooks_status.rb @@ -22,6 +22,10 @@ def to_json decorator_for(latest_triggered_webhooks).to_json(user_options: decorator_context(identifier_from_path)) end + def policy_name + :'webhooks::webhooks' + end + private def latest_triggered_webhooks @@ -33,7 +37,7 @@ def pact end def webhooks - webhook_service.find_by_consumer_and_provider(consumer, provider) + @webhooks ||= webhook_service.find_by_consumer_and_provider(consumer, provider) end def decorator_for latest_triggered_webhooks diff --git a/lib/pact_broker/api/resources/pacticipant.rb b/lib/pact_broker/api/resources/pacticipant.rb index c88c88f8e..949d05656 100644 --- a/lib/pact_broker/api/resources/pacticipant.rb +++ b/lib/pact_broker/api/resources/pacticipant.rb @@ -40,15 +40,7 @@ def from_json end def resource_exists? - !!resource_object - end - - def resource_object - pacticipant - end - - def policy_resource - pacticipant + !!pacticipant end def delete_resource @@ -59,6 +51,10 @@ def delete_resource def to_json PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).to_json(decorator_options) end + + def policy_name + :'pacticipants::pacticipant' + end end end end diff --git a/lib/pact_broker/api/resources/pacticipants.rb b/lib/pact_broker/api/resources/pacticipants.rb index 867b090fa..20aa2f525 100644 --- a/lib/pact_broker/api/resources/pacticipants.rb +++ b/lib/pact_broker/api/resources/pacticipants.rb @@ -61,10 +61,6 @@ def policy_name :'pacticipants::pacticipants' end - def policy_record - request.post? ? nil : pacticipants - end - private def pacticipants diff --git a/lib/pact_broker/api/resources/pacticipants_for_label.rb b/lib/pact_broker/api/resources/pacticipants_for_label.rb index f735b949f..1e0088935 100644 --- a/lib/pact_broker/api/resources/pacticipants_for_label.rb +++ b/lib/pact_broker/api/resources/pacticipants_for_label.rb @@ -21,6 +21,10 @@ def to_json def generate_json pacticipants PactBroker::Api::Decorators::PacticipantCollectionDecorator.new(pacticipants).to_json(decorator_options) end + + def policy_name + :'pacticipants::pacticipants' + end end end end diff --git a/lib/pact_broker/api/resources/previous_distinct_pact_version.rb b/lib/pact_broker/api/resources/previous_distinct_pact_version.rb index 8edcfa339..5d52d9399 100644 --- a/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +++ b/lib/pact_broker/api/resources/previous_distinct_pact_version.rb @@ -17,15 +17,7 @@ def allowed_methods end def resource_exists? - !!resource_object - end - - def resource_object - pact - end - - def policy_resource - pact + !!pact end def to_json @@ -40,6 +32,9 @@ def pact_params @pact_params ||= PactBroker::Pacts::PactParams.from_request request, path_info end + def policy_name + :'pacts::pact' + end end end end diff --git a/lib/pact_broker/api/resources/provider_pacts.rb b/lib/pact_broker/api/resources/provider_pacts.rb index 8b6c66f75..f90cb3bad 100644 --- a/lib/pact_broker/api/resources/provider_pacts.rb +++ b/lib/pact_broker/api/resources/provider_pacts.rb @@ -20,11 +20,7 @@ def resource_exists? end def policy_name - :'pacts:provider_pacts' - end - - def policy_record - provider + :'pacts::pacts' end def to_json diff --git a/lib/pact_broker/api/resources/relationships.rb b/lib/pact_broker/api/resources/relationships.rb index 2ea25600f..faa221376 100644 --- a/lib/pact_broker/api/resources/relationships.rb +++ b/lib/pact_broker/api/resources/relationships.rb @@ -4,9 +4,7 @@ module PactBroker module Api module Resources - class Relationships < BaseResource - def content_types_provided [["text/csv", :to_csv]] end @@ -22,6 +20,10 @@ def to_csv def pacts pact_service.find_latest_pacts end + + def policy_name + :'integrations::integrations' + end end end end diff --git a/lib/pact_broker/api/resources/tag.rb b/lib/pact_broker/api/resources/tag.rb index fa38573bb..cd62bbfbb 100644 --- a/lib/pact_broker/api/resources/tag.rb +++ b/lib/pact_broker/api/resources/tag.rb @@ -27,11 +27,7 @@ def from_json end def resource_exists? - !!resource_object - end - - def resource_object - tag + !!tag end def to_json @@ -46,6 +42,10 @@ def delete_resource tag_service.delete identifier_from_path true end + + def policy_name + :'tags::tag' + end end end diff --git a/lib/pact_broker/api/resources/tagged_pact_versions.rb b/lib/pact_broker/api/resources/tagged_pact_versions.rb index 9d8ede626..2e20683f0 100644 --- a/lib/pact_broker/api/resources/tagged_pact_versions.rb +++ b/lib/pact_broker/api/resources/tagged_pact_versions.rb @@ -6,7 +6,6 @@ module PactBroker module Api module Resources class TaggedPactVersions < BaseResource - def content_types_provided [["application/hal+json", :to_json]] end @@ -29,7 +28,11 @@ def delete_resource end def pacts - pact_service.find_all_pact_versions_between consumer_name, and: provider_name, tag: identifier_from_path[:tag] + @pacts ||= pact_service.find_all_pact_versions_between consumer_name, and: provider_name, tag: identifier_from_path[:tag] + end + + def policy_name + :'pact::pacts' end end end diff --git a/lib/pact_broker/api/resources/triggered_webhook_logs.rb b/lib/pact_broker/api/resources/triggered_webhook_logs.rb index eacce5153..e0cd9aa8a 100644 --- a/lib/pact_broker/api/resources/triggered_webhook_logs.rb +++ b/lib/pact_broker/api/resources/triggered_webhook_logs.rb @@ -16,11 +16,7 @@ def allowed_methods end def resource_exists? - !!resource_object - end - - def resource_object - triggered_webhook + !!triggered_webhook end def to_text @@ -28,6 +24,12 @@ def to_text triggered_webhook.webhook_executions.collect(&:logs).join("\n") end + def policy_name + :'webhook::webhook' + end + + private + def triggered_webhook @triggered_webhook ||= begin criteria = { webhook_uuid: identifier_from_path[:uuid], trigger_uuid: identifier_from_path[:trigger_uuid] } diff --git a/lib/pact_broker/api/resources/verification.rb b/lib/pact_broker/api/resources/verification.rb index d036dd386..f6032a93e 100644 --- a/lib/pact_broker/api/resources/verification.rb +++ b/lib/pact_broker/api/resources/verification.rb @@ -28,14 +28,10 @@ def resource_exists? set_json_error_message("To see all the verifications for a pact, use the Matrix page") false else - !!resource_object + !!verification end end - def resource_object - verification - end - def to_json decorator_for(verification).to_json(decorator_options) end @@ -49,6 +45,10 @@ def delete_resource true end + def policy_name + :'verifications::verification' + end + private def verification diff --git a/lib/pact_broker/api/resources/verification_triggered_webhooks.rb b/lib/pact_broker/api/resources/verification_triggered_webhooks.rb index 8391cd208..2f4ccc8ff 100644 --- a/lib/pact_broker/api/resources/verification_triggered_webhooks.rb +++ b/lib/pact_broker/api/resources/verification_triggered_webhooks.rb @@ -14,33 +14,27 @@ def content_types_provided end def resource_exists? - !!resource_object + !!verification end - def resource_object - verification + def to_json + Decorators::TriggeredWebhooksDecorator.new(triggered_webhooks).to_json(decorator_options(resource_title: resource_title)) end - def to_json - Decorators::TriggeredWebhooksDecorator.new(triggered_webhooks).to_json(decorator_options) + def policy_name + :'webhooks::triggered_webhooks' end private def triggered_webhooks - webhook_service.find_triggered_webhooks_for_verification(verification) + @triggered_webhooks ||= webhook_service.find_triggered_webhooks_for_verification(verification) end def resource_title "Webhooks triggered by the publication of verification result #{verification.number}" end - def decorator_options - { - user_options: decorator_context.merge(resource_title: resource_title) - } - end - def verification @verification ||= verification_service.find(identifier_from_path) end diff --git a/lib/pact_broker/api/resources/verifications.rb b/lib/pact_broker/api/resources/verifications.rb index 8c50d8ae8..0f4519d7a 100644 --- a/lib/pact_broker/api/resources/verifications.rb +++ b/lib/pact_broker/api/resources/verifications.rb @@ -28,11 +28,7 @@ def post_is_create? end def resource_exists? - !!resource_object - end - - def resource_object - pact + !!pact end def malformed_request? @@ -57,6 +53,10 @@ def from_json true end + def policy_name + :'verifications::verifications' + end + private def pact diff --git a/lib/pact_broker/api/resources/version.rb b/lib/pact_broker/api/resources/version.rb index 58fb3e627..79f8f173c 100644 --- a/lib/pact_broker/api/resources/version.rb +++ b/lib/pact_broker/api/resources/version.rb @@ -16,11 +16,7 @@ def allowed_methods end def resource_exists? - !!resource_object - end - - def resource_object - version + !!version end def to_json @@ -32,6 +28,10 @@ def delete_resource true end + def policy_name + :'versions::version' + end + private def version diff --git a/lib/pact_broker/api/resources/versions.rb b/lib/pact_broker/api/resources/versions.rb index 4e8df17db..6736593b8 100644 --- a/lib/pact_broker/api/resources/versions.rb +++ b/lib/pact_broker/api/resources/versions.rb @@ -6,7 +6,6 @@ module PactBroker module Api module Resources class Versions < BaseResource - def content_types_provided [["application/hal+json", :to_json]] end @@ -24,7 +23,11 @@ def to_json end def versions - pacticipant_service.find_all_pacticipant_versions_in_reverse_order pacticipant_name + @versions ||= pacticipant_service.find_all_pacticipant_versions_in_reverse_order pacticipant_name + end + + def policy_name + :'versions::versions' end end end diff --git a/lib/pact_broker/api/resources/webhook.rb b/lib/pact_broker/api/resources/webhook.rb index 253231b1e..d35d3d322 100644 --- a/lib/pact_broker/api/resources/webhook.rb +++ b/lib/pact_broker/api/resources/webhook.rb @@ -57,6 +57,10 @@ def delete_resource true end + def policy_name + :'webhooks::webhook' + end + private def webhook diff --git a/lib/pact_broker/api/resources/webhook_execution.rb b/lib/pact_broker/api/resources/webhook_execution.rb index 657f4a22e..704cfaecf 100644 --- a/lib/pact_broker/api/resources/webhook_execution.rb +++ b/lib/pact_broker/api/resources/webhook_execution.rb @@ -48,6 +48,10 @@ def malformed_request? end end + def policy_name + :'webhooks::webhook' + end + private def post_response_body webhook_execution_result diff --git a/lib/pact_broker/api/resources/webhooks.rb b/lib/pact_broker/api/resources/webhooks.rb index 8f7bf3336..e046e4187 100644 --- a/lib/pact_broker/api/resources/webhooks.rb +++ b/lib/pact_broker/api/resources/webhooks.rb @@ -50,10 +50,14 @@ def to_json Decorators::WebhooksDecorator.new(webhooks).to_json(decorator_options(resource_title: 'Pact webhooks')) end + def policy_name + :'webhooks::webhooks' + end + private def webhooks - webhook_service.find_by_consumer_and_provider consumer, provider + webhook_service.find_by_consumer_and_provider(consumer, provider) end def webhook diff --git a/spec/lib/pact_broker/api/resources/default_base_resource_spec.rb b/spec/lib/pact_broker/api/resources/default_base_resource_spec.rb index 8ce39600e..f68802a42 100644 --- a/spec/lib/pact_broker/api/resources/default_base_resource_spec.rb +++ b/spec/lib/pact_broker/api/resources/default_base_resource_spec.rb @@ -133,23 +133,29 @@ module Resources .select { |klass| klass < DefaultBaseResource } .select { |klass| !klass.name.end_with?("BaseResource") } - ALL_RESOURCES.each do | resource | - describe resource do + ALL_RESOURCES.each do | resource_class | + describe resource_class do let(:request) { double('request', uri: URI("http://example.org")).as_null_object } let(:response) { double('response') } + let(:resource) { resource_class.new(request, response) } it "includes OPTIONS in the list of allowed_methods" do - expect(resource.new(request, response).allowed_methods).to include "OPTIONS" + expect(resource.allowed_methods).to include "OPTIONS" end it "calls super in its constructor" do expect(PactBroker.configuration.before_resource).to receive(:call) - resource.new(request, response) + resource end it "calls super in finish_request" do expect(PactBroker.configuration.after_resource).to receive(:call) - resource.new(request, response).finish_request + resource.finish_request + end + + it "has a policy_name method" do + expect(resource).to respond_to(:policy_name) + puts resource.policy_name end end end diff --git a/spec/lib/pact_broker/api/resources/verification_triggered_webhooks_spec.rb b/spec/lib/pact_broker/api/resources/verification_triggered_webhooks_spec.rb index 043168f73..aa7547364 100644 --- a/spec/lib/pact_broker/api/resources/verification_triggered_webhooks_spec.rb +++ b/spec/lib/pact_broker/api/resources/verification_triggered_webhooks_spec.rb @@ -34,7 +34,6 @@ module Resources end context "when the verification exists" do - it "finds the triggered webhooks for the verification" do expect(webhook_service).to receive(:find_triggered_webhooks_for_verification) subject