0
0
Fork 0

added self.create to the request

With this it is possible to reuse an already set request and therefore
safe some memory and time.
This commit is contained in:
Gibheer 2012-11-16 09:33:25 +01:00
parent 331ee7c53c
commit 8a1c464c8b
2 changed files with 27 additions and 0 deletions

View File

@ -6,9 +6,15 @@ require_relative 'request/server'
module Zero
# This class wraps around a rack environment for easier access to all data.
class Request
def self.create(environment)
return environment['zero.request'] if environment.has_key?('zero.request')
new(environment)
end
# create a new request object
def initialize(env)
@env = env
@env['zero.request'] = self
end
# get the environment

View File

@ -0,0 +1,21 @@
require 'spec_helper'
describe Zero::Request, '.create' do
subject { Zero::Request.new(env) }
context "with a fresh environment" do
let(:env) { EnvGenerator.get('/foo') }
it "creates an instance of Zero::Request" do
Zero::Request.create(env).should be_an_instance_of(Zero::Request)
end
end
context "with an already used environment" do
let(:env) { EnvGenerator.get('/foo') }
let(:new_env) { subject.env }
it "returns an already build request" do
Zero::Request.create(new_env).should be(subject)
end
end
end