Skip to content

Commit

Permalink
Merge pull request #26 from paneq/named_exception
Browse files Browse the repository at this point in the history
Raise named exception when someone is trying to send event to unavailable
  • Loading branch information
apotonick committed Jun 28, 2011
2 parents 8285639 + 7d198da commit 5ebe788
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/apotomo/request_processor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module Apotomo
class RequestProcessor

class InvalidSourceWidget < RuntimeError; end

include Hooks

define_hook :after_initialize
Expand All @@ -23,7 +26,7 @@ def attach_stateless_blocks_for(blocks, root, controller)
# Called when the browser wants an url_for_event address. This fires the request event in
# the widget tree and collects the rendered page updates.
def process_for(request_params)
source = self.root.find_widget(request_params[:source]) or raise "Source #{request_params[:source].inspect} non-existent."
source = self.root.find_widget(request_params[:source]) or raise InvalidSourceWidget, "Source #{request_params[:source].inspect} non-existent."

source.fire(request_params[:type].to_sym, request_params) # set data to params for now.

Expand Down
2 changes: 1 addition & 1 deletion test/unit/request_processor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def squeak(evt); render :text => evt.data.inspect; end
end

should "raise an exception when :source is unknown" do
assert_raises RuntimeError do
assert_raises Apotomo::RequestProcessor::InvalidSourceWidget do
@processor.process_for({:type => :squeak, :source => 'tom'})
end
end
Expand Down

0 comments on commit 5ebe788

Please sign in to comment.