summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/zero/controller.rb17
-rw-r--r--spec/unit/controller/render_spec.rb19
2 files changed, 32 insertions, 4 deletions
diff --git a/lib/zero/controller.rb b/lib/zero/controller.rb
index b42e500..ce9e247 100644
--- a/lib/zero/controller.rb
+++ b/lib/zero/controller.rb
@@ -56,13 +56,22 @@ module Zero
# build the response and return it
#
- # This method calls #process if it was defined so make it easier to process
- # the request before rendering stuff.
+ # This method calls #process. #process has to be provided by the actual
+ # implementation and should do all processing necessary to provide the
+ # content.
# @return Response a rack conform response
def response
- process if respond_to?(:process)
- render
+ process
@response.to_a
end
+
+ # renders a template
+ #
+ # This method calls #render of the provided renderer and gives it the
+ # template name and accept types, so that the renderer can search for the
+ # appropiate template to render.
+ def render(template)
+ @renderer.render(template, @request.accept.types, self)
+ end
end
end
diff --git a/spec/unit/controller/render_spec.rb b/spec/unit/controller/render_spec.rb
new file mode 100644
index 0000000..771db28
--- /dev/null
+++ b/spec/unit/controller/render_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe Zero::Controller, '#render' do
+ subject { Zero::Controller.new(env) }
+ let(:env) { EnvGenerator.get('/foo') }
+ let(:renderer) { mock }
+ let(:template) { '/foo' }
+
+ before :each do
+ Zero::Controller.renderer = renderer
+ renderer.should_receive(:render).with(template,
+ kind_of(Zero::Request::AcceptType), subject)
+ end
+ after :each do
+ Zero::Controller.renderer = nil
+ end
+
+ it { subject.render(template) }
+end