Skip to content

Commit

Permalink
refactor: reduce the ridiculous number of arguments that are passed u…
Browse files Browse the repository at this point in the history
…nnecessarily to QueryResultsWithDeploymentStatusSummary
  • Loading branch information
bethesque committed Mar 15, 2020
1 parent d15fc57 commit 0e60b83
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@

module PactBroker
module Matrix
class QueryResultsWithDeploymentStatusSummary < QueryResults
attr_reader :deployment_status_summary
class QueryResultsWithDeploymentStatusSummary
extend Forwardable

def initialize rows, selectors, options, resolved_selectors, integrations, deployment_status_summary
super(rows, selectors, options, resolved_selectors, integrations)
attr_reader :query_results, :deployment_status_summary

delegate [:selectors, :options, :resolved_selectors, :integrations] => :query_results
delegate (Array.instance_methods - Object.instance_methods) => :rows
delegate [:deployable?] => :deployment_status_summary


def initialize query_results, deployment_status_summary
@query_results = query_results
@deployment_status_summary = deployment_status_summary
end

def rows
query_results.rows
end
end
end
end
2 changes: 1 addition & 1 deletion lib/pact_broker/matrix/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Service
def find selectors, options = {}
query_results = matrix_repository.find selectors, options
deployment_status_summary = DeploymentStatusSummary.new(query_results.rows, query_results.resolved_selectors, query_results.integrations)
QueryResultsWithDeploymentStatusSummary.new(query_results.rows, query_results.selectors, query_results.options, query_results.resolved_selectors, query_results.integrations, deployment_status_summary)
QueryResultsWithDeploymentStatusSummary.new(query_results, deployment_status_summary)
end

def find_for_consumer_and_provider params, options = {}
Expand Down
13 changes: 11 additions & 2 deletions spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,16 @@ module Decorators
]
end

let(:query_results){ PactBroker::Matrix::QueryResultsWithDeploymentStatusSummary.new([row_1, row_2], selectors, options, resolved_selectors, integrations, deployment_status_summary)}
let(:query_results) do
double('QueryResults',
rows: [row_1, row_2],
selectors: selectors,
options: options,
resolved_selectors: resolved_selectors,
integrations: integrations
)
end
let(:query_results_with_deployment_status_summary){ PactBroker::Matrix::QueryResultsWithDeploymentStatusSummary.new(query_results, deployment_status_summary)}
let(:selectors) { nil }
let(:integrations){ [] }
let(:options) { nil }
Expand All @@ -145,7 +154,7 @@ module Decorators
instance_double('PactBroker::Matrix::DeploymentStatusSummary', reasons: ['foo', 'bar'], deployable?: deployable, counts: counts)
end
let(:deployable) { true }
let(:json) { MatrixDecorator.new(query_results).to_json(user_options: { base_url: 'http://example.org' }) }
let(:json) { MatrixDecorator.new(query_results_with_deployment_status_summary).to_json(user_options: { base_url: 'http://example.org' }) }
let(:parsed_json) { JSON.parse(json, symbolize_names: true) }

it "includes the consumer details" do
Expand Down

0 comments on commit 0e60b83

Please sign in to comment.