From ecc054352512cac8c0895c78c5f3d043046dcfec Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 15 Jul 2008 18:42:22 -0700 Subject: JavaScriptGenerator should only sets output_buffer for the duration of the update block --- actionpack/test/template/javascript_helper_test.rb | 6 +++++- actionpack/test/template/prototype_helper_test.rb | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index 36dfeba5ed..d41111127b 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -3,7 +3,11 @@ require 'abstract_unit' class JavaScriptHelperTest < ActionView::TestCase tests ActionView::Helpers::JavaScriptHelper - attr_accessor :output_buffer + attr_accessor :template_format, :output_buffer + + def setup + @template = self + end def test_escape_javascript assert_equal '', escape_javascript(nil) diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index 5528430d80..92cc85703b 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -28,7 +28,7 @@ class PrototypeHelperBaseTest < ActionView::TestCase attr_accessor :template_format, :output_buffer def setup - @template = nil + @template = self @controller = Class.new do def url_for(options) if options.is_a?(String) @@ -243,8 +243,12 @@ class PrototypeHelperTest < PrototypeHelperBaseTest end def test_update_page + old_output_buffer = output_buffer + block = Proc.new { |page| page.replace_html('foo', 'bar') } assert_equal create_generator(&block).to_s, update_page(&block) + + assert_equal old_output_buffer, output_buffer end def test_update_page_tag -- cgit v1.2.3 From 8b306bf24c53f698cd83f7d616f2478a6efa5797 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Jul 2008 20:52:29 -0500 Subject: Improved test coverage for fragment cache helper --- actionpack/test/controller/caching_test.rb | 62 +++++++++++++++++----- .../formatted_fragment_cached.html.erb | 3 ++ .../formatted_fragment_cached.js.rjs | 6 +++ .../formatted_fragment_cached.xml.builder | 5 ++ 4 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb create mode 100644 actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs create mode 100644 actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder (limited to 'actionpack/test') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 8f53ecd178..47a0fcf99d 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -148,7 +148,6 @@ class PageCachingTest < Test::Unit::TestCase end end - class ActionCachingTestController < ActionController::Base caches_action :index, :redirected, :forbidden, :if => Proc.new { |c| !c.request.format.json? }, :expires_in => 1.hour caches_action :show, :cache_path => 'http://test.host/custom/show' @@ -489,54 +488,54 @@ class FragmentCachingTest < Test::Unit::TestCase def test_fragment_cache_key assert_equal 'views/what a key', @controller.fragment_cache_key('what a key') - assert_equal( "views/test.host/fragment_caching_test/some_action", - @controller.fragment_cache_key(:controller => 'fragment_caching_test',:action => 'some_action')) + assert_equal "views/test.host/fragment_caching_test/some_action", + @controller.fragment_cache_key(:controller => 'fragment_caching_test',:action => 'some_action') end - def test_read_fragment__with_caching_enabled + def test_read_fragment_with_caching_enabled @store.write('views/name', 'value') assert_equal 'value', @controller.read_fragment('name') end - def test_read_fragment__with_caching_disabled + def test_read_fragment_with_caching_disabled ActionController::Base.perform_caching = false @store.write('views/name', 'value') assert_nil @controller.read_fragment('name') end - def test_fragment_exist__with_caching_enabled + def test_fragment_exist_with_caching_enabled @store.write('views/name', 'value') assert @controller.fragment_exist?('name') assert !@controller.fragment_exist?('other_name') end - def test_fragment_exist__with_caching_disabled + def test_fragment_exist_with_caching_disabled ActionController::Base.perform_caching = false @store.write('views/name', 'value') assert !@controller.fragment_exist?('name') assert !@controller.fragment_exist?('other_name') end - def test_write_fragment__with_caching_enabled + def test_write_fragment_with_caching_enabled assert_nil @store.read('views/name') assert_equal 'value', @controller.write_fragment('name', 'value') assert_equal 'value', @store.read('views/name') end - def test_write_fragment__with_caching_disabled + def test_write_fragment_with_caching_disabled assert_nil @store.read('views/name') ActionController::Base.perform_caching = false assert_equal nil, @controller.write_fragment('name', 'value') assert_nil @store.read('views/name') end - def test_expire_fragment__with_simple_key + def test_expire_fragment_with_simple_key @store.write('views/name', 'value') @controller.expire_fragment 'name' assert_nil @store.read('views/name') end - def test_expire_fragment__with__regexp + def test_expire_fragment_with_regexp @store.write('views/name', 'value') @store.write('views/another_name', 'another_value') @store.write('views/primalgrasp', 'will not expire ;-)') @@ -548,7 +547,7 @@ class FragmentCachingTest < Test::Unit::TestCase assert_equal 'will not expire ;-)', @store.read('views/primalgrasp') end - def test_fragment_for__with_disabled_caching + def test_fragment_for_with_disabled_caching ActionController::Base.perform_caching = false @store.write('views/expensive', 'fragment content') @@ -573,7 +572,6 @@ class FragmentCachingTest < Test::Unit::TestCase end end - class FunctionalCachingController < ActionController::Base def fragment_cached end @@ -590,6 +588,13 @@ class FunctionalCachingController < ActionController::Base end end + def formatted_fragment_cached + respond_to do |format| + format.html + format.xml + format.js + end + end def rescue_action(e) raise e @@ -639,4 +644,35 @@ CACHED assert_match /Fragment caching in a partial/, @response.body assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial') end + + def test_html_formatted_fragment_caching + get :formatted_fragment_cached, :format => "html" + assert_response :success + expected_body = "\n

ERB

\n" + + assert_equal expected_body, @response.body + + assert_equal "

ERB

", @store.read('views/test.host/functional_caching/formatted_fragment_cached') + end + + def test_xml_formatted_fragment_caching + get :formatted_fragment_cached, :format => "xml" + assert_response :success + expected_body = "\n

Builder

\n\n" + + assert_equal expected_body, @response.body + + assert_equal "

Builder

\n", @store.read('views/test.host/functional_caching/formatted_fragment_cached') + end + + def test_js_formatted_fragment_caching + get :formatted_fragment_cached, :format => "js" + assert_response :success + expected_body = %(title = "Hey";\n$("element_1").visualEffect("highlight");\n) + + %($("element_2").visualEffect("highlight");\nfooter = "Bye";) + assert_equal expected_body, @response.body + + assert_equal ['$("element_1").visualEffect("highlight");', '$("element_2").visualEffect("highlight");'], + @store.read('views/test.host/functional_caching/formatted_fragment_cached') + end end diff --git a/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb new file mode 100644 index 0000000000..d7f43ad95e --- /dev/null +++ b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb @@ -0,0 +1,3 @@ + +<% cache do %>

ERB

<% end %> + \ No newline at end of file diff --git a/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs new file mode 100644 index 0000000000..057f15e62f --- /dev/null +++ b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs @@ -0,0 +1,6 @@ +page.assign 'title', 'Hey' +cache do + page['element_1'].visual_effect :highlight + page['element_2'].visual_effect :highlight +end +page.assign 'footer', 'Bye' diff --git a/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder new file mode 100644 index 0000000000..efdcc28e0f --- /dev/null +++ b/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder @@ -0,0 +1,5 @@ +xml.body do + cache do + xml.p "Builder" + end +end -- cgit v1.2.3 From 0f8206104e5dfca1024d1f6bc12a8783c00527e2 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 03:18:09 +0100 Subject: RackRequest#content_type should return Mime::Type --- actionpack/test/controller/rack_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 486fe49737..67ccf1b127 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -166,6 +166,18 @@ class RackRequestParamsParsingTest < BaseRackTest end end +class RackRequestContentTypeTest < BaseRackTest + def test_html_content_type_verification + @request.env['CONTENT_TYPE'] = Mime::HTML.to_s + assert @request.content_type.verify_request? + end + + def test_xml_content_type_verification + @request.env['CONTENT_TYPE'] = Mime::XML.to_s + assert !@request.content_type.verify_request? + end +end + class RackRequestNeedsRewoundTest < BaseRackTest def test_body_should_be_rewound data = 'foo' -- cgit v1.2.3 From 89eec91e670ae267cd88b2b3555bfefe527f0eaa Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 03:31:45 +0100 Subject: Add tests for CgiRequest#content_type --- actionpack/test/controller/cgi_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb index bf3b8b788e..7367036dec 100755 --- a/actionpack/test/controller/cgi_test.rb +++ b/actionpack/test/controller/cgi_test.rb @@ -168,6 +168,18 @@ class CgiRequestParamsParsingTest < BaseCgiTest end end +class CgiRequestContentTypeTest < BaseCgiTest + def test_html_content_type_verification + @request.env['CONTENT_TYPE'] = Mime::HTML.to_s + assert @request.content_type.verify_request? + end + + def test_xml_content_type_verification + @request.env['CONTENT_TYPE'] = Mime::XML.to_s + assert !@request.content_type.verify_request? + end +end + class CgiRequestNeedsRewoundTest < BaseCgiTest def test_body_should_be_rewound data = 'foo' -- cgit v1.2.3 From 3343eb428c502006c40368231a154d8f82be97eb Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 04:09:01 +0100 Subject: Tests for rack response content type --- actionpack/test/controller/rack_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 67ccf1b127..0636a85013 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -246,3 +246,24 @@ class RackResponseTest < BaseRackTest assert_equal ["Hello, World!"], parts end end + +class RackResponseHeadersTest < BaseRackTest + def setup + super + @response = ActionController::RackResponse.new(@request) + @output = StringIO.new('') + @headers = proc { @response.out(@output)[1] } + end + + def test_content_type + [204, 304].each do |c| + @response.headers['Status'] = c + assert !@headers.call.has_key?("Content-Type") + end + + [200, 302, 404, 500].each do |c| + @response.headers['Status'] = c + assert @headers.call.has_key?("Content-Type") + end + end +end -- cgit v1.2.3 From 5cc3ea6969f047a782fa8ac44530baeef597edb3 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 04:17:28 +0100 Subject: RackResponse should not contain Status header --- actionpack/test/controller/rack_test.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 0636a85013..1cef1e0f58 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -252,18 +252,28 @@ class RackResponseHeadersTest < BaseRackTest super @response = ActionController::RackResponse.new(@request) @output = StringIO.new('') - @headers = proc { @response.out(@output)[1] } + @response.headers['Status'] = 200 end def test_content_type [204, 304].each do |c| @response.headers['Status'] = c - assert !@headers.call.has_key?("Content-Type") + assert !response_headers.has_key?("Content-Type") end [200, 302, 404, 500].each do |c| @response.headers['Status'] = c - assert @headers.call.has_key?("Content-Type") + assert response_headers.has_key?("Content-Type") end end + + def test_status + assert !response_headers.has_key?('Status') + end + + private + + def response_headers + @response.out(@output)[1] + end end -- cgit v1.2.3 From 83e29b9773ac113ceacb1e36c2f333d692de2573 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Jul 2008 22:51:16 -0500 Subject: Removed config.action_view.cache_template_loading, use config.cache_classes instead --- actionpack/test/abstract_unit.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 0d2e0f273a..520379fe82 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -22,7 +22,6 @@ ActiveSupport::Deprecation.debug = true ActionController::Base.logger = nil ActionController::Routing::Routes.reload rescue nil -ActionView::Base.cache_template_loading = true FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') ActionController::Base.view_paths = FIXTURE_LOAD_PATH -- cgit v1.2.3 From 1d002f6bcbd4e4f5cc421ee4da5be18839ccc4cb Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 05:01:29 +0100 Subject: Make RackRequest#request_method respect _method --- actionpack/test/controller/cgi_test.rb | 33 +++++++++++++++++++++++++++++++++ actionpack/test/controller/rack_test.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb index 7367036dec..9120458d24 100755 --- a/actionpack/test/controller/cgi_test.rb +++ b/actionpack/test/controller/cgi_test.rb @@ -53,6 +53,14 @@ class BaseCgiTest < Test::Unit::TestCase end def default_test; end + + private + + def set_content_data(data) + @request.env['CONTENT_LENGTH'] = data.length + @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' + @request.env['RAW_POST_DATA'] = data + end end class CgiRequestTest < BaseCgiTest @@ -180,6 +188,31 @@ class CgiRequestContentTypeTest < BaseCgiTest end end +class CgiRequestMethodTest < BaseCgiTest + def test_get + assert_equal :get, @request.request_method + end + + def test_post + @request.env['REQUEST_METHOD'] = 'POST' + assert_equal :post, @request.request_method + end + + def test_put + @request.env['REQUEST_METHOD'] = 'POST' + set_content_data '_method=put' + + assert_equal :put, @request.request_method + end + + def test_delete + @request.env['REQUEST_METHOD'] = 'POST' + set_content_data '_method=delete' + + assert_equal :delete, @request.request_method + end +end + class CgiRequestNeedsRewoundTest < BaseCgiTest def test_body_should_be_rewound data = 'foo' diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 1cef1e0f58..99edb2c901 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -51,6 +51,14 @@ class BaseRackTest < Test::Unit::TestCase end def default_test; end + + private + + def set_content_data(data) + @request.env['CONTENT_LENGTH'] = data.length + @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' + @request.env['RAW_POST_DATA'] = data + end end class RackRequestTest < BaseRackTest @@ -178,6 +186,31 @@ class RackRequestContentTypeTest < BaseRackTest end end +class RackRequestMethodTest < BaseRackTest + def test_get + assert_equal :get, @request.request_method + end + + def test_post + @request.env['REQUEST_METHOD'] = 'POST' + assert_equal :post, @request.request_method + end + + def test_put + @request.env['REQUEST_METHOD'] = 'POST' + set_content_data '_method=put' + + assert_equal :put, @request.request_method + end + + def test_delete + @request.env['REQUEST_METHOD'] = 'POST' + set_content_data '_method=delete' + + assert_equal :delete, @request.request_method + end +end + class RackRequestNeedsRewoundTest < BaseRackTest def test_body_should_be_rewound data = 'foo' -- cgit v1.2.3 From 2a7aca8ec34ebfe0e30dd5e8696918b083ef56f5 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 05:07:34 +0100 Subject: Improve rack/cgi tests --- actionpack/test/controller/cgi_test.rb | 9 +++------ actionpack/test/controller/rack_test.rb | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb index 9120458d24..8ca70f8595 100755 --- a/actionpack/test/controller/cgi_test.rb +++ b/actionpack/test/controller/cgi_test.rb @@ -57,6 +57,7 @@ class BaseCgiTest < Test::Unit::TestCase private def set_content_data(data) + @request.env['REQUEST_METHOD'] = 'POST' @request.env['CONTENT_LENGTH'] = data.length @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' @request.env['RAW_POST_DATA'] = data @@ -163,10 +164,8 @@ end class CgiRequestParamsParsingTest < BaseCgiTest def test_doesnt_break_when_content_type_has_charset - data = 'flamenco=love' - @request.env['CONTENT_LENGTH'] = data.length - @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' - @request.env['RAW_POST_DATA'] = data + set_content_data 'flamenco=love' + assert_equal({"flamenco"=> "love"}, @request.request_parameters) end @@ -199,14 +198,12 @@ class CgiRequestMethodTest < BaseCgiTest end def test_put - @request.env['REQUEST_METHOD'] = 'POST' set_content_data '_method=put' assert_equal :put, @request.request_method end def test_delete - @request.env['REQUEST_METHOD'] = 'POST' set_content_data '_method=delete' assert_equal :delete, @request.request_method diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 99edb2c901..ab8bbc3bf9 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -55,6 +55,7 @@ class BaseRackTest < Test::Unit::TestCase private def set_content_data(data) + @request.env['REQUEST_METHOD'] = 'POST' @request.env['CONTENT_LENGTH'] = data.length @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' @request.env['RAW_POST_DATA'] = data @@ -161,10 +162,8 @@ end class RackRequestParamsParsingTest < BaseRackTest def test_doesnt_break_when_content_type_has_charset - data = 'flamenco=love' - @request.env['CONTENT_LENGTH'] = data.length - @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' - @request.env['RAW_POST_DATA'] = data + set_content_data 'flamenco=love' + assert_equal({"flamenco"=> "love"}, @request.request_parameters) end @@ -197,14 +196,12 @@ class RackRequestMethodTest < BaseRackTest end def test_put - @request.env['REQUEST_METHOD'] = 'POST' set_content_data '_method=put' assert_equal :put, @request.request_method end def test_delete - @request.env['REQUEST_METHOD'] = 'POST' set_content_data '_method=delete' assert_equal :delete, @request.request_method -- cgit v1.2.3 From c64d749abdf31a2be322b1787165024067abbda7 Mon Sep 17 00:00:00 2001 From: Stefan Kaes Date: Wed, 16 Jul 2008 08:26:23 -0500 Subject: Fixed template recompile logic [#630 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/abstract_unit.rb | 1 + .../test/template/compiled_templates_test.rb | 41 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 actionpack/test/template/compiled_templates_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 520379fe82..9db4cddd6a 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -23,6 +23,7 @@ ActionController::Base.logger = nil ActionController::Routing::Routes.reload rescue nil FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') +ActionView::PathSet::Path.eager_load_templates! ActionController::Base.view_paths = FIXTURE_LOAD_PATH # Wrap tests that use Mocha and skip if unavailable. diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb new file mode 100644 index 0000000000..4b34827f91 --- /dev/null +++ b/actionpack/test/template/compiled_templates_test.rb @@ -0,0 +1,41 @@ +require 'abstract_unit' +require 'controller/fake_models' + +uses_mocha 'TestTemplateRecompilation' do + class CompiledTemplatesTest < Test::Unit::TestCase + def setup + @view = ActionView::Base.new(ActionController::Base.view_paths, {}) + @compiled_templates = ActionView::Base::CompiledTemplates + @compiled_templates.instance_methods.each do |m| + @compiled_templates.send(:remove_method, m) if m =~ /^_run_/ + end + end + + def test_template_gets_compiled + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", @view.render("test/hello_world.erb") + assert_equal 1, @compiled_templates.instance_methods.size + end + + def test_template_gets_recompiled_when_using_different_keys_in_local_assigns + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", @view.render("test/hello_world.erb") + assert_equal "Hello world!", @view.render("test/hello_world.erb", {:foo => "bar"}) + assert_equal 2, @compiled_templates.instance_methods.size + end + + def test_compiled_template_will_not_be_recompiled_when_rendered_with_identical_local_assigns + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", @view.render("test/hello_world.erb") + ActionView::Template.any_instance.expects(:compile!).never + assert_equal "Hello world!", @view.render("test/hello_world.erb") + end + + def test_compiled_template_will_always_be_recompiled_when_rendered_if_template_is_outside_cache + assert_equal 0, @compiled_templates.instance_methods.size + assert_equal "Hello world!", @view.render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") + ActionView::Template.any_instance.expects(:compile!).times(3) + 3.times { assert_equal "Hello world!", @view.render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } + end + end +end -- cgit v1.2.3 From 90c930f45c5c6766306929241462ffff8f67b86e Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 18:51:40 +0100 Subject: Allow Dispatcher exceptions to be handled in application.rb using rescue_from --- actionpack/test/controller/rescue_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 27fcc5e04c..da076d2090 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -62,6 +62,11 @@ class RescueController < ActionController::Base render :text => exception.message end + # This is a Dispatcher exception and should be in ApplicationController. + rescue_from ActionController::RoutingError do + render :text => 'no way' + end + def raises render :text => 'already rendered' raise "don't panic!" @@ -378,6 +383,10 @@ class RescueTest < Test::Unit::TestCase assert_equal "RescueController::ResourceUnavailableToRescueAsString", @response.body end + def test_rescue_dispatcher_exceptions + RescueController.process_with_exception(@request, @response, ActionController::RoutingError.new("Route not found")) + assert_equal "no way", @response.body + end protected def with_all_requests_local(local = true) -- cgit v1.2.3 From f7fdbae770275ccbc277c42287b9783cb00fa9fa Mon Sep 17 00:00:00 2001 From: Ripta Pasay Date: Sat, 12 Jul 2008 18:54:24 -0400 Subject: Use fully-qualified controller name when logging. [#600 state:resolved] Signed-off-by: Pratik Naik --- actionpack/test/controller/base_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 34c0200fe8..d49cc2a9aa 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -7,6 +7,7 @@ module Submodule end class ContainedNonEmptyController < ActionController::Base def public_action + render :nothing => true end hide_action :hidden_action @@ -105,6 +106,18 @@ end class PerformActionTest < Test::Unit::TestCase + class MockLogger + attr_reader :logged + + def initialize + @logged = [] + end + + def method_missing(method, *args) + @logged << args.first + end + end + def use_controller(controller_class) @controller = controller_class.new @@ -142,6 +155,13 @@ class PerformActionTest < Test::Unit::TestCase get :another_hidden_action assert_response 404 end + + def test_namespaced_action_should_log_module_name + use_controller Submodule::ContainedNonEmptyController + @controller.logger = MockLogger.new + get :public_action + assert_match /Processing\sSubmodule::ContainedNonEmptyController#public_action/, @controller.logger.logged[1] + end end class DefaultUrlOptionsTest < Test::Unit::TestCase -- cgit v1.2.3 From 99930d499e424f4560b371412e05d10476216ece Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 17 Jul 2008 18:19:09 +0100 Subject: Fix symbol cookie test --- actionpack/test/controller/cookie_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index b45fbb17d3..5a6fb49861 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -60,7 +60,7 @@ class CookieTest < Test::Unit::TestCase end def test_setting_cookie_for_fourteen_days_with_symbols - get :authenticate_for_fourteen_days + get :authenticate_for_fourteen_days_with_symbols assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], @response.headers["cookie"] end -- cgit v1.2.3