File tree 5 files changed +8
-7
lines changed
spec/lib/pact_broker/api/resources
5 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ def from_json
34
34
if pacticipant
35
35
@pacticipant = pacticipant_service . update params_with_string_keys . merge ( 'name' => pacticipant_name )
36
36
else
37
- @pacticipant = pacticipant_service . create params_with_string_keys . merge ( ' name' => pacticipant_name )
37
+ @pacticipant = pacticipant_service . create params . merge ( : name => pacticipant_name )
38
38
response . headers [ "Location" ] = pacticipant_url ( base_url , pacticipant )
39
39
end
40
40
response . body = to_json
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ def post_is_create?
32
32
end
33
33
34
34
def from_json
35
- created_model = pacticipant_service . create params_with_string_keys
35
+ created_model = pacticipant_service . create ( params )
36
36
response . body = decorator_for ( created_model ) . to_json ( user_options : decorator_context )
37
37
end
38
38
Original file line number Diff line number Diff line change @@ -41,6 +41,9 @@ def find_by_name_or_create name
41
41
end
42
42
end
43
43
44
+ # Need to be able to handle two calls that make the pacticipant at the same time.
45
+ # TODO raise error if attributes apart from name are different, because this indicates that
46
+ # the second request is not at the same time.
44
47
def create args
45
48
PactBroker ::Domain ::Pacticipant . dataset . insert_ignore . insert (
46
49
name : args [ :name ] ,
Original file line number Diff line number Diff line change @@ -58,17 +58,15 @@ def self.find_pacticipant_repository_url_by_pacticipant_name name
58
58
end
59
59
60
60
def self . update params
61
+ # TODO move this to the repository!
61
62
pacticipant = pacticipant_repository . find_by_name ( params . fetch ( 'name' ) )
62
63
PactBroker ::Api ::Decorators ::PacticipantDecorator . new ( pacticipant ) . from_hash ( params )
63
64
pacticipant . save
64
65
pacticipant_repository . find_by_name ( params . fetch ( 'name' ) )
65
66
end
66
67
67
68
def self . create params
68
- pacticipant = PactBroker ::Domain ::Pacticipant . new
69
- PactBroker ::Api ::Decorators ::PacticipantDecorator . new ( pacticipant ) . from_hash ( params )
70
- pacticipant . save
71
- pacticipant
69
+ pacticipant_repository . create ( params )
72
70
end
73
71
74
72
def self . delete name
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ module Resources
47
47
48
48
context "with valid JSON" do
49
49
it "creates the pacticipant" do
50
- expect ( PactBroker ::Pacticipants ::Service ) . to receive ( :create ) . with ( ' name' => 'New Consumer' )
50
+ expect ( PactBroker ::Pacticipants ::Service ) . to receive ( :create ) . with ( : name => 'New Consumer' )
51
51
subject
52
52
end
53
53
You can’t perform that action at this time.
0 commit comments