Skip to content

Commit

Permalink
fix: fix error raised when clean selectors include a selector with a …
Browse files Browse the repository at this point in the history
…max age and a selector with a max age and a branch

Closes: #579
  • Loading branch information
bethesque committed Feb 22, 2023
1 parent 51ef24b commit 53b171b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pact_broker/db/clean_incremental.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def versions_to_delete(columns = [:id])
end

def version_ids_to_keep
@version_ids_to_keep ||= keep.collect { |selector| PactBroker::Domain::Version.select(:id).for_selector(selector) }.reduce(&:union)
@version_ids_to_keep ||= keep.collect { |selector| PactBroker::Domain::Version.for_selector(selector).select(:id) }.reduce(&:union)
end

def current_counts
Expand Down
26 changes: 26 additions & 0 deletions spec/lib/pact_broker/db/clean_incremental_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "pact_broker/db/clean_incremental"
require "pact_broker/matrix/unresolved_selector"
require "timecop"

module PactBroker
module DB
Expand Down Expand Up @@ -130,6 +131,31 @@ def pact_publication_count_for(consumer_name, version_number)
expect { subject }.to change { PactBroker::Pacts::PactVersion.count }.by(-1)
end
end

context "when there is a selector with a branch and a max age, and a selector with a max age only" do
before do
Timecop.freeze(Date.today - 20) do
td.publish_pact(consumer_name: "Foo", provider_name: "Bar", consumer_version_number: "1", branch: "main")
td.publish_pact(consumer_name: "Foo", provider_name: "Bar", consumer_version_number: "2", branch: "feat/foo")
end
Timecop.freeze(Date.today - 10) do
td.publish_pact(consumer_name: "Foo", provider_name: "Bar", consumer_version_number: "3", branch: "main")
end
td.publish_pact(consumer_name: "Foo", provider_name: "Bar", consumer_version_number: "4", branch: "feat/foo")
end

let(:options) { { keep: [ { max_age: 5 }, { max_age: 15, branch: "main" } ] } }

it "applies the max age correctly by branch" do
expect { subject }.to change {
PactBroker::Domain::Version.join(:branch_versions, { version_id: :id })
.order(:order)
.select_map([:number, :branch_name])
}
.from([["1", "main"], ["2", "feat/foo"], ["3", "main"], ["4", "feat/foo"]])
.to([["3", "main"], ["4", "feat/foo"]])
end
end
end
end
end
Expand Down

0 comments on commit 53b171b

Please sign in to comment.