File tree 3 files changed +43
-2
lines changed
3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,14 @@ class Repository
9
9
include PactBroker ::Repositories ::Helpers
10
10
11
11
def create args
12
- Domain ::Tag . new ( name : args . fetch ( :name ) , version : args . fetch ( :version ) ) . save
12
+ params = {
13
+ name : args . fetch ( :name ) ,
14
+ version_id : args . fetch ( :version ) . id ,
15
+ created_at : Sequel . datetime_class . now ,
16
+ updated_at : Sequel . datetime_class . now
17
+ }
18
+ Domain ::Tag . dataset . insert_ignore . insert ( params )
19
+ Domain ::Tag . find ( name : args [ :name ] , version_id : args [ :version ] . id )
13
20
end
14
21
15
22
def find args
Original file line number Diff line number Diff line change 4
4
module PactBroker
5
5
module Tags
6
6
describe Repository do
7
-
8
7
let ( :td ) { TestDataBuilder . new }
9
8
9
+ describe ".create" do
10
+ before do
11
+ td . create_pacticipant ( "foo" )
12
+ . create_version ( "1" )
13
+ end
14
+
15
+ let ( :params ) { { name : "prod" , version : td . version } }
16
+
17
+ subject { Repository . new . create ( params ) }
18
+
19
+ it "returns a tag" do
20
+ expect ( subject ) . to be_a ( Domain ::Tag )
21
+ end
22
+
23
+ it "sets the properties" do
24
+ expect ( subject . name ) . to eq "prod"
25
+ expect ( subject . version . id ) . to eq td . version . id
26
+ end
27
+
28
+ context "when the tag already exists" do
29
+ before do
30
+ td . create_tag ( "prod" )
31
+ end
32
+
33
+ it "does nothing" do
34
+ expect { subject } . to_not change { Domain ::Tag . count }
35
+ end
36
+
37
+ it "returns a tag" do
38
+ expect ( subject ) . to be_a ( Domain ::Tag )
39
+ end
40
+ end
41
+ end
42
+
10
43
describe ".find" do
11
44
12
45
let ( :pacticipant_name ) { "test_pacticipant" }
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ class TestDataBuilder
35
35
attr_reader :provider
36
36
attr_reader :consumer_version
37
37
attr_reader :provider_version
38
+ attr_reader :version
38
39
attr_reader :pact
39
40
attr_reader :verification
40
41
attr_reader :webhook
You can’t perform that action at this time.
0 commit comments