class PactBroker::Domain::Verification

Constants

FROM_JSON_WITH_SYMBOL_KEYS
TO_JSON

Public Instance Methods

all_interactions_missing_test_results?() click to toggle source
# File lib/pact_broker/domain/verification.rb, line 211
def all_interactions_missing_test_results?
  pact_content_with_test_results.interactions.count == pact_content_with_test_results.interactions_missing_test_results.count
end
before_create() click to toggle source
Calls superclass method
# File lib/pact_broker/domain/verification.rb, line 22
def before_create
  super
  self.execution_date ||= DateTime.now
end
consumer(consumer_name) click to toggle source
# File lib/pact_broker/domain/verification.rb, line 139
def consumer consumer_name
  where(name_like(:consumer_name, consumer_name))
end
consumer_name() click to toggle source
# File lib/pact_broker/domain/verification.rb, line 187
def consumer_name
  consumer.name
end
consumer_version_number(number) click to toggle source
# File lib/pact_broker/domain/verification.rb, line 147
def consumer_version_number number
  where(name_like(:consumer_version_number, number))
end
delete() click to toggle source
Calls superclass method
# File lib/pact_broker/domain/verification.rb, line 133
def delete
  require "pact_broker/webhooks/triggered_webhook"
  PactBroker::Webhooks::TriggeredWebhook.where(verification: self).delete
  super
end
failed_and_pact_pending?() click to toggle source
# File lib/pact_broker/domain/verification.rb, line 224
def failed_and_pact_pending?
  !success && pact_pending
end
for_consumer_name(consumer_name) click to toggle source
# File lib/pact_broker/domain/verification.rb, line 34
def for_consumer_name(consumer_name)
  where(consumer: PactBroker::Domain::Pacticipant.find_by_name(consumer_name))
end
for_consumer_name_and_consumer_version_number(consumer_name, consumer_version_number) click to toggle source
# File lib/pact_broker/domain/verification.rb, line 174
def for_consumer_name_and_consumer_version_number(consumer_name, consumer_version_number)
  consumer_versions = PactBroker::Domain::Version.select(:id).where_pacticipant_name_and_version_number(consumer_name, consumer_version_number)
  join(:pact_publications, {
    Sequel[:pact_publications][:pact_version_id] => Sequel[:verifications][:pact_version_id],
    Sequel[:pact_publications][:consumer_version_id] => consumer_versions
  })
end
for_provider_name(provider_name) click to toggle source
# File lib/pact_broker/domain/verification.rb, line 30
def for_provider_name(provider_name)
  where(provider: PactBroker::Domain::Pacticipant.find_by_name(provider_name))
end
from_provider_main_branch() click to toggle source

TODO optimise this

# File lib/pact_broker/domain/verification.rb, line 39
def from_provider_main_branch
  providers_join = {
    Sequel[:verifications][:provider_id] => Sequel[:providers][:id]
  }

  branch_versions_join = {
    Sequel[:verifications][:provider_version_id] => Sequel[:branch_versions][:version_id],
    Sequel[:providers][:main_branch] => Sequel[:branch_versions][:branch_name]
  }

  join(:pacticipants, providers_join, { table_alias: :providers })
    .join(:branch_versions, branch_versions_join)
end
interactions_missing_test_results() click to toggle source
# File lib/pact_broker/domain/verification.rb, line 207
def interactions_missing_test_results
  @interactions_missing_test_results ||= pact_content_with_test_results.interactions_missing_test_results
end
join_pact_publications() click to toggle source
# File lib/pact_broker/domain/verification.rb, line 170
def join_pact_publications
  join(:pact_publications, { Sequel[:pact_publications][:pact_version_id] => Sequel[:verifications][:pact_version_id] })
end
latest_by_pact_version() click to toggle source

TODO change this to a group by

# File lib/pact_broker/domain/verification.rb, line 54
def latest_by_pact_version
  base_query = self
  base_join = {
    Sequel[:verifications][:pact_version_id] => Sequel[:v2][:pact_version_id]
  }

  if no_columns_selected?
    base_query = base_query.select_all_qualified
  end

  base_query.left_join(:latest_verification_id_for_pact_version_and_provider_version, base_join, { table_alias: :v2 }) do
    Sequel[:v2][:verification_id] > Sequel[:verifications][:id]
  end
  .where(Sequel[:v2][:verification_id] => nil)
end
latest_pact_publication() click to toggle source
# File lib/pact_broker/domain/verification.rb, line 203
def latest_pact_publication
  pact_version.latest_pact_publication
end
latest_verification_ids_for_consumer_version_tags(consumer_ids, consumer_version_tag_names) click to toggle source
# File lib/pact_broker/domain/verification.rb, line 98
def latest_verification_ids_for_consumer_version_tags(consumer_ids, consumer_version_tag_names)
  pact_join = { :verifications[:pact_version_id] => :lpp[:pact_version_id], :lpp[:consumer_id] => consumer_ids }
  tag_join = { :lpp[:consumer_version_id] => :cvt[:version_id], :cvt[:name] => consumer_version_tag_names }
  provider_versions_join = { :verifications[:provider_version_id] => :pv[:id] }

  db[Sequel.as(:latest_verification_id_for_pact_version_and_provider_version, :verifications)]
    .select_group(
      :pv[:pacticipant_id].as(:provider_id),
      :lpp[:consumer_id],
      :cvt[:name].as(:consumer_version_tag_name)
    )
    .select_append{ max(verifications[verification_id]).as(latest_verification_id) }
    .join(:latest_pact_publication_ids_for_consumer_versions, pact_join, { table_alias: :lpp } )
    .join(:tags, tag_join, { table_alias: :cvt })
    .join(:versions, provider_versions_join, { table_alias: :pv })
    .where(:verifications[:consumer_id] => consumer_ids)
end
latest_verifications_for_all_consumer_version_tags() click to toggle source

Do not use this query. It performs worse than the view. Keeping for posterity

# File lib/pact_broker/domain/verification.rb, line 72
def latest_verifications_for_all_consumer_version_tags
  verif_pact_join = { Sequel[:v][:pact_version_id] => Sequel[:lpp][:pact_version_id] }
  tag_join = { Sequel[:lpp][:consumer_version_id] => Sequel[:cvt][:version_id] }
  verisons_join = { Sequel[:v][:provider_version_id] => Sequel[:pv][:id] }

  base_query = db[Sequel.as(:latest_verification_id_for_pact_version_and_provider_version, :v)]
    .select(:v[:verification_id], :pv[:pacticipant_id].as(:provider_id), :lpp[:consumer_id], :cvt[:name].as(:consumer_version_tag_name))
    .join(:latest_pact_publication_ids_for_consumer_versions, verif_pact_join, { table_alias: :lpp } )
    .join(:tags, tag_join, { table_alias: :cvt })
    .join(:versions, verisons_join, { table_alias: :pv })


  base_join = {
    :pv[:pacticipant_id] => :v2[:provider_id],
    :lpp[:consumer_id] => :v2[:consumer_id],
    :cvt[:name] => :v2[:consumer_version_tag_name]
  }

  thing = base_query
    .left_join(base_query, base_join, { table_alias: :v2 }) do | _table, _joined_table, _something |
      :v2[:verification_id] > :v[:verification_id]
    end.where(:v2[:verification_id] => nil)

  where(id: thing.from_self.select(:verification_id))
end
latest_verifications_for_consumer_version_tags(consumer_ids, consumer_version_tag_names) click to toggle source

Do not use this query. It performs worse than the view. Keeping for posterity

# File lib/pact_broker/domain/verification.rb, line 118
def latest_verifications_for_consumer_version_tags(consumer_ids, consumer_version_tag_names)
  latest_ids_for_cv_tags = latest_verification_ids_for_consumer_version_tags(consumer_ids, consumer_version_tag_names)
  join_cols = {
    Sequel[:verifications][:id] => Sequel[:t2][:latest_verification_id]
  }
  select_all_qualified
    .select_append(Sequel[:t2][:consumer_version_tag_name])
    .where(Sequel[:verifications][:consumer_id] => consumer_ids)
    .join(latest_ids_for_cv_tags, join_cols, { table_alias: :t2 })
end
method_missing(m, *args, **kwargs, &block) click to toggle source

So consumer_version_tag_name can be accessed by method name

Calls superclass method
# File lib/pact_broker/domain/verification.rb, line 229
def method_missing(m, *args, **kwargs, &block)
  if values.key?(m) && args.size == 0
    values[m]
  else
    super
  end
end
pact_content_with_test_results() click to toggle source
# File lib/pact_broker/domain/verification.rb, line 215
def pact_content_with_test_results
  @pact_content_with_test_results = PactBroker::Pacts::Content.from_json(pact_version.content).with_test_results(test_results)
end
pact_pending?() click to toggle source

Whether the pact content was pending at the time the verification was run

# File lib/pact_broker/domain/verification.rb, line 220
def pact_pending?
  pact_pending
end
pact_version_sha(sha) click to toggle source
# File lib/pact_broker/domain/verification.rb, line 151
def pact_version_sha sha
  where(pact_version_sha: sha)
end
provider(provider_name) click to toggle source
# File lib/pact_broker/domain/verification.rb, line 143
def provider provider_name
  where(name_like(:provider_name, provider_name))
end
provider_name() click to toggle source
# File lib/pact_broker/domain/verification.rb, line 191
def provider_name
  provider.name
end
provider_version_number() click to toggle source
# File lib/pact_broker/domain/verification.rb, line 195
def provider_version_number
  provider_version.number
end
provider_version_tag_names() click to toggle source
# File lib/pact_broker/domain/verification.rb, line 199
def provider_version_tag_names
  provider_version.tags.collect(&:name)
end
remove_verifications_for_overridden_consumer_versions() click to toggle source
# File lib/pact_broker/domain/verification.rb, line 129
def remove_verifications_for_overridden_consumer_versions
  join(:latest_pact_publication_ids_for_consumer_versions, { pact_version_id: :pact_version_id } )
end
tag(tag_name) click to toggle source
# File lib/pact_broker/domain/verification.rb, line 159
def tag tag_name
  filter = name_like(Sequel.qualify(:tags, :name), tag_name)
  join(:tags, { version_id: :consumer_version_id }).where(filter)
end
untagged() click to toggle source
# File lib/pact_broker/domain/verification.rb, line 164
def untagged
  join(:pact_publications, {pact_version_id: :pact_version_id})
    .left_outer_join(:tags, {version_id: :consumer_version_id})
    .where(Sequel.qualify(:tags, :name) => nil)
end
verification_number(number) click to toggle source
# File lib/pact_broker/domain/verification.rb, line 155
def verification_number number
  where(Sequel.qualify("verifications", "number") => number)
end