<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -31,6 +31,8 @@ module Nanite
             handler = job.intermediate_handler_for_key(key)
             if handler
               case handler.arity
+              when 1
+                handler.call(job.intermediate_state[msg.from][key].last)
               when 3
                 handler.call(key, msg.from, job.intermediate_state[msg.from][key].last)
               when 4</diff>
      <filename>lib/nanite/job.rb</filename>
    </modified>
    <modified>
      <diff>@@ -33,7 +33,44 @@ describe Nanite::JobWarden do
 
   end # Creating a new Job
 
-
+  describe &quot;Processing an intermediate message&quot; do
+    before(:each) do
+      @intm_handler = lambda {|arg1, arg2, arg3| puts 'ehlo'}
+      @message = mock(&quot;Message&quot;, :token =&gt; &quot;3faba24fcc&quot;, :from =&gt; 'nanite-agent')
+      @serializer = mock(&quot;Serializer&quot;, :load =&gt; @message)
+      @warden = Nanite::JobWarden.new(@serializer)
+      @job = Nanite::Job.new(stub(&quot;request&quot;, :token =&gt; &quot;3faba24fcc&quot;), [], @intm_handler)
+      @job.instance_variable_set(:@pending_keys, [&quot;defaultkey&quot;])
+      @job.instance_variable_set(:@intermediate_state, {&quot;nanite-agent&quot; =&gt; {&quot;defaultkey&quot; =&gt; [1]}})
+      @warden.jobs[@job.token] = @job
+      Nanite::Log.stub!(:debug)
+      Nanite::Log.stub!(:error)
+    end
+    
+    it &quot;should call the intermediate handler with three parameters&quot; do
+      @intm_handler.should_receive(:call).with(&quot;defaultkey&quot;, &quot;nanite-agent&quot;, 1)
+      @warden.process(@message)
+    end
+    
+    it &quot;should call the intermediate handler with four parameters&quot; do
+      @intm_handler.stub!(:arity).and_return(4)
+      @intm_handler.should_receive(:call).with(&quot;defaultkey&quot;, &quot;nanite-agent&quot;, 1, @job)
+      @warden.process(@message)
+    end
+    
+    it &quot;should not call the intermediate handler when it can't be found for the specified key&quot; do
+      @intm_handler.should_not_receive(:call)
+      @job.instance_variable_set(:@intermediate_handler, nil)
+      @warden.process(@message)
+    end
+    
+    it &quot;should call the intermediate handler with one parameter which needs to be the result&quot; do
+      @intm_handler.should_receive(:call).with(1)
+      @intm_handler.stub!(:arity).and_return(1)
+      @warden.process(@message)
+    end
+  end
+  
   describe &quot;Processing a Message&quot; do
 
     before(:each) do</diff>
      <filename>spec/job_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>1e5b7a17b95d034f5d9c0947f4be0e5333a48a4c</id>
    </parent>
  </parents>
  <author>
    <name>Mathias Meyer</name>
    <email>meyer@paperplanes.de</email>
  </author>
  <url>http://github.com/ezmobius/nanite/commit/850565d1bf2f34548c79cee7d0dc9f25da696ce4</url>
  <id>850565d1bf2f34548c79cee7d0dc9f25da696ce4</id>
  <committed-date>2009-06-24T09:08:27-07:00</committed-date>
  <authored-date>2009-06-24T09:08:27-07:00</authored-date>
  <message>Added some specs for dispatching intermediate handlers. Added support for single-argument handlers, since they're the ones used by agent-to-agent intermediate calls.</message>
  <tree>afd7117e67925e72189bf2c0db0675949e951324</tree>
  <committer>
    <name>Mathias Meyer</name>
    <email>meyer@paperplanes.de</email>
  </committer>
</commit>
