diff options
author | Łukasz Strzałkowski <lukasz.strzalkowski@gmail.com> | 2013-08-11 23:19:22 +0200 |
---|---|---|
committer | Łukasz Strzałkowski <lukasz.strzalkowski@gmail.com> | 2013-08-25 11:40:10 +0200 |
commit | a2ca04bb3ac178bbe1503ac65dc88f5f3f8cb37f (patch) | |
tree | 22857d7f2c78d12f6dfcd4b8a03e8dfa560af792 /actionpack | |
parent | c40c362ec1ac9ec96e92ddb046b67b713a434e48 (diff) | |
download | rails-a2ca04bb3ac178bbe1503ac65dc88f5f3f8cb37f.tar.gz rails-a2ca04bb3ac178bbe1503ac65dc88f5f3f8cb37f.tar.bz2 rails-a2ca04bb3ac178bbe1503ac65dc88f5f3f8cb37f.zip |
Extend basic rendering, test it in railties
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/metal/rendering.rb | 19 | ||||
-rw-r--r-- | actionpack/test/controller/basic_rendering_test.rb | 19 |
2 files changed, 16 insertions, 22 deletions
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index 2d58e1440c..d965cb8c16 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -6,15 +6,28 @@ module ActionController # :api: public def render(*args, &block) super(*args, &block) - text = args.first[:text] - if text.present? - self.response_body = text + opts = args.first + if (opts.keys & [:text, :nothing]).present? + self.response_body = if opts.has_key?(:text) && opts[:text].present? + opts[:text] + elsif opts.has_key?(:nothing) && opts[:nothing] + " " + end + else + raise UnsupportedOperationError end end def rendered_format Mime::TEXT end + + class UnsupportedOperationError < StandardError + def initialize + super "Unsupported render operation. BasicRendering supports only :text + and :nothing options. For more, you need to include ActionView." + end + end end module Rendering diff --git a/actionpack/test/controller/basic_rendering_test.rb b/actionpack/test/controller/basic_rendering_test.rb deleted file mode 100644 index 2db3cff395..0000000000 --- a/actionpack/test/controller/basic_rendering_test.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'abstract_unit' - -class BasicRenderingController < ActionController::Base - def render_hello_world - render text: "Hello World!" - end -end - -class BasicRenderingTest < ActionController::TestCase - tests BasicRenderingController - - def test_render_hello_world - get :render_hello_world - - assert_equal "Hello World!", @response.body - assert_equal "text/plain", @response.content_type - end -end -
\ No newline at end of file |