From 216309c16519d94a9e0aebf758029a78696ab8d6 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Tue, 12 May 2009 16:21:34 -0700 Subject: Implemented redirects and partial rendering in new base. --- actionpack/test/abstract_unit.rb | 4 ++ actionpack/test/abstract_unit2.rb | 69 +++++++++++++++---------------- actionpack/test/controller/render_test.rb | 4 +- actionpack/test/new_base/redirect_test.rb | 1 + 4 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 actionpack/test/new_base/redirect_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index b07e6e5f3a..825ac9a46c 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -1,3 +1,6 @@ +if ENV["new_base"] + require "abstract_unit2" +else $:.unshift(File.dirname(__FILE__) + '/../lib') $:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib') $:.unshift(File.dirname(__FILE__) + '/fixtures/helpers') @@ -38,3 +41,4 @@ ORIGINAL_LOCALES = I18n.available_locales.map(&:to_s).sort FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') ActionController::Base.view_paths = FIXTURE_LOAD_PATH +end \ No newline at end of file diff --git a/actionpack/test/abstract_unit2.rb b/actionpack/test/abstract_unit2.rb index 95e7b2e273..2fdaba7342 100644 --- a/actionpack/test/abstract_unit2.rb +++ b/actionpack/test/abstract_unit2.rb @@ -75,7 +75,7 @@ module ActionController end class Base - use ActionController::Testing + include ActionController::Testing end Base.view_paths = FIXTURE_LOAD_PATH @@ -89,43 +89,42 @@ module ActionController end def assert_template(options = {}, message = nil) - validate_response! - - clean_backtrace do - case options - when NilClass, String - hax = @controller._action_view.instance_variable_get(:@_rendered) - rendered = (hax[:template] || []).map { |t| t.identifier } - msg = build_message(message, - "expecting but rendering with ", - options, rendered.join(', ')) - assert_block(msg) do - if options.nil? - hax[:template].blank? - else - rendered.any? { |t| t.match(options) } - end + validate_request! + + hax = @controller._action_view.instance_variable_get(:@_rendered) + + case options + when NilClass, String + rendered = (hax[:template] || []).map { |t| t.identifier } + msg = build_message(message, + "expecting but rendering with ", + options, rendered.join(', ')) + assert_block(msg) do + if options.nil? + hax[:template].blank? + else + rendered.any? { |t| t.match(options) } end - when Hash - if expected_partial = options[:partial] - partials = hax[:partials] - if expected_count = options[:count] - found = partials.detect { |p, _| p.identifier.match(expected_partial) } - actual_count = found.nil? ? 0 : found.second - msg = build_message(message, - "expecting ? to be rendered ? time(s) but rendered ? time(s)", - expected_partial, expected_count, actual_count) - assert(actual_count == expected_count.to_i, msg) - else - msg = build_message(message, - "expecting partial but action rendered ", - options[:partial], partials.keys) - assert(partials.keys.any? { |p| p.identifier.match(expected_partial) }, msg) - end + end + when Hash + if expected_partial = options[:partial] + partials = hax[:partials] + if expected_count = options[:count] + found = partials.detect { |p, _| p.identifier.match(expected_partial) } + actual_count = found.nil? ? 0 : found.second + msg = build_message(message, + "expecting ? to be rendered ? time(s) but rendered ? time(s)", + expected_partial, expected_count, actual_count) + assert(actual_count == expected_count.to_i, msg) else - assert hax[:partials].empty?, - "Expected no partials to be rendered" + msg = build_message(message, + "expecting partial but action rendered ", + options[:partial], partials.keys) + assert(partials.keys.any? { |p| p.identifier.match(expected_partial) }, msg) end + else + assert hax[:partials].empty?, + "Expected no partials to be rendered" end end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index a58d9b08b5..4cea050a1e 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1,4 +1,4 @@ -require ENV['new_base'] ? 'abstract_unit2' : 'abstract_unit' +require 'abstract_unit' require 'controller/fake_models' require 'pathname' @@ -1647,7 +1647,7 @@ class EtagRenderTest < ActionController::TestCase def test_render_against_etag_request_should_304_when_match @request.if_none_match = etag_for("hello david") get :render_hello_world_from_variable - assert_equal 304, @response.status + assert_equal 304, @response.status.to_i assert @response.body.empty? end diff --git a/actionpack/test/new_base/redirect_test.rb b/actionpack/test/new_base/redirect_test.rb new file mode 100644 index 0000000000..e591ebd05f --- /dev/null +++ b/actionpack/test/new_base/redirect_test.rb @@ -0,0 +1 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") \ No newline at end of file -- cgit v1.2.3