Skip to content

Commit

Permalink
Fix bug causing service updates not being sent after save
Browse files Browse the repository at this point in the history
  • Loading branch information
your committed Oct 4, 2024
1 parent 5bc0ec8 commit 8a65471
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Service < ApplicationRecord

belongs_to :updated_by, class_name: :User

after_create_commit :broadcast_message
after_save_commit :broadcast_service_update
after_save_commit :broadcast_last_update

def good_service?
Expand Down Expand Up @@ -68,7 +68,7 @@ def allow_destroy?
errors.add(:delete_confirmation, :cannot_delete) unless destroyable?
end

def broadcast_message
def broadcast_service_update
broadcast_replace_to(
"services-#{scope}",
partial: "dashboard/services",
Expand Down
2 changes: 2 additions & 0 deletions spec/models/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
context "#{scope} scope" do
let(:scope) { scope }

it { allow(described_class).to receive(:after_save_commit).with(:broadcast_message) }

it "broadcasts the message to the 'message-#{scope}' stream" do
is_expected.to have_received(:broadcast_replace_to).with(stream, expected_args).once
end
Expand Down
4 changes: 3 additions & 1 deletion spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
it { is_expected.to validate_inclusion_of(:status).in_array(described_class::ALL_STATUSES) }
end

describe "after_create_commit -> broadcast_message" do
describe "after_save_commit -> broadcast_service_update" do
subject { build(:service, scope:) }

before do
Expand All @@ -27,6 +27,8 @@
context "#{scope} scope" do
let(:scope) { scope }

it { allow(described_class).to receive(:after_save_commit).with(:broadcast_service_update) }

it "broadcasts the message to the 'services-#{scope}' stream" do
is_expected.to have_received(:broadcast_replace_to).with(stream, expected_args).once
end
Expand Down

0 comments on commit 8a65471

Please sign in to comment.