diff options
author | Ryan Bigg <radarlistener@gmail.com> | 2008-10-06 11:57:12 +1030 |
---|---|---|
committer | Ryan Bigg <radarlistener@gmail.com> | 2008-10-06 11:57:12 +1030 |
commit | a21d8f632fe8aa3bf4c1b83accc7a2dd230c28e7 (patch) | |
tree | bb0b0e9423d4e259de6041e661bba119f7871faa /actionpack/test | |
parent | b340337aaff5b59fdf2110207fec3e1c43f1380a (diff) | |
parent | 6090513cfb8acb5554a6653a6f2cb87648585d41 (diff) | |
download | rails-a21d8f632fe8aa3bf4c1b83accc7a2dd230c28e7.tar.gz rails-a21d8f632fe8aa3bf4c1b83accc7a2dd230c28e7.tar.bz2 rails-a21d8f632fe8aa3bf4c1b83accc7a2dd230c28e7.zip |
Merge branch 'master' of git@github.com:lifo/docrails
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/abstract_unit.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 41 | ||||
-rw-r--r-- | actionpack/test/controller/rescue_test.rb | 35 | ||||
-rw-r--r-- | actionpack/test/template/form_tag_helper_test.rb | 6 |
4 files changed, 58 insertions, 26 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 9db4cddd6a..673efa6af0 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -1,5 +1,5 @@ $:.unshift(File.dirname(__FILE__) + '/../lib') -$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib/active_support') +$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib') $:.unshift(File.dirname(__FILE__) + '/fixtures/helpers') require 'yaml' diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index af7b5dde62..5a6ca98b2e 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -39,6 +39,16 @@ class TestController < ActionController::Base render :action => 'hello_world' end end + + def conditional_hello_with_bangs + render :action => 'hello_world' + end + before_filter :handle_last_modified_and_etags, :only=>:conditional_hello_with_bangs + + def handle_last_modified_and_etags + last_modified! Time.now.utc.beginning_of_day + etag! [:foo, 123] + end def render_hello_world render :template => "test/hello_world" @@ -1306,6 +1316,7 @@ class EtagRenderTest < Test::Unit::TestCase @controller = TestController.new @request.host = "www.nextangle.com" + @expected_bang_etag = etag_for(expand_key([:foo, 123])) end def test_render_200_should_set_etag @@ -1365,11 +1376,27 @@ class EtagRenderTest < Test::Unit::TestCase assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body assert_equal etag_for("<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n"), @response.headers['ETag'] end - + + def test_etag_with_bang_should_set_etag + get :conditional_hello_with_bangs + assert_equal @expected_bang_etag, @response.headers["ETag"] + assert_response :success + end + + def test_etag_with_bang_should_obey_if_none_match + @request.if_none_match = @expected_bang_etag + get :conditional_hello_with_bangs + assert_response :not_modified + end + protected def etag_for(text) %("#{Digest::MD5.hexdigest(text)}") end + + def expand_key(args) + ActiveSupport::Cache.expand_cache_key(args) + end end class LastModifiedRenderTest < Test::Unit::TestCase @@ -1402,6 +1429,18 @@ class LastModifiedRenderTest < Test::Unit::TestCase assert !@response.body.blank? assert_equal @last_modified, @response.headers['Last-Modified'] end + + def test_request_with_bang_gets_last_modified + get :conditional_hello_with_bangs + assert_equal @last_modified, @response.headers['Last-Modified'] + assert_response :success + end + + def test_request_with_bang_obeys_last_modified + @request.if_modified_since = @last_modified + get :conditional_hello_with_bangs + assert_response :not_modified + end end class RenderingLoggingTest < Test::Unit::TestCase diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index da076d2090..32c6c013f1 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -75,7 +75,7 @@ class RescueController < ActionController::Base def method_not_allowed raise ActionController::MethodNotAllowed.new(:get, :head, :put) end - + def not_implemented raise ActionController::NotImplemented.new(:get, :put) end @@ -107,7 +107,7 @@ class RescueController < ActionController::Base def record_invalid_raise_as_string raise RecordInvalidToRescueAsString end - + def bad_gateway raise BadGateway end @@ -135,18 +135,19 @@ class RescueController < ActionController::Base end end -class RescueTest < Test::Unit::TestCase +class RescueControllerTest < ActionController::TestCase FIXTURE_PUBLIC = "#{File.dirname(__FILE__)}/../fixtures".freeze - def setup - @controller = RescueController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + setup :set_all_requests_local + setup :populate_exception_object + def set_all_requests_local RescueController.consider_all_requests_local = true @request.remote_addr = '1.2.3.4' @request.host = 'example.com' + end + def populate_exception_object begin raise 'foo' rescue => @exception @@ -307,7 +308,7 @@ class RescueTest < Test::Unit::TestCase assert_nil @controller.send(:clean_backtrace, Exception.new) end end - + def test_not_implemented with_all_requests_local false do with_rails_public_path(".") do @@ -463,14 +464,7 @@ class ExceptionInheritanceRescueController < ActionController::Base end end -class ExceptionInheritanceRescueTest < Test::Unit::TestCase - - def setup - @controller = ExceptionInheritanceRescueController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - +class ExceptionInheritanceRescueControllerTest < ActionController::TestCase def test_bottom_first get :raise_grandchild_exception assert_response :no_content @@ -500,14 +494,7 @@ class ControllerInheritanceRescueController < ExceptionInheritanceRescueControll end end -class ControllerInheritanceRescueControllerTest < Test::Unit::TestCase - - def setup - @controller = ControllerInheritanceRescueController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - +class ControllerInheritanceRescueControllerTest < ActionController::TestCase def test_first_exception_in_child_controller get :raise_first_exception_in_child_controller assert_response :gone diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 6473d011d5..ad8baef5e4 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -271,6 +271,12 @@ class FormTagHelperTest < ActionView::TestCase expected = %(<fieldset>Hello world!</fieldset>) assert_dom_equal expected, output_buffer + + self.output_buffer = '' + field_set_tag('', :class => 'format') { concat "Hello world!" } + + expected = %(<fieldset class="format">Hello world!</fieldset>) + assert_dom_equal expected, output_buffer end def protect_against_forgery? |