Permalink
Browse files

make request and response static

This is a step back but makes the controller work for the moment. It
should be reimplemented in a better way in the future.
  • Loading branch information...
1 parent 4a4d68d commit a2aed1fa20f1f17f940c27c49ce19ec3e1bd09b0 @Gibheer Gibheer committed Jan 29, 2013
@@ -11,16 +11,17 @@ def self.call(env)
new(env).response
end
- # set the class to use for responses
- accept_options :response
-
- # set a class to use for requests
- accept_options :request
+ # set the renderer to use for rendering
+ def self.renderer=(renderer)
+ @@renderer = renderer
+ end
- # set the renderer to use in the controller
- accept_options :renderer
+ # returns the defined renderer
+ def self.renderer
+ @@renderer
+ end
- # the renderer which can be used to render templates
+ # returns the current renderer
attr_reader :renderer
# initialize the controller
@@ -29,8 +30,8 @@ def self.call(env)
# renderer, request and response.
# @param env [Hash] a rack compatible environment
def initialize(env)
- @request = self.class.request.new(env)
- @response = self.class.response.new
+ @request = Zero::Request.new(env)
+ @response = Zero::Response.new
@renderer = self.class.renderer
end
@@ -6,13 +6,11 @@
let(:env) { EnvGenerator.get('/foo') }
before :each do
- object.renderer(Object.new)
- object.response(Zero::Response)
- object.request(Zero::Request)
+ object.renderer = Object.new
end
it "returns a response" do
- subject.should be_respond_to(:to_a)
+ subject.should respond_to(:to_a)
end
it "returns an object with the first element being a status" do
@@ -26,18 +24,4 @@
r = Zero::Request.new(env)
expect(r.params['foo']).to eq('bar')
end
-
- context "with the response" do
- let(:response_class) { mock }
- before :each do
- object.response(response_class)
- response_class.should_receive(:new).and_return(Zero::Response.new)
- end
-
- after :each do
- Zero::Controller.response(nil)
- end
-
- it { subject }
- end
end
@@ -4,22 +4,17 @@
let(:object) { create_controller }
subject { object.new(env) }
- before do
- object.request(Zero::Request)
- object.response(Zero::Response)
- end
-
let(:env) { EnvGenerator.get('/foo') }
let(:renderer) { mock }
let(:template) { '/foo' }
before :each do
- object.renderer(renderer)
+ object.renderer = renderer
renderer.should_receive(:render).with(template,
kind_of(Zero::Request::AcceptType), subject)
end
after :each do
- Zero::Controller.renderer(nil)
+ Zero::Controller.renderer = nil
end
it { subject.render(template) }
@@ -4,14 +4,8 @@
subject { create_controller }
let(:renderer) { Object.new }
- before do
- subject.response(Zero::Response)
- subject.request(Zero::Request)
- end
-
it 'returns the set renderer' do
- subject.renderer(renderer)
- p subject.renderer
+ subject.renderer = renderer
expect(subject.new({}).renderer).to be(renderer)
end
end

0 comments on commit a2aed1f

Please sign in to comment.