Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync new controls after create #1377

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading