Skip to content

Commit

Permalink
fix: fix bug where pacticipant with blank name was being created inst…
Browse files Browse the repository at this point in the history
…ead of updating existing record
  • Loading branch information
bethesque committed Jun 3, 2022
1 parent d8dc98c commit be24a8a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/pact_broker/domain/pacticipant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Pacticipant < Sequel::Model
using PactBroker::StringRefinements

plugin :insert_ignore, identifying_columns: [:name]
plugin :upsert, identifying_columns: [:name]
plugin :timestamps, update_on_create: true

set_primary_key :id
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/pacticipants/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def replace(pacticipant_name, open_struct_pacticipant)
repository_name: open_struct_pacticipant.repository_name,
repository_namespace: open_struct_pacticipant.repository_namespace,
main_branch: open_struct_pacticipant.main_branch
).save
).upsert
end

def delete(pacticipant)
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/pact_broker/pacticipants/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ module Pacticipants

subject { Repository.new.replace("Bar", OpenStruct.new(main_branch: "bar", repository_url: "new_url")) }

it "does not create a new record" do
expect { subject }.to_not change { PactBroker::Domain::Pacticipant.count }
end

it "replaces the pacticipant" do
expect(subject.name).to eq "Bar"
expect(subject.main_branch).to eq "bar"
Expand Down

0 comments on commit be24a8a

Please sign in to comment.