diff --git a/lib/pact_broker/pacticipants/repository.rb b/lib/pact_broker/pacticipants/repository.rb index 26f0e74e8..f836cee0e 100644 --- a/lib/pact_broker/pacticipants/repository.rb +++ b/lib/pact_broker/pacticipants/repository.rb @@ -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) diff --git a/spec/lib/pact_broker/pacticipants/repository_spec.rb b/spec/lib/pact_broker/pacticipants/repository_spec.rb index 7509c479f..2538c7633 100644 --- a/spec/lib/pact_broker/pacticipants/repository_spec.rb +++ b/spec/lib/pact_broker/pacticipants/repository_spec.rb @@ -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