diff options
Diffstat (limited to 'actionpack/test')
43 files changed, 195 insertions, 237 deletions
diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract_controller/layouts_test.rb index 37eb55ec98..b28df7743f 100644 --- a/actionpack/test/abstract_controller/layouts_test.rb +++ b/actionpack/test/abstract_controller/layouts_test.rb @@ -9,7 +9,7 @@ module AbstractControllerTests include AbstractController::Renderer include AbstractController::Layouts - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "layouts/hello.erb" => "With String <%= yield %>", "layouts/hello_override.erb" => "With Override <%= yield %>", "layouts/abstract_controller_tests/layouts/with_string_implied_child.erb" => diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 1333a9d71a..30e795a7a2 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -1,5 +1,6 @@ $:.unshift(File.dirname(__FILE__) + '/../lib') $:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib') +$:.unshift(File.dirname(__FILE__) + '/../../activemodel/lib') $:.unshift(File.dirname(__FILE__) + '/lib') $:.unshift(File.dirname(__FILE__) + '/fixtures/helpers') diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb index b9f5be2361..2036d1eeb5 100644 --- a/actionpack/test/activerecord/polymorphic_routes_test.rb +++ b/actionpack/test/activerecord/polymorphic_routes_test.rb @@ -234,10 +234,13 @@ class PolymorphicRoutesTest < ActionController::TestCase with_admin_test_routes do @project.save @task.save + + options = {} object_array = [:admin, @project, @task] - assert_no_difference 'object_array.size' do - polymorphic_url(object_array) - end + original_args = [object_array.dup, options.dup] + + assert_no_difference('object_array.size') { polymorphic_path(object_array, options) } + assert_equal original_args, [object_array, options] end end diff --git a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb index 0a596c7ae0..2a31f3be44 100644 --- a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb +++ b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb @@ -126,6 +126,7 @@ class RenderPartialWithRecordIdentificationController < ActionController::Base end class Game < Struct.new(:name, :id) + extend ActiveModel::Naming def to_param id.to_s end diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 24686ab4b6..ecbaba39d1 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -13,6 +13,18 @@ class ActionPackAssertionsController < ActionController::Base # a standard template def hello_xml_world() render :template => "test/hello_xml_world"; end + # a standard template rendering PDF + def hello_xml_world_pdf + self.content_type = "application/pdf" + render :template => "test/hello_xml_world" + end + + # a standard template rendering PDF + def hello_xml_world_pdf_header + response.headers["Content-Type"] = "application/pdf; charset=utf-8" + render :template => "test/hello_xml_world" + end + # a standard partial def partial() render :partial => 'test/partial'; end @@ -537,11 +549,13 @@ class ActionPackHeaderTest < ActionController::TestCase end def test_rendering_xml_respects_content_type - pending do - @response.headers['type'] = 'application/pdf' - process :hello_xml_world - assert_equal('application/pdf; charset=utf-8', @response.headers['Content-Type']) - end + process :hello_xml_world_pdf + assert_equal('application/pdf; charset=utf-8', @response.headers['Content-Type']) + end + + def test_rendering_xml_respects_content_type_when_set_in_the_header + process :hello_xml_world_pdf_header + assert_equal('application/pdf; charset=utf-8', @response.headers['Content-Type']) end def test_render_text_with_custom_content_type diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 03fd98a85c..8877057070 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -146,11 +146,7 @@ class PerformActionTest < ActionController::TestCase def test_method_missing_is_not_an_action_name use_controller MethodMissingController - if defined?(ActionController::Http) - assert ! @controller.__send__(:action_method?, 'method_missing') - else - assert ! @controller.__send__(:action_methods).include?('method_missing') - end + assert ! @controller.__send__(:action_method?, 'method_missing') get :method_missing assert_response :success diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index b930ff4997..2da97a9d86 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -9,24 +9,20 @@ class ActionController::Base end unless method_defined?(pending) end - if defined?(ActionController::Http) - def before_filters - filters = _process_action_callbacks.select { |c| c.kind == :before } - filters.map! { |c| c.instance_variable_get(:@raw_filter) } - end + def before_filters + filters = _process_action_callbacks.select { |c| c.kind == :before } + filters.map! { |c| c.instance_variable_get(:@raw_filter) } end end - if defined?(ActionController::Http) - def assigns(key = nil) - assigns = {} - instance_variable_names.each do |ivar| - next if ActionController::Base.protected_instance_variables.include?(ivar) - assigns[ivar[1..-1]] = instance_variable_get(ivar) - end - - key.nil? ? assigns : assigns[key.to_s] + def assigns(key = nil) + assigns = {} + instance_variable_names.each do |ivar| + next if ActionController::Base.protected_instance_variables.include?(ivar) + assigns[ivar[1..-1]] = instance_variable_get(ivar) end + + key.nil? ? assigns : assigns[key.to_s] end end @@ -598,22 +594,11 @@ class FilterTest < ActionController::TestCase assert_equal "before and after", assigns["execution_log"] end - for_tag(:old_base) do - def test_prepending_and_appending_around_filter - controller = test_process(MixedFilterController) - assert_equal " before aroundfilter before procfilter before appended aroundfilter " + - " after appended aroundfilter after aroundfilter after procfilter ", - MixedFilterController.execution_log - end - end - - for_tag(:new_base) do - def test_prepending_and_appending_around_filter - controller = test_process(MixedFilterController) - assert_equal " before aroundfilter before procfilter before appended aroundfilter " + - " after appended aroundfilter after procfilter after aroundfilter ", - MixedFilterController.execution_log - end + def test_prepending_and_appending_around_filter + controller = test_process(MixedFilterController) + assert_equal " before aroundfilter before procfilter before appended aroundfilter " + + " after appended aroundfilter after procfilter after aroundfilter ", + MixedFilterController.execution_log end def test_rendering_breaks_filtering_chain @@ -876,14 +861,6 @@ class YieldingAroundFiltersTest < ActionController::TestCase assert_raise(After) { test_process(controller,'raises_after') } end - for_tag(:old_base) do - def test_with_method - controller = ControllerWithFilterMethod - assert_nothing_raised { test_process(controller,'no_raise') } - assert_raise(After) { test_process(controller,'raises_after') } - end - end - def test_with_proc test_process(ControllerWithProcFilter,'no_raise') assert assigns['before'] @@ -906,18 +883,9 @@ class YieldingAroundFiltersTest < ActionController::TestCase end end - for_tag(:old_base) do - def test_filter_order_with_all_filter_types - test_process(ControllerWithAllTypesOfFilters,'no_raise') - assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) around (after yield) after', assigns['ran_filter'].join(' ') - end - end - - for_tag(:new_base) do - def test_filter_order_with_all_filter_types - test_process(ControllerWithAllTypesOfFilters,'no_raise') - assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) after around (after yield)', assigns['ran_filter'].join(' ') - end + def test_filter_order_with_all_filter_types + test_process(ControllerWithAllTypesOfFilters,'no_raise') + assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) after around (after yield)', assigns['ran_filter'].join(' ') end def test_filter_order_with_skip_filter_method diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index 515c4c9f52..23149fee27 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -127,11 +127,7 @@ class HelperTest < Test::Unit::TestCase end def test_all_helpers - methods = if defined?(ActionController::Http) - AllHelpersController._helpers.instance_methods.map {|m| m.to_s} - else - AllHelpersController.master_helper_module.instance_methods.map {|m| m.to_s} - end + methods = AllHelpersController._helpers.instance_methods.map {|m| m.to_s} # abc_helper.rb assert methods.include?('bare_a') @@ -147,12 +143,7 @@ class HelperTest < Test::Unit::TestCase @controller_class.helpers_dir = File.dirname(__FILE__) + '/../fixtures/alternate_helpers' # Reload helpers - if defined?(ActionController::Http) - @controller_class._helpers = Module.new - else - @controller_class.master_helper_module = Module.new - end - + @controller_class._helpers = Module.new @controller_class.helper :all # helpers/abc_helper.rb should not be included @@ -184,11 +175,7 @@ class HelperTest < Test::Unit::TestCase end def master_helper_methods - if defined?(ActionController::Http) - @controller_class._helpers.instance_methods.map {|m| m.to_s } - else - @controller_class.master_helper_module.instance_methods.map {|m| m.to_s } - end + @controller_class._helpers.instance_methods.map {|m| m.to_s } end def missing_methods diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index c3d7b0778d..feb2f81cc1 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -165,26 +165,10 @@ class LayoutSetInResponseTest < ActionController::TestCase assert_nil @controller.template.layout end - for_tag(:old_base) do - # exempt_from_layout is deprecated - def test_exempt_from_layout_honored_by_render_template - ActionController::Base.exempt_from_layout :erb - @controller = RenderWithTemplateOptionController.new - - get :hello - assert_equal "alt/hello.rhtml", @response.body.strip - - ensure - ActionController::Base.exempt_from_layout.delete(ERB) - end - end - def test_layout_is_picked_from_the_controller_instances_view_path - pending do - @controller = PrependsViewPathController.new - get :hello - assert_equal 'layouts/alt', @controller.template.layout - end + @controller = PrependsViewPathController.new + get :hello + assert @controller.template.layout =~ /layouts\/alt\.\w+/ end def test_absolute_pathed_layout diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 0c6822a5b1..93ca34c41c 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -375,11 +375,9 @@ class MimeControllerTest < ActionController::TestCase end def test_rjs_type_skips_layout - pending(:new_base) do - @request.accept = "text/javascript" - get :all_types_with_layout - assert_equal 'RJS for all_types_with_layout', @response.body - end + @request.accept = "text/javascript" + get :all_types_with_layout + assert_equal 'RJS for all_types_with_layout', @response.body end def test_html_type_with_layout @@ -467,14 +465,6 @@ class MimeControllerTest < ActionController::TestCase assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body assert_equal "text/html", @response.content_type end - - def test_format_with_custom_response_type_and_request_headers_with_only_one_layout_present - get :iphone_with_html_response_type_without_layout - assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body - - @request.accept = "text/iphone" - assert_raise(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout } - end end class AbstractPostController < ActionController::Base @@ -529,16 +519,14 @@ class MimeControllerLayoutsTest < ActionController::TestCase assert_equal 'Hello iPhone', @response.body end - for_tag(:old_base) do - def test_format_with_inherited_layouts - @controller = SuperPostController.new + def test_format_with_inherited_layouts + @controller = SuperPostController.new - get :index - assert_equal 'Super Firefox', @response.body + get :index + assert_equal '<html><div id="html">Super Firefox</div></html>', @response.body - @request.accept = "text/iphone" - get :index - assert_equal '<html><div id="super_iphone">Super iPhone</div></html>', @response.body - end + @request.accept = "text/iphone" + get :index + assert_equal '<html><div id="super_iphone">Super iPhone</div></html>', @response.body end end diff --git a/actionpack/test/controller/record_identifier_test.rb b/actionpack/test/controller/record_identifier_test.rb index 12c1eaea69..28bc608d47 100644 --- a/actionpack/test/controller/record_identifier_test.rb +++ b/actionpack/test/controller/record_identifier_test.rb @@ -1,6 +1,8 @@ require 'abstract_unit' class Comment + extend ActiveModel::Naming + attr_reader :id def save; @id = 1 end def new_record?; @id.nil? end diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 13247f2d08..453a77e7bc 100644 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -4,6 +4,7 @@ class WorkshopsController < ActionController::Base end class Workshop + extend ActiveModel::Naming attr_accessor :id, :new_record def initialize(id, new_record) diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 9e42d1738a..9934639d21 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -301,6 +301,9 @@ class TestController < ActionController::Base def render_implicit_html_template_from_xhr_request end + def render_implicit_js_template_without_layout + end + def formatted_html_erb end @@ -928,16 +931,13 @@ class RenderTest < ActionController::TestCase end def test_should_implicitly_render_html_template_from_xhr_request - pending - # xhr :get, :render_implicit_html_template_from_xhr_request - # assert_equal "XHR!\nHello HTML!", @response.body + xhr :get, :render_implicit_html_template_from_xhr_request + assert_equal "XHR!\nHello HTML!", @response.body end def test_should_implicitly_render_js_template_without_layout - pending do - get :render_implicit_js_template_without_layout, :format => :js - assert_no_match %r{<html>}, @response.body - end + get :render_implicit_js_template_without_layout, :format => :js + assert_no_match %r{<html>}, @response.body end def test_should_render_formatted_template diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 4134da3b9e..d88d5c5dac 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -45,8 +45,8 @@ class SendFileTest < ActionController::TestCase assert_equal file_data, response.body end - for_tag(:old_base) do - def test_file_stream + def test_file_stream + pending do response = nil assert_nothing_raised { response = process('file') } assert_not_nil response diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index 27bdd10ee5..4ea0fedb8f 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -56,7 +56,7 @@ class MimeTypeTest < ActiveSupport::TestCase test "type convenience methods" do # Don't test Mime::ALL, since it Mime::ALL#html? == true - types = Mime::SET.to_a.map{|m| m.to_sym }.uniq - [:all] + types = Mime::SET.symbols.uniq - [:all] # Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) } @@ -76,7 +76,7 @@ class MimeTypeTest < ActiveSupport::TestCase end test "verifiable mime types" do - all_types = Mime::SET.to_a.map{|m| m.to_sym} + all_types = Mime::SET.symbols all_types.uniq! # Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE all_types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) } diff --git a/actionpack/test/fixtures/layouts/builder.builder b/actionpack/test/fixtures/layouts/builder.builder index 729af4b8bc..7c7d4b2dd1 100644 --- a/actionpack/test/fixtures/layouts/builder.builder +++ b/actionpack/test/fixtures/layouts/builder.builder @@ -1,3 +1,3 @@ xml.wrapper do - xml << @content_for_layout + xml << yield end
\ No newline at end of file diff --git a/actionpack/test/fixtures/layouts/standard.html.erb b/actionpack/test/fixtures/layouts/standard.html.erb index 368764e6f4..5e6c24fe39 100644 --- a/actionpack/test/fixtures/layouts/standard.html.erb +++ b/actionpack/test/fixtures/layouts/standard.html.erb @@ -1 +1 @@ -<html><%= @content_for_layout %><%= @variable_for_layout %></html>
\ No newline at end of file +<html><%= yield %><%= @variable_for_layout %></html>
\ No newline at end of file diff --git a/actionpack/test/fixtures/layouts/talk_from_action.erb b/actionpack/test/fixtures/layouts/talk_from_action.erb index 187aab07a2..bf53fdb785 100644 --- a/actionpack/test/fixtures/layouts/talk_from_action.erb +++ b/actionpack/test/fixtures/layouts/talk_from_action.erb @@ -1,2 +1,2 @@ -<title><%= @title || @content_for_title %></title> -<%= @content_for_layout -%>
\ No newline at end of file +<title><%= @title || yield(:title) %></title> +<%= yield -%>
\ No newline at end of file diff --git a/actionpack/test/fixtures/test/render_implicit_js_template_without_layout.js.erb b/actionpack/test/fixtures/test/render_implicit_js_template_without_layout.js.erb new file mode 100644 index 0000000000..892ae5eca2 --- /dev/null +++ b/actionpack/test/fixtures/test/render_implicit_js_template_without_layout.js.erb @@ -0,0 +1 @@ +alert('hello');
\ No newline at end of file diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb index 0b30c79b10..9e6f14d373 100644 --- a/actionpack/test/lib/controller/fake_models.rb +++ b/actionpack/test/lib/controller/fake_models.rb @@ -1,4 +1,8 @@ +require "active_model" + class Customer < Struct.new(:name, :id) + extend ActiveModel::Naming + def to_param id.to_s end @@ -12,6 +16,8 @@ end module Quiz class Question < Struct.new(:name, :id) + extend ActiveModel::Naming + def to_param id.to_s end diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/test/lib/fixture_template.rb index 59fb6819ed..5cf414a1c6 100644 --- a/actionpack/test/lib/fixture_template.rb +++ b/actionpack/test/lib/fixture_template.rb @@ -1,6 +1,5 @@ module ActionView #:nodoc: -class Template - class FixturePath < Path + class FixtureResolver < Resolver def initialize(hash = {}, options = {}) super(options) @hash = hash @@ -22,7 +21,7 @@ class Template def formats_regexp @formats_regexp ||= begin - formats = Mime::SET.map { |m| m.symbol } + formats = Mime::SET.symbols '(?:' + formats.map { |l| "\\.#{Regexp.escape(l.to_s)}" }.join('|') + ')?' end end @@ -65,40 +64,4 @@ class Template end end end - - - # class FixtureTemplate < Template - # class FixturePath < Template::Path - # def initialize(hash = {}) - # @hash = {} - # - # hash.each do |k, v| - # @hash[k.sub(/\.\w+$/, '')] = FixtureTemplate.new(v, k.split("/").last, self) - # end - # - # super("fixtures://root") - # end - # - # def find_template(path) - # @hash[path] - # end - # end - # - # def initialize(body, *args) - # @body = body - # super(*args) - # end - # - # def source - # @body - # end - # - # private - # - # def find_full_path(path, load_paths) - # return '/', path - # end - # - # end -end end
\ No newline at end of file diff --git a/actionpack/test/new_base/content_type_test.rb b/actionpack/test/new_base/content_type_test.rb index 82b817a5a3..cfc03a3024 100644 --- a/actionpack/test/new_base/content_type_test.rb +++ b/actionpack/test/new_base/content_type_test.rb @@ -19,7 +19,7 @@ module ContentType class ImpliedController < ActionController::Base # Template's mime type is used if no content_type is specified - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "content_type/implied/i_am_html_erb.html.erb" => "Hello world!", "content_type/implied/i_am_xml_erb.xml.erb" => "<xml>Hello world!</xml>", "content_type/implied/i_am_html_builder.html.builder" => "xml.p 'Hello'", diff --git a/actionpack/test/new_base/etag_test.rb b/actionpack/test/new_base/etag_test.rb index a40d3c936a..3a69e7dac4 100644 --- a/actionpack/test/new_base/etag_test.rb +++ b/actionpack/test/new_base/etag_test.rb @@ -2,7 +2,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") module Etags class BasicController < ActionController::Base - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "etags/basic/base.html.erb" => "Hello from without_layout.html.erb", "layouts/etags.html.erb" => "teh <%= yield %> tagz" )] diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb index 4402eadf42..dfa7cc2141 100644 --- a/actionpack/test/new_base/render_action_test.rb +++ b/actionpack/test/new_base/render_action_test.rb @@ -3,7 +3,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") module RenderAction # This has no layout and it works class BasicController < ActionController::Base - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "render_action/basic/hello_world.html.erb" => "Hello world!" )] @@ -117,7 +117,7 @@ module RenderActionWithApplicationLayout # # ==== Render actions with layouts ==== class BasicController < ::ApplicationController # Set the view path to an application view structure with layouts - self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = self.view_paths = [ActionView::FixtureResolver.new( "render_action_with_application_layout/basic/hello_world.html.erb" => "Hello World!", "render_action_with_application_layout/basic/hello.html.builder" => "xml.p 'Omg'", "layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI", @@ -202,7 +202,7 @@ end module RenderActionWithControllerLayout class BasicController < ActionController::Base - self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = self.view_paths = [ActionView::FixtureResolver.new( "render_action_with_controller_layout/basic/hello_world.html.erb" => "Hello World!", "layouts/render_action_with_controller_layout/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI" )] @@ -263,7 +263,7 @@ end module RenderActionWithBothLayouts class BasicController < ActionController::Base - self.view_paths = [ActionView::Template::FixturePath.new({ + self.view_paths = [ActionView::FixtureResolver.new({ "render_action_with_both_layouts/basic/hello_world.html.erb" => "Hello World!", "layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI", "layouts/render_action_with_both_layouts/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI" diff --git a/actionpack/test/new_base/render_implicit_action_test.rb b/actionpack/test/new_base/render_implicit_action_test.rb index 2846df48da..fd96e1955f 100644 --- a/actionpack/test/new_base/render_implicit_action_test.rb +++ b/actionpack/test/new_base/render_implicit_action_test.rb @@ -2,7 +2,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") module RenderImplicitAction class SimpleController < ::ApplicationController - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "render_implicit_action/simple/hello_world.html.erb" => "Hello world!", "render_implicit_action/simple/hyphen-ated.html.erb" => "Hello hyphen-ated!" )] diff --git a/actionpack/test/new_base/render_layout_test.rb b/actionpack/test/new_base/render_layout_test.rb index f32c60d683..279b807a5f 100644 --- a/actionpack/test/new_base/render_layout_test.rb +++ b/actionpack/test/new_base/render_layout_test.rb @@ -2,7 +2,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") module ControllerLayouts class ImplicitController < ::ApplicationController - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "layouts/application.html.erb" => "OMG <%= yield %> KTHXBAI", "layouts/override.html.erb" => "Override! <%= yield %>", "basic.html.erb" => "Hello world!", @@ -26,7 +26,7 @@ module ControllerLayouts end class ImplicitNameController < ::ApplicationController - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "layouts/controller_layouts/implicit_name.html.erb" => "OMGIMPLICIT <%= yield %> KTHXBAI", "basic.html.erb" => "Hello world!" )] @@ -68,7 +68,7 @@ module ControllerLayouts end class MismatchFormatController < ::ApplicationController - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "layouts/application.html.erb" => "<html><%= yield %></html>", "controller_layouts/mismatch_format/index.js.rjs" => "page[:test].omg", "controller_layouts/mismatch_format/implicit.rjs" => "page[:test].omg" diff --git a/actionpack/test/new_base/render_partial_test.rb b/actionpack/test/new_base/render_partial_test.rb index 3a300afe5c..bbb98a0c01 100644 --- a/actionpack/test/new_base/render_partial_test.rb +++ b/actionpack/test/new_base/render_partial_test.rb @@ -4,7 +4,7 @@ module RenderPartial class BasicController < ActionController::Base - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "render_partial/basic/_basic.html.erb" => "OMG!", "render_partial/basic/basic.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'basic' %><%= @test_unchanged %>" )] diff --git a/actionpack/test/new_base/render_rjs_test.rb b/actionpack/test/new_base/render_rjs_test.rb new file mode 100644 index 0000000000..bd4c87b3bf --- /dev/null +++ b/actionpack/test/new_base/render_rjs_test.rb @@ -0,0 +1,46 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") + +module RenderRjs + + class BasicController < ActionController::Base + + self.view_paths = [ActionView::FixtureResolver.new( + "render_rjs/basic/index.js.rjs" => "page[:customer].replace_html render(:partial => 'customer')", + "render_rjs/basic/index_html.js.rjs" => "page[:customer].replace_html :partial => 'customer'", + "render_rjs/basic/_customer.js.erb" => "JS Partial", + "render_rjs/basic/_customer.html.erb" => "HTML Partial", + "render_rjs/basic/index_locale.js.rjs" => "page[:customer].replace_html :partial => 'customer'", + "render_rjs/basic/_customer.da.html.erb" => "Danish HTML Partial", + "render_rjs/basic/_customer.da.js.erb" => "Danish JS Partial" + )] + + def index + render + end + + def index_locale + old_locale, I18n.locale = I18n.locale, :da + end + + end + + class TestBasic < SimpleRouteCase + testing BasicController + + test "rendering a partial in an RJS template should pick the JS template over the HTML one" do + get :index + assert_response("$(\"customer\").update(\"JS Partial\");") + end + + test "replacing an element with a partial in an RJS template should pick the HTML template over the JS one" do + get :index_html + assert_response("$(\"customer\").update(\"HTML Partial\");") + end + + test "replacing an element with a partial in an RJS template with a locale should pick the localed HTML template" do + get :index_locale, :format => :js + assert_response("$(\"customer\").update(\"Danish HTML Partial\");") + end + + end +end
\ No newline at end of file diff --git a/actionpack/test/new_base/render_template_test.rb b/actionpack/test/new_base/render_template_test.rb index face5b7571..94ea38fc7b 100644 --- a/actionpack/test/new_base/render_template_test.rb +++ b/actionpack/test/new_base/render_template_test.rb @@ -3,7 +3,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") module RenderTemplate class WithoutLayoutController < ActionController::Base - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "test/basic.html.erb" => "Hello from basic.html.erb", "shared.html.erb" => "Elastica", "locals.html.erb" => "The secret is <%= secret %>", @@ -79,7 +79,7 @@ module RenderTemplate end class WithLayoutController < ::ApplicationController - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "test/basic.html.erb" => "Hello from basic.html.erb", "shared.html.erb" => "Elastica", "layouts/application.html.erb" => "<%= yield %>, I'm here!", @@ -148,7 +148,7 @@ module RenderTemplate module Compatibility class WithoutLayoutController < ActionController::Base - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "test/basic.html.erb" => "Hello from basic.html.erb", "shared.html.erb" => "Elastica" )] diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb index ed3d50fa0b..5783b4766a 100644 --- a/actionpack/test/new_base/render_test.rb +++ b/actionpack/test/new_base/render_test.rb @@ -2,7 +2,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") module Render class BlankRenderController < ActionController::Base - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "render/blank_render/index.html.erb" => "Hello world!", "render/blank_render/access_request.html.erb" => "The request: <%= request.method.to_s.upcase %>", "render/blank_render/access_action_name.html.erb" => "Action Name: <%= action_name %>", diff --git a/actionpack/test/new_base/render_text_test.rb b/actionpack/test/new_base/render_text_test.rb index 4a90eaac40..84f77432c9 100644 --- a/actionpack/test/new_base/render_text_test.rb +++ b/actionpack/test/new_base/render_text_test.rb @@ -2,7 +2,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") module RenderText class SimpleController < ActionController::Base - self.view_paths = [ActionView::Template::FixturePath.new] + self.view_paths = [ActionView::FixtureResolver.new] def index render :text => "hello david" @@ -10,7 +10,7 @@ module RenderText end class WithLayoutController < ::ApplicationController - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "layouts/application.html.erb" => "<%= yield %>, I'm here!", "layouts/greetings.html.erb" => "<%= yield %>, I wish thee well.", "layouts/ivar.html.erb" => "<%= yield %>, <%= @ivar %>" diff --git a/actionpack/test/new_base/render_xml_test.rb b/actionpack/test/new_base/render_xml_test.rb index e6c40b1533..a3890ddfb2 100644 --- a/actionpack/test/new_base/render_xml_test.rb +++ b/actionpack/test/new_base/render_xml_test.rb @@ -4,7 +4,7 @@ module RenderXml # This has no layout and it works class BasicController < ActionController::Base - self.view_paths = [ActionView::Template::FixturePath.new( + self.view_paths = [ActionView::FixtureResolver.new( "render_xml/basic/with_render_erb" => "Hello world!" )] end diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb index b4b8cbe074..4691049a41 100644 --- a/actionpack/test/template/active_record_helper_test.rb +++ b/actionpack/test/template/active_record_helper_test.rb @@ -33,8 +33,8 @@ class ActiveRecordHelperTest < ActionView::TestCase ["Author name can't be <em>empty</em>"] end - def on(field) - "can't be <em>empty</em>" + def [](field) + ["can't be <em>empty</em>"] end end @@ -47,14 +47,14 @@ class ActiveRecordHelperTest < ActionView::TestCase @post = Post.new def @post.errors Class.new { - def on(field) + def [](field) case field.to_s when "author_name" - "can't be empty" + ["can't be empty"] when "body" - true + ['foo'] else - false + [] end end def empty?() false end @@ -85,7 +85,7 @@ class ActiveRecordHelperTest < ActionView::TestCase @user = User.new def @user.errors Class.new { - def on(field) field == "email" end + def [](field) field == "email" ? ['nonempty'] : [] end def empty?() false end def count() 1 end def full_messages() [ "User email can't be empty" ] end diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb index bd97caf5d7..6f1179f359 100644 --- a/actionpack/test/template/atom_feed_helper_test.rb +++ b/actionpack/test/template/atom_feed_helper_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' Scroll = Struct.new(:id, :to_param, :title, :body, :updated_at, :created_at) +Scroll.extend ActiveModel::Naming class ScrollsController < ActionController::Base FEEDS = {} diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb index 4e7aa63f96..bac67c1a7d 100644 --- a/actionpack/test/template/body_parts_test.rb +++ b/actionpack/test/template/body_parts_test.rb @@ -4,9 +4,8 @@ class BodyPartsTest < ActionController::TestCase RENDERINGS = [Object.new, Object.new, Object.new] class TestController < ActionController::Base - def performed? - defined?(ActionController::Http) ? true : super - end + def performed?() true end + def index RENDERINGS.each do |rendering| @template.punctuate_body! rendering @@ -19,11 +18,9 @@ class BodyPartsTest < ActionController::TestCase def test_body_parts get :index - pending(:old_base) do - # TestProcess buffers body_parts into body - # TODO: Rewrite test w/o going through process - assert_equal RENDERINGS, @response.body_parts - end + # TestProcess buffers body_parts into body + # TODO: Rewrite test w/o going through process + assert_equal RENDERINGS, @response.body_parts assert_equal RENDERINGS.join, @response.body end end diff --git a/actionpack/test/template/capture_helper_test.rb b/actionpack/test/template/capture_helper_test.rb new file mode 100644 index 0000000000..2017a18806 --- /dev/null +++ b/actionpack/test/template/capture_helper_test.rb @@ -0,0 +1,15 @@ +require 'abstract_unit' + +class CaptureHelperTest < ActionView::TestCase + def setup + super + @_content_for = Hash.new {|h,k| h[k] = "" } + end + + def test_content_for + assert ! content_for?(:title) + content_for :title, 'title' + assert content_for?(:title) + assert ! content_for?(:something_else) + end +end diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index b29b03f99d..9c268aef27 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -41,7 +41,7 @@ class CompiledTemplatesTest < Test::Unit::TestCase end def render_without_cache(*args) - path = ActionView::Template::FileSystemPathWithFallback.new(FIXTURE_LOAD_PATH) + path = ActionView::FileSystemResolverWithFallback.new(FIXTURE_LOAD_PATH) view_paths = ActionView::Base.process_view_paths(path) ActionView::Base.new(view_paths, {}).render(*args) end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 947668ccc6..f8215132e3 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -50,7 +50,7 @@ class FormHelperTest < ActionView::TestCase @comment = Comment.new def @post.errors() Class.new{ - def on(field); "can't be empty" if field == "author_name"; end + def [](field); field == "author_name" ? ["can't be empty"] : [] end def empty?() false end def count() 1 end def full_messages() [ "Author name can't be empty" ] end @@ -1193,4 +1193,4 @@ class FormHelperTest < ActionView::TestCase def protect_against_forgery? false end -end
\ No newline at end of file +end diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index f9f418aec9..02b1d137f5 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -1,8 +1,10 @@ require 'abstract_unit' Bunny = Struct.new(:Bunny, :id) +Bunny.extend ActiveModel::Naming class Author + extend ActiveModel::Naming attr_reader :id def save; @id = 1 end def new_record?; @id.nil? end @@ -12,6 +14,7 @@ class Author end class Article + extend ActiveModel::Naming attr_reader :id attr_reader :author_id def save; @id = 1; @author_id = 1 end diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb index 809ed6d6af..5b840d123b 100644 --- a/actionpack/test/template/record_tag_helper_test.rb +++ b/actionpack/test/template/record_tag_helper_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' class Post + extend ActiveModel::Naming def id 45 end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 2ed11aa3c0..7f30ae88a1 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -46,29 +46,6 @@ module RenderTestCases I18n.locale = old_locale end - def test_render_implicit_html_template_from_xhr_request - old_format = @view.formats - pending do - @view.formats = [:js] - assert_equal "Hello HTML!", @view.render(:file => "test/render_implicit_html_template_from_xhr_request") - end - ensure - @view.formats = old_format - end - - def test_render_implicit_html_template_from_xhr_request_with_localization - old_locale = I18n.locale - old_format = @view.formats - pending do - I18n.locale = :da - @view.formats = [:js] - assert_equal "Hey HTML!\n", @view.render(:file => "test/render_implicit_html_template_from_xhr_request") - end - ensure - I18n.locale = old_locale - @view.formats = old_format - end - def test_render_file_at_top_level assert_equal 'Elastica', @view.render(:file => '/shared') end @@ -278,7 +255,7 @@ class CachedViewRenderTest < ActiveSupport::TestCase # Ensure view path cache is primed def setup view_paths = ActionController::Base.view_paths - assert_equal ActionView::Template::FileSystemPathWithFallback, view_paths.first.class + assert_equal ActionView::FileSystemResolverWithFallback, view_paths.first.class setup_view(view_paths) end end @@ -289,9 +266,9 @@ class LazyViewRenderTest < ActiveSupport::TestCase # Test the same thing as above, but make sure the view path # is not eager loaded def setup - path = ActionView::Template::FileSystemPathWithFallback.new(FIXTURE_LOAD_PATH) + path = ActionView::FileSystemResolverWithFallback.new(FIXTURE_LOAD_PATH) view_paths = ActionView::Base.process_view_paths(path) - assert_equal ActionView::Template::FileSystemPathWithFallback, view_paths.first.class + assert_equal ActionView::FileSystemResolverWithFallback, view_paths.first.class setup_view(view_paths) end end diff --git a/actionpack/test/template/test_test.rb b/actionpack/test/template/test_test.rb index dd07a6d438..f32d0b3d42 100644 --- a/actionpack/test/template/test_test.rb +++ b/actionpack/test/template/test_test.rb @@ -41,6 +41,7 @@ class PeopleHelperTest < ActionView::TestCase def test_link_to_person person = mock(:name => "David") + person.class.extend ActiveModel::Naming expects(:mocha_mock_path).with(person).returns("/people/1") assert_equal '<a href="/people/1">David</a>', link_to_person(person) end diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index f3d2f87b4a..f0364fd660 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -494,6 +494,7 @@ class LinkToUnlessCurrentWithControllerTest < ActionView::TestCase end class Workshop + extend ActiveModel::Naming attr_accessor :id, :new_record def initialize(id, new_record) @@ -510,6 +511,7 @@ class Workshop end class Session + extend ActiveModel::Naming attr_accessor :id, :workshop_id, :new_record def initialize(id, new_record) |