@@ -19,29 +19,52 @@ module Pacts
19
19
end
20
20
21
21
describe "#latest_pact_publication" do
22
- before do
23
- TestDataBuilder . new
24
- . create_provider ( "Bar" )
25
- . create_consumer ( "Foo" )
26
- . create_consumer_version ( "1.2.100" )
27
- . create_pact
28
- . revise_pact
29
- . create_consumer_version ( "1.2.101" )
30
- . create_pact
31
- . create_consumer_version ( "1.2.102" )
32
- . create_pact
33
- . revise_pact
34
- . create_provider ( "Animals" )
35
- . create_pact
36
- . create_provider ( "Wiffles" )
37
- . create_pact
22
+
23
+ context "when the latest pact publication is not an overwritten one" do
24
+ before do
25
+ TestDataBuilder . new
26
+ . create_provider ( "Bar" )
27
+ . create_consumer ( "Foo" )
28
+ . create_consumer_version ( "1.2.100" )
29
+ . create_pact
30
+ . revise_pact
31
+ . create_consumer_version ( "1.2.101" )
32
+ . create_pact
33
+ . create_consumer_version ( "1.2.102" )
34
+ . create_pact
35
+ . revise_pact
36
+ . create_provider ( "Animals" )
37
+ . create_pact
38
+ . create_provider ( "Wiffles" )
39
+ . create_pact
40
+ end
41
+
42
+ it "returns the latest pact publication for the given pact version" do
43
+ pact = PactBroker ::Pacts ::Repository . new . find_pact ( "Foo" , "1.2.102" , "Animals" )
44
+ pact_version = PactBroker ::Pacts ::PactVersion . find ( sha : pact . pact_version_sha )
45
+ latest_pact_publication = pact_version . latest_pact_publication
46
+ expect ( latest_pact_publication . id ) . to eq pact . id
47
+ end
38
48
end
39
49
40
- it "returns the latest pact publication for the given pact version" do
41
- pact = PactBroker ::Pacts ::Repository . new . find_pact ( "Foo" , "1.2.102" , "Animals" )
42
- pact_version = PactBroker ::Pacts ::PactVersion . find ( sha : pact . pact_version_sha )
43
- latest_pact_publication = pact_version . latest_pact_publication
44
- expect ( latest_pact_publication . id ) . to eq pact . id
50
+ context "when the only pact publication with the given sha is an overwritten one" do
51
+ let ( :td ) { TestDataBuilder . new }
52
+ let! ( :first_version ) do
53
+ td . create_provider ( "Bar" )
54
+ . create_consumer ( "Foo" )
55
+ . create_consumer_version ( "1" )
56
+ . create_pact
57
+ . and_return ( :pact )
58
+ end
59
+ let! ( :second_revision ) do
60
+ td . revise_pact
61
+ end
62
+
63
+ it "returns the overwritten pact publication" do
64
+ pact_version = PactBroker ::Pacts ::PactVersion . find ( sha : first_version . pact_version_sha )
65
+ latest_pact_publication = pact_version . latest_pact_publication
66
+ expect ( latest_pact_publication . revision_number ) . to eq 1
67
+ end
45
68
end
46
69
end
47
70
0 commit comments