Skip to content

Comments

OperationBuilder#apply! should be able to handle an array of operations#213

Merged
leastbad merged 1 commit intomasterfrom
fix-apply!-should-handle-array-of-operations
Jul 17, 2022
Merged

OperationBuilder#apply! should be able to handle an array of operations#213
leastbad merged 1 commit intomasterfrom
fix-apply!-should-handle-array-of-operations

Conversation

@marcoroth
Copy link
Member

@marcoroth marcoroth commented Jul 17, 2022

Type of PR

Bug Fix

Description

The OperationBuilder#apply! method somehow didn't account for passing an Array into it when trying to apply operations to a channel. Instead it added the array of operations to the @enqueued_operations ending up in a nested array.

Why should this be added

The nested @enqueued_operations resulted in a NoMethodError (undefined method 'deep_transform_keys!' for []:Array): when trying to use in combination with the .broadcast_later method. This PR fixes the apply! method to also take an array of operations.

irb(main):002:0> cable_ready["example"].broadcast_later
Enqueued CableReadyBroadcastJob (Job ID: f7e8dd9b-8072-406c-8228-1d7cc36307ec) to Async(default) with arguments: {:identifier=>"example", :operations=>[]}
=> nil
Performing CableReadyBroadcastJob (Job ID: f7e8dd9b-8072-406c-8228-1d7cc36307ec) from Async(default) enqueued at 2022-07-17T16:27:01Z with arguments: {:identifier=>"example", :operations=>[]}
irb(main):005:0> Error performing CableReadyBroadcastJob (Job ID: f7e8dd9b-8072-406c-8228-1d7cc36307ec) from Async(default) in 10.67ms: NoMethodError (undefined method `deep_transform_keys!' for []:Array):

To reproduce:

irb(main):001:0> include CableReady::Broadcaster
=> Object

irb(main):002:0> cable_ready["example"].apply!([{"message"=>"Hello World", "operation"=>"consoleLog"}])
=>
#<CableReady::Channel:0x00007f9160b786f0
 @enqueued_operations=[[{"message"=>"Hello World", "operation"=>"consoleLog"}]],
 @identifier="example",
 @previous_selector=nil>

# notice the nested array in @enqueued_operations

irb(main):003:0> cable_ready["example"].broadcast
/Users/marcoroth/Development/cable_ready/lib/cable_ready/operation_builder.rb:72:in `block in operations_payload': undefined method `deep_transform_keys!' for [{"message"=>"Hello World", "operation"=>"consoleLog"}]:Array (NoMethodError)

Checklist

  • My code follows the style guidelines of this project
  • Checks (StandardRB & Prettier-Standard) are passing
  • This is not a documentation update

@leastbad leastbad merged commit 2071244 into master Jul 17, 2022
@leastbad leastbad deleted the fix-apply!-should-handle-array-of-operations branch July 17, 2022 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants