Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/event_source/protocols/amqp_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def self.proxy_klass
def self.subscribe_operation_name_for(app_name, subscriber_key)
"on_#{app_name}.#{subscriber_key}"
end

def self.subscriber_action_name_for(_app_name, action_name)
"on_#{action_name}"
end
end
end
end
4 changes: 4 additions & 0 deletions lib/event_source/protocols/arn_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def self.proxy_klass
def self.subscribe_operation_name_for(app_name, subscriber_key)
"on_#{app_name}.#{subscriber_key}"
end

def self.subscriber_action_name_for(_app_name, action_name)
"on_#{action_name}"
end
end
end
end
4 changes: 4 additions & 0 deletions lib/event_source/protocols/http_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def self.proxy_klass
def self.subscribe_operation_name_for(_app_name, subscriber_key)
"/on#{subscriber_key}"
end

def self.subscriber_action_name_for(_app_name, action_name)
action_name.gsub("/", "_").delete_prefix("_")
end
end
end
end
11 changes: 11 additions & 0 deletions lib/event_source/protocols/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def protocol_klass_for(protocol)
match ? match[1] : nil
end

def subscriber_action_name_for(protocol, app_name, action_name)
match = @connection_modules.detect do |r_item|
r_item[0].any? { |ri| ri == protocol}
end
match ? match[1].subscriber_action_name_for(app_name, action_name) : nil
end

def subscribe_operation_name_for(protocol, app_name, subscriber_key)
match = @connection_modules.detect do |r_item|
r_item[0].any? { |ri| ri == protocol}
Expand All @@ -52,6 +59,10 @@ def self.protocol_klass_for(protocol)
def self.subscribe_operation_name_for(protocol, app_name, subscriber_key)
instance.subscribe_operation_name_for(protocol.to_sym, app_name, subscriber_key)
end

def self.subscriber_action_name_for(protocol, app_name, action_name)
instance.subscriber_action_name_for(protocol.to_sym, app_name, action_name)
end
end
end
end
13 changes: 11 additions & 2 deletions lib/event_source/rspec/event_routing_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ module EventRoutingMatchers
)
return false unless conn
s_key = s_class.subscriber_executable_key_for(s_action)
!EventSource::Subscriber.executable_container[s_key].blank?
action_key = EventSource::Protocols::Registry.subscriber_action_name_for(
message_spec[0],
EventSource.app_name,
message_spec[2]
)
!EventSource::Subscriber.executable_container[s_key].blank? && s_action.to_s == action_key.to_s
end

failure_message do |message_spec|
Expand All @@ -75,11 +80,15 @@ module EventRoutingMatchers
}
)
return "#{base_message}, but could not resolve a connection" unless conn
s_key = s_class.subscriber_executable_key_for(s_action)
s_exe = EventSource::Subscriber.executable_container[s_key]
return "#{base_message}, but could not resolve an executable" unless s_exe
return "#{base_message}, but routed instead to #{s_action}" unless s_action.to_s == message_spec[2].to_s
base_message
end

failure_message_when_negated do |message_spec|
"expected #{message_spec} not to route to the :#{s_action} action of the #{s_class} subscriber"
"expected #{message_spec} not to route to the :#{s_action} action of the #{s_class} subscriber, but it did"
end

description do
Expand Down
7 changes: 7 additions & 0 deletions spec/rails_app/spec/determination_subscriber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@
:on_determined_aqhp_eligible
)
end

it "does not route a message to the wrong handler for 'magi_medicaid.mitc.eligibilities', :on_totally_made_up_event" do
expect([:amqp, 'magi_medicaid.mitc.eligibilities', 'totally_made_up_event']).not_to route_to_subscription(
Subscribers::DeterminationSubscriber,
:on_determined_aqhp_eligible
)
end
end
Loading