Skip to content

Commit

Permalink
Merge pull request #1377 from alphagov/fix-controls-create
Browse files Browse the repository at this point in the history
Sync new controls after create
  • Loading branch information
csutter authored Feb 17, 2025
2 parents b417418 + 156bbb3 commit 3749bab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/concerns/remote_synchronizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ module RemoteSynchronizable
# Normally we would avoid using ActiveRecord callbacks to make network calls, but as the core
# purpose of Search Admin is to provide an interface to manage resources on various remote APIs,
# this is part of its core domain.
before_create :create_remote, unless: :skip_remote_synchronization_on_create
#
# Note the remote creation needs to be _after_ the record is created, as the record needs to
# have an ID. This won't persist if the remote creation fails as the transaction would be rolled
# back.
after_create :create_remote, unless: :skip_remote_synchronization_on_create
before_update :update_remote
before_destroy :destroy_remote

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
expect(client).to have_received(:create).with(record)
end

it "persists the record before passing it to the client" do
expect(client).to receive(:create).with(an_object_satisfying(&:persisted?))

record.save # rubocop:disable Rails/SaveBang (we're not interested in the return value)
end

context "when the remote resource creation fails" do
let(:error) { ClientError.new("Uh oh") }

Expand Down

0 comments on commit 3749bab

Please sign in to comment.