Skip to content

Commit 26a9ed4

Browse files
Fix publishing events responding to #to_hash on Ruby 2.7
When a method accepts both splatted positional & keyword parameters and a single argument responding to `#to_hash` is given, the argument is coerced to hash and assigned to the keyword arguments. E.g.: class Hashable def to_hash { im: :a_hash } end end def method_with_splat_on_the_positional_argument(*args, **kwargs) # method_with_splat_on_the_positional_argument(Hashable.new) puts args.inspect # => [] puts kwargs.inspect # => {:im=>:a_hash} end However, def method_without_splat_on_the_positional_argument(args, **kwargs) # method_without_splat_on_the_positional_argument(Hashable.new) puts args.inspect # => #<Hashable:0x000055cfe8b072b0> puts kwargs.inspect # => {} end We fix the problem on the Spree::Bus override by being explicit about the expected parameters. References solidusio/solidus_stripe#157 (comment)
1 parent 1c4b1ff commit 26a9ed4

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

core/lib/spree/bus.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ module Spree
99
# It has some modifications to support internal usage of the legacy event
1010
# system {see Spree::AppConfiguration#use_legacy_events}.
1111
Bus = Omnes::Bus.new
12-
Bus.define_singleton_method(:publish) do |*args, **kwargs, &block|
12+
Bus.define_singleton_method(:publish) do |event, **kwargs|
1313
if Spree::Config.use_legacy_events
14-
Spree::Event.fire(*args, **kwargs, &block)
14+
Spree::Event.fire(event, **kwargs)
1515
else
1616
# Override caller_location to point to the actual event publisher
17-
super(*args, **kwargs, caller_location: caller_locations(1)[0], &block)
17+
super(event, **kwargs, caller_location: caller_locations(1)[0])
1818
end
1919
end
2020
end

0 commit comments

Comments
 (0)