Skip to content

Commit

Permalink
ArgumentError for "instantiated participants"
Browse files Browse the repository at this point in the history
they belong to the past
  • Loading branch information
jmettraux committed Jan 30, 2011
1 parent 9f4b6c9 commit 18c7570
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/ruote/engine.rb
Expand Up @@ -521,15 +521,13 @@ def load_definition (path)
# containing the participant implementation. 'require' will load and eval
# the ruby code only once, 'load' each time.
#
def register_participant (regex, participant=nil, opts=nil, &block)
def register_participant (regex, participant=nil, opts={}, &block)

if participant.is_a?(Hash)
opts = participant
participant = nil
end

opts ||= {}

pa = @context.plist.register(regex, participant, opts, block)

@context.storage.put_msg('participant_registered', 'regex' => regex.to_s)
Expand Down
5 changes: 5 additions & 0 deletions lib/ruote/svc/participant_list.rb
Expand Up @@ -47,6 +47,11 @@ def initialize (context)
#
def register (name, participant, options, block)

raise(
ArgumentError.new(
"can only accept strings (classnames) or classes as participant arg")
) unless [ String, Class, NilClass ].include?(participant.class)

klass = (participant || Ruote::BlockParticipant).to_s

options = options.inject({}) { |h, (k, v)|
Expand Down
10 changes: 10 additions & 0 deletions test/functional/ft_3_participant_registration.rb
Expand Up @@ -410,5 +410,15 @@ def test_register_block_catchall_default
%w[ Ruote::StorageParticipant ],
@engine.participant_list.collect { |pe| pe.classname })
end

def test_argument_error_on_instantiated_participant

assert_raise ArgumentError do
@engine.register 'alpha', Ruote::StorageParticipant.new
end
assert_raise ArgumentError do
@engine.register 'alpha', Ruote::StorageParticipant.new, 'hello' => 'kitty'
end
end
end

0 comments on commit 18c7570

Please sign in to comment.