File tree 2 files changed +40
-1
lines changed
lib/pact_broker/pacticipants
spec/lib/pact_broker/pacticipants
2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,13 @@ def find_by_name_or_create name
42
42
end
43
43
44
44
def create args
45
- PactBroker ::Domain ::Pacticipant . new ( name : args [ :name ] , repository_url : args [ :repository_url ] ) . save ( raise_on_save_failure : true )
45
+ id = PactBroker ::Domain ::Pacticipant . dataset . insert_ignore . insert (
46
+ name : args [ :name ] ,
47
+ repository_url : args [ :repository_url ] ,
48
+ created_at : Sequel . datetime_class . now ,
49
+ updated_at : Sequel . datetime_class . now
50
+ )
51
+ PactBroker ::Domain ::Pacticipant . find ( id : id )
46
52
end
47
53
48
54
def pacticipant_names
Original file line number Diff line number Diff line change 5
5
module PactBroker
6
6
module Pacticipants
7
7
describe Repository do
8
+ describe "#create" do
9
+ let ( :repository ) { Repository . new }
10
+
11
+ subject { repository . create ( name : "Foo" ) }
12
+
13
+ context "when the pacticipant does not already exist" do
14
+ before do
15
+ TestDataBuilder . new . create_pacticipant ( "Bar" )
16
+ end
17
+
18
+ subject { repository . create ( name : "Foo" ) }
19
+
20
+ it "returns the new pacticipant" do
21
+ expect ( subject ) . to be_a ( PactBroker ::Domain ::Pacticipant )
22
+ expect ( subject . name ) . to eq "Foo"
23
+ end
24
+ end
25
+
26
+ context "when a race condition occurs and the pacticipant was already created by another request" do
27
+ before do
28
+ TestDataBuilder . new . create_pacticipant ( "Foo" )
29
+ end
30
+
31
+ it "does not raise an error" do
32
+ subject
33
+ end
34
+
35
+ it "returns the existing pacticipant" do
36
+ expect ( subject ) . to be_a ( PactBroker ::Domain ::Pacticipant )
37
+ expect ( subject . name ) . to eq "Foo"
38
+ end
39
+ end
40
+ end
8
41
9
42
describe "#find" do
10
43
before do
You can’t perform that action at this time.
0 commit comments