lib/bunny_mock/exchange.rb in bunny-mock-1.4.0 vs lib/bunny_mock/exchange.rb in bunny-mock-1.5.0

- old
+ new

@@ -166,17 +166,15 @@ # @return [BunnyMock::Exchange] self # @api public # def unbind(exchange, opts = {}) if exchange.respond_to?(:remove_route) - # we can do the unbinding ourselves - exchange.remove_route opts.fetch(:routing_key, @name) + exchange.remove_route opts.fetch(:routing_key, @name), self else - # we need the channel to look up the exchange - @channel.xchg_unbind opts.fetch(:routing_key, @name), exchange + @channel.xchg_unbind opts.fetch(:routing_key, @name), exchange, self end self end @@ -193,11 +191,10 @@ # @return [Boolean] true if this exchange is bound to the given exchange, false otherwise # @api public # def bound_to?(exchange, opts = {}) if exchange.respond_to?(:routes_to?) - # we can find out on the exchange object exchange.routes_to? self, opts else # we need the channel to look up the exchange @@ -216,11 +213,12 @@ # @return [Boolean] true if the given queue or exchange matching options is bound to this exchange, false otherwise # @api public # def routes_to?(exchange_or_queue, opts = {}) route = exchange_or_queue.respond_to?(:name) ? exchange_or_queue.name : exchange_or_queue - @routes.key? opts.fetch(:routing_key, route) + rk = opts.fetch(:routing_key, route) + @routes.key?(rk) && @routes[rk].any? { |r| r == exchange_or_queue } end def has_binding?(exchange_or_queue, opts = {}) # rubocop:disable Style/PredicateName warn '[DEPRECATED] `has_binding?` is deprecated. Please use `routes_to?` instead.' routes_to?(exchange_or_queue, opts) @@ -243,14 +241,19 @@ # Implementation # # @private def add_route(key, xchg_or_queue) - @routes[key] = xchg_or_queue + @routes[key] ||= [] + @routes[key] << xchg_or_queue end # @private - def remove_route(key) - @routes.delete key + def remove_route(key, xchg_or_queue) + instance = xchg_or_queue.respond_to?(:name) ? xchg_or_queue.name : xchg_or_queue + @routes[key].delete_if do |r| + route = r.respond_to?(:name) ? r.name : r + route == instance + end if @routes.key? key end end end