@@ -351,16 +351,36 @@ def find_for_verification(provider_name, consumer_version_selectors)
351
351
selected_pacts = find_pacts_for_which_the_latest_version_is_required ( provider_name , consumer_version_selectors ) +
352
352
find_pacts_for_which_the_latest_version_for_the_tag_is_required ( provider_name , consumer_version_selectors ) +
353
353
find_pacts_for_which_all_versions_for_the_tag_are_required ( provider_name , consumer_version_selectors )
354
+
355
+ selected_pacts = selected_pacts + find_pacts_for_fallback_tags ( selected_pacts , provider_name , consumer_version_selectors )
356
+
354
357
selected_pacts
355
358
. group_by ( &:pact_version_sha )
356
359
. values
357
360
. collect do | selected_pacts_for_pact_version_id |
358
361
SelectedPact . merge ( selected_pacts_for_pact_version_id )
359
362
end
363
+
360
364
end
361
365
362
366
private
363
367
368
+ def find_pacts_for_fallback_tags ( selected_pacts , provider_name , consumer_version_selectors )
369
+ # TODO at the moment, the validation doesn't stop fallback being used with 'all' selectors
370
+ selectors_with_fallback_tags = consumer_version_selectors . select ( &:fallback_tag? )
371
+ selectors_missing_a_pact = selectors_with_fallback_tags . reject do | selector |
372
+ selected_pacts . any? do | selected_pact |
373
+ selected_pact . latest_for_tag? ( selector . tag )
374
+ end
375
+ end
376
+
377
+ if selectors_missing_a_pact . any?
378
+ find_pacts_for_which_the_latest_version_for_the_fallback_tag_is_required ( provider_name , selectors_missing_a_pact )
379
+ else
380
+ [ ]
381
+ end
382
+ end
383
+
364
384
def find_pacts_for_which_the_latest_version_is_required ( provider_name , consumer_version_selectors )
365
385
if consumer_version_selectors . empty?
366
386
LatestPactPublications
@@ -384,26 +404,57 @@ def find_pacts_for_which_the_latest_version_for_the_tag_is_required(provider_nam
384
404
if tag_names . any?
385
405
LatestTaggedPactPublications
386
406
. provider ( provider_name )
387
- . order_ignore_case ( :consumer_name )
388
407
. where ( tag_name : tag_names )
389
408
. all
390
409
. group_by ( &:pact_version_id )
391
410
. values
392
411
. collect do | pact_publications |
393
- selector_tag_names = pact_publications . collect ( &:tag_name )
394
- selectors = Selectors . create_for_latest_of_each_tag ( selector_tag_names )
395
- last_pact_publication = pact_publications . sort_by ( &:consumer_version_order ) . last
396
- pact_publication = PactPublication . find ( id : last_pact_publication . id )
397
- SelectedPact . new (
398
- pact_publication . to_domain ,
399
- selectors
400
- )
412
+ create_selected_pact ( pact_publications )
401
413
end
402
414
else
403
415
[ ]
404
416
end
405
417
end
406
418
419
+ def create_selected_pact ( pact_publications )
420
+ selector_tag_names = pact_publications . collect ( &:tag_name )
421
+ selectors = Selectors . create_for_latest_of_each_tag ( selector_tag_names )
422
+ last_pact_publication = pact_publications . sort_by ( &:consumer_version_order ) . last
423
+ pact_publication = PactPublication . find ( id : last_pact_publication . id )
424
+ SelectedPact . new (
425
+ pact_publication . to_domain ,
426
+ selectors
427
+ )
428
+ end
429
+
430
+ def create_fallback_selected_pact ( pact_publications , consumer_version_selectors )
431
+ selector_tag_names = pact_publications . collect ( &:tag_name )
432
+ selectors = Selectors . create_for_latest_fallback_of_each_tag ( selector_tag_names )
433
+ last_pact_publication = pact_publications . sort_by ( &:consumer_version_order ) . last
434
+ pact_publication = PactPublication . find ( id : last_pact_publication . id )
435
+ SelectedPact . new (
436
+ pact_publication . to_domain ,
437
+ selectors
438
+ )
439
+ end
440
+
441
+ def find_pacts_for_which_the_latest_version_for_the_fallback_tag_is_required ( provider_name , selectors )
442
+ selectors . collect do | selector |
443
+ LatestTaggedPactPublications
444
+ . provider ( provider_name )
445
+ . where ( tag_name : selector . fallback_tag )
446
+ . all
447
+ . collect do | latest_tagged_pact_publication |
448
+ pact_publication = PactPublication . find ( id : latest_tagged_pact_publication . id )
449
+ SelectedPact . new (
450
+ pact_publication . to_domain ,
451
+ Selectors . new ( selector )
452
+ )
453
+ end
454
+ end . flatten
455
+ end
456
+
457
+
407
458
def find_pacts_for_which_all_versions_for_the_tag_are_required ( provider_name , consumer_version_selectors )
408
459
# The tags for which all versions are specified
409
460
tag_names = consumer_version_selectors . tag_names_of_selectors_for_all_pacts
0 commit comments