Class: PactBroker::Pacts::PactVersion

Inherits:
Object
  • Object
show all
Includes:
PactVersionAssociationLoaders
Defined in:
lib/pact_broker/pacts/pact_version.rb

Constant Summary

Constants included from PactVersionAssociationLoaders

PactBroker::Pacts::PactVersionAssociationLoaders::LATEST_CONSUMER_VERSION_LAZY_LOADER, PactBroker::Pacts::PactVersionAssociationLoaders::LATEST_MAIN_BRANCH_VERIFICATION, PactBroker::Pacts::PactVersionAssociationLoaders::LATEST_VERIFICATION_DATASET

Instance Method Summary collapse

Instance Method Details

#any_successful_verifications_from_another_branch_from_before_this_branch_created?(branch_name) ⇒ Boolean

Returns:

  • (Boolean)


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/pact_broker/pacts/pact_version.rb', line 180

def any_successful_verifications_from_another_branch_from_before_this_branch_created?(branch_name)
  branch = PactBroker::Versions::Branch.where(pacticipant_id: provider_id, name: branch_name).single_record

  verifications_join = {
    Sequel[:verifications][:pact_version_id] => Sequel[:pact_versions][:id],
    Sequel[:verifications][:success] => true
  }
  query = PactVersion.where(Sequel[:pact_versions][:id] => id)
    .join(:verifications, verifications_join)
    .join(:branch_versions, Sequel[:branch_versions][:version_id] => Sequel[:verifications][:provider_version_id]) do
      Sequel.lit("branch_versions.branch_name != ?", branch_name)
    end

  if branch
    query = query.where { Sequel[:verifications][:created_at] < branch.created_at }
  end

  query.any?
end

#any_successful_verifications_from_provider_branch?(branch_name) ⇒ Boolean

Returns:

  • (Boolean)


173
174
175
176
177
178
# File 'lib/pact_broker/pacts/pact_version.rb', line 173

def any_successful_verifications_from_provider_branch?(branch_name)
  PactVersion.where(Sequel[:pact_versions][:id] => id)
    .join_successful_verifications
    .join_branch_versions_for_branch_name_to_verifications(branch_name)
    .any?
end

#consumer_nameObject



101
102
103
# File 'lib/pact_broker/pacts/pact_version.rb', line 101

def consumer_name
  consumer.name
end

#latest_consumer_version_numberObject



113
114
115
# File 'lib/pact_broker/pacts/pact_version.rb', line 113

def latest_consumer_version_number
  latest_consumer_version.number
end

#latest_pact_publicationObject



105
106
107
108
109
110
# File 'lib/pact_broker/pacts/pact_version.rb', line 105

def latest_pact_publication
  PactBroker::Pacts::PactPublication
    .for_pact_version_id(id)
    .remove_overridden_revisions_from_complete_query
    .latest || PactBroker::Pacts::PactPublication.for_pact_version_id(id).latest
end

#nameObject



93
94
95
# File 'lib/pact_broker/pacts/pact_version.rb', line 93

def name
  "Pact between #{consumer_name} and #{provider_name}"
end

#pending_for_provider_branch?(branch_name) ⇒ Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/pact_broker/pacts/pact_version.rb', line 117

def pending_for_provider_branch?(branch_name)
  !any_successful_verifications_from_provider_branch?(branch_name) && !any_successful_verifications_from_another_branch_from_before_this_branch_created?(branch_name)
end

#provider_nameObject



97
98
99
# File 'lib/pact_broker/pacts/pact_version.rb', line 97

def provider_name
  provider.name
end

#select_provider_tags_with_successful_verifications(tags) ⇒ Object



147
148
149
150
151
152
153
154
155
# File 'lib/pact_broker/pacts/pact_version.rb', line 147

def select_provider_tags_with_successful_verifications(tags)
  tags.select do | tag |
    PactVersion.where(Sequel[:pact_versions][:id] => id)
      .join_successful_verifications
      .join_provider_versions
      .join_provider_version_tags_for_tag(tag)
      .any?
  end
end

#select_provider_tags_with_successful_verifications_from_another_branch_from_before_this_branch_created(tags) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/pact_broker/pacts/pact_version.rb', line 121

def select_provider_tags_with_successful_verifications_from_another_branch_from_before_this_branch_created(tags)
  tags.select do | tag |
    first_tag_with_name = PactBroker::Domain::Tag.where(pacticipant_id: provider_id, name: tag).order(:created_at).first

    verifications_join = {
      Sequel[:verifications][:pact_version_id] => Sequel[:pact_versions][:id],
      Sequel[:verifications][:success] => true
    }
    tags_join = {
      Sequel[:tags][:version_id] => Sequel[:versions][:id],
    }
    query = PactVersion.where(Sequel[:pact_versions][:id] => id)
      .join(:verifications, verifications_join)
      .join(:versions, Sequel[:versions][:id] => Sequel[:verifications][:provider_version_id])
      .join(:tags, tags_join) do
        Sequel.lit("tags.name != ?", tag)
      end

    if first_tag_with_name
      query = query.where { Sequel[:verifications][:created_at] < first_tag_with_name.created_at }
    end

    query.any?
  end
end

#set_interactions_and_messages_counts!Object



163
164
165
166
167
168
169
170
171
# File 'lib/pact_broker/pacts/pact_version.rb', line 163

def set_interactions_and_messages_counts!
  if interactions_count.nil? || messages_count.nil?
    content_object = PactBroker::Pacts::Content.from_json(content)
    update(
      messages_count: content_object.messages&.count || 0,
      interactions_count: content_object.interactions&.count || 0
    )
  end
end

#verified_successfully_by_any_provider_version?Boolean

Returns:

  • (Boolean)


157
158
159
160
161
# File 'lib/pact_broker/pacts/pact_version.rb', line 157

def verified_successfully_by_any_provider_version?
  PactVersion.where(Sequel[:pact_versions][:id] => id)
    .join_successful_verifications
    .any?
end