0
Ruby on Rails 응용 프로그램에서 실시간 채팅을 만들고 있는데 사양 테스트를 만드는 데 어려움이 있습니다. 몇 가지 예제 테스트를 시도하지만 아무 것도 찾지 못했습니다. 이 클래스에 대한 테스트는 어떻게 작성합니까?MessageBroadcast on ruby
class MessageBroadcastJob < ApplicationJob
queue_as :default
def perform(message)
sender = message.person
recipient = message.conversation.opposed_person(sender)
broadcast_to_sender(sender, message)
broadcast_to_recipient(recipient, message)
end
private
def broadcast_to_sender(person, message)
ActionCable.server.broadcast(
"conversations-#{person.id}",
message: render_message(message, person),
conversation_id: message.conversation_id
)
end
def broadcast_to_recipient(person, message)
ActionCable.server.broadcast(
"conversations-#{person.id}",
window: render_window(message.conversation, person),
message: render_message(message, person),
conversation_id: message.conversation_id
)
end
def render_message(message, person)
ApplicationController.render(
partial: 'messages/message',
locals: { message: message, person: person }
)
end
def render_window(conversation, person)
ApplicationController.render(
partial: 'conversations/conversation',
locals: { conversation: conversation, person: person }
)
end
end