Hello,
I have a system spec for a page on my site. One button on this page kicks off a task that results in models being updated. Those updates appear asynchronously on the page via a broadcast on the model:
# app/models/effort.rb
class Effort < ApplicationRecord
after_update_commit :broadcast_update
private
def broadcast_update
broadcast_render_later_to event_group, partial: "efforts/updated", locals: { effort: self }
end
end
# app/views/efforts/_updated.turbo_stream.erb
<%# locals: (effort:) %>
<%= turbo_stream.replace dom_id(effort, :roster_row),
partial: "efforts/entrant_for_roster",
locals: { effort: effort } %>
This works nicely. And if I use broadcast_render_to
(synchronous) instead of broadcast_render_later_to
(async), I can test the results like this:
RSpec.describe "set data status from the event group roster page", js: true do
include ActionView::RecordIdentifier
scenario "displays the resulting data status" do
login_as steward, scope: :user
visit roster_event_group_path(event_group)
button = page.find_button("Set data status")
button.click
within("##{dom_id(effort, :roster_row)}") do
expect(page).to have_content("good")
end
end
end
But I can’t figure out how to make this spec pass while using an async broadcast_render_later_to
in the model.
Is there some way I can tell Rails to use a synchronous adapter when running in the test environment? Or any other way to test the result?
Thanks in advance!