-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
271 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require_relative "base_decorator" | ||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
class NoticesDecorator < BaseDecorator | ||
property :entries, as: :notices, getter: ->(represented:, **) { represented.collect(&:to_h) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "pact_broker/async/after_reply" | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
module AfterReply | ||
|
||
# @param [Callable] block the block to execute after the response has been sent to the user. | ||
def after_reply(&block) | ||
PactBroker::Async::AfterReply.new(request.env).execute(&block) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Saves a block for execution after the HTTP response has been sent to the user. | ||
# When the block is executed, it connects to the database before executing the code. | ||
# This is good for doing things that might take a while and don't have to be done before | ||
# the response is sent, and don't need retries (in which case, it might be better to use a SuckerPunch Job). | ||
# | ||
# This leverages a feature of Puma which I'm not sure is meant to be public or not. | ||
# There are serveral mentions of it on the internet, so I assume it's ok to use it. | ||
# Puma itself uses the rack.after_reply for http request logging. | ||
# | ||
# https://github.com/search?q=repo%3Apuma%2Fpuma%20rack.after_reply&type=code | ||
|
||
module PactBroker | ||
module Async | ||
class AfterReply | ||
def initialize(rack_env) | ||
@rack_env = rack_env | ||
@database_connector = rack_env.fetch("pactbroker.database_connector") | ||
end | ||
|
||
def execute(&block) | ||
dc = @database_connector | ||
@rack_env["rack.after_reply"] << lambda { | ||
dc.call do | ||
block.call | ||
end | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
describe "Delete pacticipant branches" do | ||
before do | ||
td.create_consumer("Bar") | ||
.create_consumer_version("1", branch: "main") | ||
.create_consumer("Foo", main_branch: "main") | ||
.create_consumer_version("1", branch: "main") | ||
.create_consumer_version("2", branch: "feat/bar") | ||
.create_consumer_version("3", branch: "feat/foo") | ||
end | ||
let(:path) { PactBroker::Api::PactBrokerUrls.pacticipant_branches_url(td.and_return(:pacticipant)) } | ||
let(:rack_env) do | ||
{ | ||
"pactbroker.database_connector" => lambda { |&block| block.call } | ||
} | ||
end | ||
|
||
subject { delete(path + "?exclude[]=feat%2Fbar", nil, rack_env) } | ||
|
||
its(:status) { is_expected.to eq 202 } | ||
|
||
it "returns a list of notices to be displayed to the user" do | ||
expect(JSON.parse(subject.body)["notices"]).to be_instance_of(Array) | ||
expect(JSON.parse(subject.body)["notices"]).to include(hash_including("text")) | ||
end | ||
|
||
it "after the request, it deletes all except the excluded branches for a pacticipant" do | ||
expect { subject }.to change { | ||
PactBroker::Versions::Branch | ||
.where(pacticipant_id: td.and_return(:pacticipant).id) | ||
.all | ||
.collect(&:name) | ||
.sort | ||
}.from(["feat/bar", "feat/foo", "main"]).to(["feat/bar", "main"]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Mock out the rack.after_reply functionality provided by Puma | ||
# I'm not sure if this is meant to be a public feature or not, but | ||
# there are several mentions of it on the net, so I assume it's ok to use it. | ||
# Puma itself uses the rack.after_reply for http request logging. | ||
# | ||
# See https://github.com/puma/puma/search?q=rack.after_reply | ||
# This middleware executes the hooks that would normally run after the request | ||
# *before* the request ends, for the purposes of testing. | ||
|
||
module PactBroker | ||
module Middleware | ||
class MockPuma | ||
|
||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
after_reply = [] | ||
response = @app.call({ "rack.after_reply" => after_reply }.merge(env)) | ||
after_reply.each(&:call) | ||
response | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters