@@ -139,6 +139,7 @@ module Pacts
139
139
let ( :existing_pact ) do
140
140
TestDataBuilder . new . create_pact_with_hierarchy ( "A Consumer" , "1.2.3" , "A Provider" , original_json_content ) . and_return ( :pact )
141
141
end
142
+ let ( :repository ) { Repository . new }
142
143
143
144
before do
144
145
::DB ::PACT_BROKER_DB [ :pact_publications ]
@@ -155,10 +156,8 @@ module Pacts
155
156
let ( :original_json_content ) { { some : 'json' } . to_json }
156
157
let ( :json_content ) { { some_other : 'json' } . to_json }
157
158
158
-
159
159
context "when the attributes have changed" do
160
-
161
- subject { Repository . new . update existing_pact . id , json_content : json_content }
160
+ subject { repository . update existing_pact . id , json_content : json_content }
162
161
163
162
it "creates a new PactVersion" do
164
163
expect { subject } . to change { PactBroker ::Pacts ::PactPublication . count } . by ( 1 )
@@ -186,11 +185,27 @@ module Pacts
186
185
it "increments the revision_number by 1" do
187
186
expect ( subject . revision_number ) . to eq 2
188
187
end
188
+
189
+ context "when there is a race condition" do
190
+ before do
191
+ allow ( repository ) . to receive ( :next_revision_number ) { | existing_pact | existing_pact . revision_number }
192
+ end
193
+
194
+ it "updates the existing row - yes this is destructive, by MySQL not supporting inner queries stops us doing a SELECT revision_number + 1" do
195
+ # And if we're conflicting the time between the two publications is so small that nobody
196
+ # can have depended on the content of the first pact
197
+ expect { subject } . to_not change { PactBroker ::Pacts ::PactPublication . count }
198
+ end
199
+
200
+ it "sets the content to the new content" do
201
+ expect ( subject . json_content ) . to eq json_content
202
+ end
203
+ end
189
204
end
190
205
191
206
context "when the content has not changed" do
192
207
193
- subject { Repository . new . update existing_pact . id , json_content : original_json_content }
208
+ subject { repository . update existing_pact . id , json_content : original_json_content }
194
209
195
210
it "does not create a new PactVersion" do
196
211
expect { subject } . to_not change { PactBroker ::Pacts ::PactPublication . count }
@@ -217,6 +232,7 @@ module Pacts
217
232
. create_consumer_version ( "1.2.3" )
218
233
. create_provider ( provider_name )
219
234
. create_pact
235
+ . create_webhook
220
236
. revise_pact
221
237
. create_consumer_version ( "2.3.4" )
222
238
. create_pact
0 commit comments