Skip to content

Commit

Permalink
Responses should be returned in the middlewares as Rack arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
arsduo committed Sep 20, 2012
1 parent 723ebf6 commit 7e34ad0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/batch_api/processor/executor.rb
Expand Up @@ -11,7 +11,7 @@ def initialize(app)

# Public: execute the batch operation.
def call(env)
env[:op].execute
env[:op].execute.to_rack
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/batch_api/response.rb
Expand Up @@ -15,6 +15,11 @@ def initialize(response)
@body = process_body(response[2])
end


def to_rack
[status, headers, body]
end

private

def process_body(body_pieces)
Expand Down
7 changes: 4 additions & 3 deletions spec/lib/processor/executor_spec.rb
Expand Up @@ -5,7 +5,8 @@

let(:app) { stub("app", call: stub) }
let(:executor) { BatchApi::Processor::Executor.new(app) }
let(:result) { stub("result") }
let(:rack) { stub("rack array") }
let(:result) { stub("result", to_rack: rack) }
let(:op) { stub("operation", execute: result) }
let(:env) { {op: op} }

Expand All @@ -15,8 +16,8 @@
executor.call(env)
end

it "returns the result" do
executor.call(env).should == result
it "returns the result as a Rack array" do
executor.call(env).should == result.to_rack
end
end
end
10 changes: 10 additions & 0 deletions spec/lib/response_spec.rb
Expand Up @@ -24,4 +24,14 @@
it "sets headers to the HTTP headers" do
response.headers.should == raw_response[1]
end

describe "#to_rack" do
it "returns a Rack-compatible array" do
response.to_rack.should == [
response.status,
response.headers,
response.body
]
end
end
end

0 comments on commit 7e34ad0

Please sign in to comment.