Skip to content

Commit

Permalink
Merge pull request #725 from pact-foundation/PACT-2478-add-scoping-fo…
Browse files Browse the repository at this point in the history
…r-pacticipants-when-user-has-contract-data-manage-own-team-permission-2

chore: changed the logic to return blank array if dataset is empty
  • Loading branch information
pahnin authored Sep 27, 2024
2 parents 7be083c + b582c65 commit 87669c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/pact_broker/pacticipants/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def find_all(options = {}, pagination_options = {}, eager_load_associations = []
end

def find(options = {}, pagination_options = {}, eager_load_associations = [])
query = scope_for(PactBroker::Domain::Pacticipant).select_all_qualified
query = scope_for(PactBroker::Domain::Pacticipant)
return [] if query.empty?

query = query.select_all_qualified
query = query.filter(:name, options[:query_string]) if options[:query_string]
query = query.label(options[:label_name]) if options[:label_name]
query.order_ignore_case(Sequel[:pacticipants][:name]).eager(*eager_load_associations).all_with_pagination_options(pagination_options)
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/pact_broker/pacticipants/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ module Pacticipants
expect(subject.collect(&:name)).to eq ["Wiffle"]
end
end

context "when scope applied" do
it "returns the pacticipants if scope allows" do
allow_any_instance_of(Repository).to receive(:scope_for).and_return(PactBroker::Domain::Pacticipant) # default, with no scope applied
expect(subject.collect(&:name)).to include(*["Bar", "Foo"])
end

it "returns blank array if scope does not allow" do
allow_any_instance_of(Repository).to receive(:scope_for).and_return([])
expect(subject).to eq []
end
end
end

describe "#find_by_name" do
Expand Down

0 comments on commit 87669c3

Please sign in to comment.