diff options
author | Carlhuda <carlhuda@engineyard.com> | 2010-03-17 16:28:05 -0700 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2010-03-17 16:29:35 -0700 |
commit | d9375f3f302a5d1856ad57946c7263d4e6a45a2a (patch) | |
tree | 76769a45da7b1315df173976067ff37edcb59b49 /actionpack/test | |
parent | 7872fa9a4397c450ee22c511966e149d594d153e (diff) | |
download | rails-d9375f3f302a5d1856ad57946c7263d4e6a45a2a.tar.gz rails-d9375f3f302a5d1856ad57946c7263d4e6a45a2a.tar.bz2 rails-d9375f3f302a5d1856ad57946c7263d4e6a45a2a.zip |
Modify assert_template to use notifications. Also, remove ActionController::Base#template since it is no longer needed.
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/action_pack_assertions_test.rb | 8 | ||||
-rw-r--r-- | actionpack/test/controller/filters_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/controller/layout_test.rb | 16 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/template/body_parts_test.rb | 3 | ||||
-rw-r--r-- | actionpack/test/template/erb/form_for_test.rb | 11 | ||||
-rw-r--r-- | actionpack/test/template/erb/helper.rb | 30 | ||||
-rw-r--r-- | actionpack/test/template/erb/tag_helper_test.rb | 40 | ||||
-rw-r--r-- | actionpack/test/template/output_buffer_test.rb | 18 |
9 files changed, 72 insertions, 64 deletions
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index b6810b0c27..1741b58f72 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -181,6 +181,8 @@ module Admin end end +# require "action_dispatch/test_process" + # a test case to exercise the new capabilities TestRequest & TestResponse class ActionPackAssertionsControllerTest < ActionController::TestCase # -- assertion-based testing ------------------------------------------------ @@ -303,14 +305,14 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase # make sure that the template objects exist def test_template_objects_alive process :assign_this - assert !@controller.template.instance_variable_get(:"@hi") - assert @controller.template.instance_variable_get(:"@howdy") + assert !@controller.instance_variable_get(:"@hi") + assert @controller.instance_variable_get(:"@howdy") end # make sure we don't have template objects when we shouldn't def test_template_object_missing process :nothing - assert_nil @controller.template.assigns['howdy'] + assert_nil @controller.instance_variable_get(:@howdy) end # check the empty flashing diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 004e1369d3..ea740f7233 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -651,9 +651,9 @@ class FilterTest < ActionController::TestCase assert_equal %w( ensure_login find_user ), assigns["ran_filter"] test_process(ConditionalSkippingController, "login") - assert_nil @controller.template.controller.instance_variable_get("@ran_after_filter") + assert_nil @controller.instance_variable_get("@ran_after_filter") test_process(ConditionalSkippingController, "change_password") - assert_equal %w( clean_up ), @controller.template.controller.instance_variable_get("@ran_after_filter") + assert_equal %w( clean_up ), @controller.instance_variable_get("@ran_after_filter") end def test_conditional_skipping_of_filters_when_parent_filter_is_also_conditional diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index f635253156..4d687c1ec6 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -120,19 +120,19 @@ class LayoutSetInResponseTest < ActionController::TestCase def test_layout_set_when_using_default_layout @controller = DefaultLayoutController.new get :hello - assert @controller.template.layout.include?('layouts/layout_test') + assert_template :layout => "layouts/layout_test" end def test_layout_set_when_set_in_controller @controller = HasOwnLayoutController.new get :hello - assert @controller.template.layout.include?('layouts/item') + assert_template :layout => "layouts/item" end def test_layout_only_exception_when_included @controller = OnlyLayoutController.new get :hello - assert @controller.template.layout.include?('layouts/item') + assert_template :layout => "layouts/item" end def test_layout_only_exception_when_excepted @@ -144,7 +144,7 @@ class LayoutSetInResponseTest < ActionController::TestCase def test_layout_except_exception_when_included @controller = ExceptLayoutController.new get :hello - assert @controller.template.layout.include?('layouts/item') + assert_template :layout => "layouts/item" end def test_layout_except_exception_when_excepted @@ -156,19 +156,19 @@ class LayoutSetInResponseTest < ActionController::TestCase def test_layout_set_when_using_render @controller = SetsLayoutInRenderController.new get :hello - assert @controller.template.layout.include?('layouts/third_party_template_library') + assert_template :layout => "layouts/third_party_template_library" end def test_layout_is_not_set_when_none_rendered @controller = RendersNoLayoutController.new get :hello - assert_nil @controller.template.layout + assert_template :layout => nil end def test_layout_is_picked_from_the_controller_instances_view_path @controller = PrependsViewPathController.new get :hello - assert @controller.template.layout =~ /layouts\/alt\.\w+/ + assert_template :layout => /layouts\/alt\.\w+/ end def test_absolute_pathed_layout @@ -219,7 +219,7 @@ unless RUBY_PLATFORM =~ /(:?mswin|mingw|bccwin)/ @controller = LayoutSymlinkedTest.new get :hello assert_response 200 - assert @controller.template.layout.include?("layouts/symlinked/symlinked_layout") + assert_template :layout => "layouts/symlinked/symlinked_layout" end end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 20fcb87da6..1d7692f0a8 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -418,7 +418,7 @@ class TestController < ActionController::Base def rendering_with_conflicting_local_vars @name = "David" - def @template.name() nil end + def view_context.name() nil end render :action => "potential_conflicts" end @@ -526,11 +526,11 @@ class TestController < ActionController::Base end def partial_with_form_builder - render :partial => ActionView::Helpers::FormBuilder.new(:post, nil, @template, {}, Proc.new {}) + render :partial => ActionView::Helpers::FormBuilder.new(:post, nil, view_context, {}, Proc.new {}) end def partial_with_form_builder_subclass - render :partial => LabellingFormBuilder.new(:post, nil, @template, {}, Proc.new {}) + render :partial => LabellingFormBuilder.new(:post, nil, view_context, {}, Proc.new {}) end def partial_collection diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb index defe85107e..69cf684083 100644 --- a/actionpack/test/template/body_parts_test.rb +++ b/actionpack/test/template/body_parts_test.rb @@ -8,9 +8,8 @@ class BodyPartsTest < ActionController::TestCase def index RENDERINGS.each do |rendering| - @template.punctuate_body! rendering + view_context.punctuate_body! rendering end - @performed_render = true end end diff --git a/actionpack/test/template/erb/form_for_test.rb b/actionpack/test/template/erb/form_for_test.rb new file mode 100644 index 0000000000..482dbb0287 --- /dev/null +++ b/actionpack/test/template/erb/form_for_test.rb @@ -0,0 +1,11 @@ +require "abstract_unit" +require "template/erb/helper" + +module ERBTest + class TagHelperTest < BlockTestCase + test "form_for works" do + output = render_content "form_for(:staticpage, :url => {:controller => 'blah', :action => 'update'})", "" + assert_equal "<form action=\"/blah/update\" method=\"post\"></form>", output + end + end +end
\ No newline at end of file diff --git a/actionpack/test/template/erb/helper.rb b/actionpack/test/template/erb/helper.rb new file mode 100644 index 0000000000..7147178849 --- /dev/null +++ b/actionpack/test/template/erb/helper.rb @@ -0,0 +1,30 @@ +module ERBTest + class ViewContext + mock_controller = Class.new do + include SharedTestRoutes.url_helpers + end + + include ActionView::Helpers::TagHelper + include ActionView::Helpers::JavaScriptHelper + include ActionView::Helpers::FormHelper + + attr_accessor :output_buffer + + def protect_against_forgery?() false end + + define_method(:controller) do + mock_controller.new + end + end + + class BlockTestCase < ActiveSupport::TestCase + def render_content(start, inside) + template = block_helper(start, inside) + ActionView::Template::Handlers::Erubis.new(template).evaluate(ViewContext.new) + end + + def block_helper(str, rest) + "<%= #{str} do %>#{rest}<% end %>" + end + end +end
\ No newline at end of file diff --git a/actionpack/test/template/erb/tag_helper_test.rb b/actionpack/test/template/erb/tag_helper_test.rb index b5b7ae87de..64a88bde1d 100644 --- a/actionpack/test/template/erb/tag_helper_test.rb +++ b/actionpack/test/template/erb/tag_helper_test.rb @@ -1,36 +1,10 @@ require "abstract_unit" +require "template/erb/helper" module ERBTest - class ViewContext - mock_controller = Class.new do - include SharedTestRoutes.url_helpers - end - - include ActionView::Helpers::TagHelper - include ActionView::Helpers::JavaScriptHelper - include ActionView::Helpers::FormHelper - - attr_accessor :output_buffer - - def protect_against_forgery?() false end - - define_method(:controller) do - mock_controller.new - end - end - - class DeprecatedViewContext < ViewContext - # include ActionView::Helpers::DeprecatedBlockHelpers - end - module SharedTagHelpers extend ActiveSupport::Testing::Declarative - def render_content(start, inside) - template = block_helper(start, inside) - ActionView::Template::Handlers::Erubis.new(template).evaluate(context.new) - end - def maybe_deprecated if @deprecated assert_deprecated { yield } @@ -64,11 +38,7 @@ module ERBTest end end - class TagHelperTest < ActiveSupport::TestCase - def context - ViewContext - end - + class TagHelperTest < BlockTestCase def block_helper(str, rest) "<%= #{str} do %>#{rest}<% end %>" end @@ -76,11 +46,7 @@ module ERBTest include SharedTagHelpers end - class DeprecatedTagHelperTest < ActiveSupport::TestCase - def context - DeprecatedViewContext - end - + class DeprecatedTagHelperTest < BlockTestCase def block_helper(str, rest) "<% __in_erb_template=true %><% #{str} do %>#{rest}<% end %>" end diff --git a/actionpack/test/template/output_buffer_test.rb b/actionpack/test/template/output_buffer_test.rb index 36bbaf9099..9016b74489 100644 --- a/actionpack/test/template/output_buffer_test.rb +++ b/actionpack/test/template/output_buffer_test.rb @@ -19,21 +19,21 @@ class OutputBufferTest < ActionController::TestCase end test 'flushing ignores nil output buffer' do - @controller.template.flush_output_buffer + @controller.view_context.flush_output_buffer assert_nil output_buffer assert_equal ['foo'], body_parts end test 'flushing ignores empty output buffer' do - @controller.template.output_buffer = '' - @controller.template.flush_output_buffer + @controller.view_context.output_buffer = '' + @controller.view_context.flush_output_buffer assert_equal '', output_buffer assert_equal ['foo'], body_parts end test 'flushing appends the output buffer to the body parts' do - @controller.template.output_buffer = 'bar' - @controller.template.flush_output_buffer + @controller.view_context.output_buffer = 'bar' + @controller.view_context.flush_output_buffer assert_equal '', output_buffer assert_equal ['foo', 'bar'], body_parts end @@ -41,8 +41,8 @@ class OutputBufferTest < ActionController::TestCase if '1.9'.respond_to?(:force_encoding) test 'flushing preserves output buffer encoding' do original_buffer = ' '.force_encoding(Encoding::EUC_JP) - @controller.template.output_buffer = original_buffer - @controller.template.flush_output_buffer + @controller.view_context.output_buffer = original_buffer + @controller.view_context.flush_output_buffer assert_equal ['foo', original_buffer], body_parts assert_not_equal original_buffer, output_buffer assert_equal Encoding::EUC_JP, output_buffer.encoding @@ -51,10 +51,10 @@ class OutputBufferTest < ActionController::TestCase protected def output_buffer - @controller.template.output_buffer + @controller.view_context.output_buffer end def body_parts - @controller.template.response.body_parts + @controller.response.body_parts end end |