diff --git a/lib/pact_broker/api/resources/group.rb b/lib/pact_broker/api/resources/group.rb index 7467038fd..83965782a 100644 --- a/lib/pact_broker/api/resources/group.rb +++ b/lib/pact_broker/api/resources/group.rb @@ -18,7 +18,11 @@ def resource_exists? end def to_csv - PactBroker::Api::Decorators::RelationshipsCsvDecorator.new(group).to_csv + if group + PactBroker::Api::Decorators::RelationshipsCsvDecorator.new(group).to_csv + else + "" + end end def policy_name diff --git a/spec/lib/pact_broker/api/resources/group_spec.rb b/spec/lib/pact_broker/api/resources/group_spec.rb index 05884b501..2b539da95 100644 --- a/spec/lib/pact_broker/api/resources/group_spec.rb +++ b/spec/lib/pact_broker/api/resources/group_spec.rb @@ -4,17 +4,13 @@ require 'rack/test' module PactBroker::Api - module Resources - describe Group do - include Rack::Test::Methods let(:app) { PactBroker::API } describe "GET" do - let(:group) { double('group') } let(:decorator) { instance_double(PactBroker::Api::Decorators::RelationshipsCsvDecorator) } let(:csv) { 'csv' } @@ -60,7 +56,6 @@ module Resources subject expect(last_response.body).to eq csv end - end context "when the pacticipant does not exist" do @@ -72,9 +67,16 @@ module Resources end end - end + context "when there is no group because the pacticipant isn't integrated with any other pacticipants" do + let(:group) { nil } + it "returns an empty body" do + expect(subject.status).to eq 200 + expect(last_response.headers['Content-Type']).to eq 'text/csv;charset=utf-8' + expect(subject.body).to eq "" + end + end + end end end - end