diff options
Diffstat (limited to 'actionpack/test/abstract')
14 files changed, 0 insertions, 857 deletions
diff --git a/actionpack/test/abstract/abstract_controller_test.rb b/actionpack/test/abstract/abstract_controller_test.rb deleted file mode 100644 index eb9143c8f6..0000000000 --- a/actionpack/test/abstract/abstract_controller_test.rb +++ /dev/null @@ -1,261 +0,0 @@ -require 'abstract_unit' -require 'set' - -module AbstractController - module Testing - - # Test basic dispatching. - # ==== - # * Call process - # * Test that the response_body is set correctly - class SimpleController < AbstractController::Base - end - - class Me < SimpleController - def index - self.response_body = "Hello world" - "Something else" - end - end - - class TestBasic < ActiveSupport::TestCase - test "dispatching works" do - controller = Me.new - controller.process(:index) - assert_equal "Hello world", controller.response_body - end - end - - # Test Render mixin - # ==== - class RenderingController < AbstractController::Base - include AbstractController::Rendering - - def _prefixes - [] - end - - def render(options = {}) - if options.is_a?(String) - options = {:_template_name => options} - end - super - end - - append_view_path File.expand_path(File.join(File.dirname(__FILE__), "views")) - end - - class Me2 < RenderingController - def index - render "index.erb" - end - - def index_to_string - self.response_body = render_to_string "index" - end - - def action_with_ivars - @my_ivar = "Hello" - render "action_with_ivars.erb" - end - - def naked_render - render - end - - def rendering_to_body - self.response_body = render_to_body :template => "naked_render" - end - - def rendering_to_string - self.response_body = render_to_string :template => "naked_render" - end - end - - class TestRenderingController < ActiveSupport::TestCase - def setup - @controller = Me2.new - end - - test "rendering templates works" do - @controller.process(:index) - assert_equal "Hello from index.erb", @controller.response_body - end - - test "render_to_string works with a String as an argument" do - @controller.process(:index_to_string) - assert_equal "Hello from index.erb", @controller.response_body - end - - test "rendering passes ivars to the view" do - @controller.process(:action_with_ivars) - assert_equal "Hello from index_with_ivars.erb", @controller.response_body - end - - test "rendering with no template name" do - @controller.process(:naked_render) - assert_equal "Hello from naked_render.erb", @controller.response_body - end - - test "rendering to a rack body" do - @controller.process(:rendering_to_body) - assert_equal "Hello from naked_render.erb", @controller.response_body - end - - test "rendering to a string" do - @controller.process(:rendering_to_string) - assert_equal "Hello from naked_render.erb", @controller.response_body - end - end - - # Test rendering with prefixes - # ==== - # * self._prefix is used when defined - class PrefixedViews < RenderingController - private - def self.prefix - name.underscore - end - - def _prefixes - [self.class.prefix] - end - end - - class Me3 < PrefixedViews - def index - render - end - - def formatted - self.formats = [:html] - render - end - end - - class TestPrefixedViews < ActiveSupport::TestCase - def setup - @controller = Me3.new - end - - test "templates are located inside their 'prefix' folder" do - @controller.process(:index) - assert_equal "Hello from me3/index.erb", @controller.response_body - end - - test "templates included their format" do - @controller.process(:formatted) - assert_equal "Hello from me3/formatted.html.erb", @controller.response_body - end - end - - # Test rendering with layouts - # ==== - # self._layout is used when defined - class WithLayouts < PrefixedViews - include AbstractController::Layouts - - private - def self.layout(formats) - find_template(name.underscore, {:formats => formats}, :_prefixes => ["layouts"]) - rescue ActionView::MissingTemplate - begin - find_template("application", {:formats => formats}, :_prefixes => ["layouts"]) - rescue ActionView::MissingTemplate - end - end - - def render_to_body(options = {}) - options[:_layout] = options[:layout] || _default_layout({}) - super - end - end - - class Me4 < WithLayouts - def index - render - end - end - - class TestLayouts < ActiveSupport::TestCase - test "layouts are included" do - controller = Me4.new - controller.process(:index) - assert_equal "Me4 Enter : Hello from me4/index.erb : Exit", controller.response_body - end - end - - # respond_to_action?(action_name) - # ==== - # * A method can be used as an action only if this method - # returns true when passed the method name as an argument - # * Defaults to true in AbstractController - class DefaultRespondToActionController < AbstractController::Base - def index() self.response_body = "success" end - end - - class ActionMissingRespondToActionController < AbstractController::Base - # No actions - private - def action_missing(action_name) - self.response_body = "success" - end - end - - class RespondToActionController < AbstractController::Base; - def index() self.response_body = "success" end - - def fail() self.response_body = "fail" end - - private - - def method_for_action(action_name) - action_name.to_s != "fail" && action_name - end - end - - class TestRespondToAction < ActiveSupport::TestCase - - def assert_dispatch(klass, body = "success", action = :index) - controller = klass.new - controller.process(action) - assert_equal body, controller.response_body - end - - test "an arbitrary method is available as an action by default" do - assert_dispatch DefaultRespondToActionController, "success", :index - end - - test "raises ActionNotFound when method does not exist and action_missing is not defined" do - assert_raise(ActionNotFound) { DefaultRespondToActionController.new.process(:fail) } - end - - test "dispatches to action_missing when method does not exist and action_missing is defined" do - assert_dispatch ActionMissingRespondToActionController, "success", :ohai - end - - test "a method is available as an action if method_for_action returns true" do - assert_dispatch RespondToActionController, "success", :index - end - - test "raises ActionNotFound if method is defined but method_for_action returns false" do - assert_raise(ActionNotFound) { RespondToActionController.new.process(:fail) } - end - end - - class Me6 < AbstractController::Base - self.action_methods - - def index - end - end - - class TestActionMethodsReloading < ActiveSupport::TestCase - - test "action_methods should be reloaded after defining a new method" do - assert_equal Set.new(["index"]), Me6.action_methods - end - end - - end -end diff --git a/actionpack/test/abstract/helper_test.rb b/actionpack/test/abstract/helper_test.rb deleted file mode 100644 index 7960e5b55b..0000000000 --- a/actionpack/test/abstract/helper_test.rb +++ /dev/null @@ -1,101 +0,0 @@ -require 'abstract_unit' - -ActionController::Base.helpers_path = File.expand_path('../../fixtures/helpers', __FILE__) - -module AbstractController - module Testing - - class ControllerWithHelpers < AbstractController::Base - include AbstractController::Rendering - include AbstractController::Helpers - - def with_module - render :inline => "Module <%= included_method %>" - end - end - - module HelperyTest - def included_method - "Included" - end - end - - class AbstractHelpers < ControllerWithHelpers - helper(HelperyTest) do - def helpery_test - "World" - end - end - - helper :abc - - def with_block - render :inline => "Hello <%= helpery_test %>" - end - - def with_symbol - render :inline => "I respond to bare_a: <%= respond_to?(:bare_a) %>" - end - end - - class ::HelperyTestController < AbstractHelpers - clear_helpers - end - - class AbstractHelpersBlock < ControllerWithHelpers - helper do - include AbstractController::Testing::HelperyTest - end - end - - class TestHelpers < ActiveSupport::TestCase - def setup - @controller = AbstractHelpers.new - end - - def test_helpers_with_block - @controller.process(:with_block) - assert_equal "Hello World", @controller.response_body - end - - def test_helpers_with_module - @controller.process(:with_module) - assert_equal "Module Included", @controller.response_body - end - - def test_helpers_with_symbol - @controller.process(:with_symbol) - assert_equal "I respond to bare_a: true", @controller.response_body - end - - def test_declare_missing_helper - AbstractHelpers.helper :missing - flunk "should have raised an exception" - rescue LoadError => e - assert_equal "helpers/missing_helper.rb", e.path - end - - def test_helpers_with_module_through_block - @controller = AbstractHelpersBlock.new - @controller.process(:with_module) - assert_equal "Module Included", @controller.response_body - end - end - - class ClearHelpersTest < ActiveSupport::TestCase - def setup - @controller = HelperyTestController.new - end - - def test_clears_up_previous_helpers - @controller.process(:with_symbol) - assert_equal "I respond to bare_a: false", @controller.response_body - end - - def test_includes_controller_default_helper - @controller.process(:with_block) - assert_equal "Hello Default", @controller.response_body - end - end - end -end diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb deleted file mode 100644 index 4a05c00f8b..0000000000 --- a/actionpack/test/abstract/layouts_test.rb +++ /dev/null @@ -1,383 +0,0 @@ -require 'abstract_unit' - -module AbstractControllerTests - module Layouts - - # Base controller for these tests - class Base < AbstractController::Base - include AbstractController::Rendering - include AbstractController::Layouts - - abstract! - - self.view_paths = [ActionView::FixtureResolver.new( - "layouts/hello.erb" => "With String <%= yield %>", - "layouts/hello_override.erb" => "With Override <%= yield %>", - "layouts/overwrite.erb" => "Overwrite <%= yield %>", - "layouts/with_false_layout.erb" => "False Layout <%= yield %>", - "abstract_controller_tests/layouts/with_string_implied_child.erb" => - "With Implied <%= yield %>", - "abstract_controller_tests/layouts/with_grand_child_of_implied.erb" => - "With Grand Child <%= yield %>" - - )] - end - - class Blank < Base - self.view_paths = [] - - def index - render :template => ActionView::Template::Text.new("Hello blank!") - end - end - - class WithString < Base - layout "hello" - - def index - render :template => ActionView::Template::Text.new("Hello string!") - end - - def overwrite_default - render :template => ActionView::Template::Text.new("Hello string!"), :layout => :default - end - - def overwrite_false - render :template => ActionView::Template::Text.new("Hello string!"), :layout => false - end - - def overwrite_string - render :template => ActionView::Template::Text.new("Hello string!"), :layout => "overwrite" - end - - def overwrite_skip - render :text => "Hello text!" - end - end - - class WithStringChild < WithString - end - - class WithStringOverriddenChild < WithString - layout "hello_override" - end - - class WithStringImpliedChild < WithString - layout nil - end - - class WithChildOfImplied < WithStringImpliedChild - end - - class WithGrandChildOfImplied < WithStringImpliedChild - layout nil - end - - class WithProc < Base - layout proc { "overwrite" } - - def index - render :template => ActionView::Template::Text.new("Hello proc!") - end - end - - class WithProcReturningNil < Base - layout proc { nil } - - def index - render template: ActionView::Template::Text.new("Hello nil!") - end - end - - class WithZeroArityProc < Base - layout proc { "overwrite" } - - def index - render :template => ActionView::Template::Text.new("Hello zero arity proc!") - end - end - - class WithProcInContextOfInstance < Base - def an_instance_method; end - - layout proc { - break unless respond_to? :an_instance_method - "overwrite" - } - - def index - render :template => ActionView::Template::Text.new("Hello again zero arity proc!") - end - end - - class WithSymbol < Base - layout :hello - - def index - render :template => ActionView::Template::Text.new("Hello symbol!") - end - private - def hello - "overwrite" - end - end - - class WithSymbolReturningNil < Base - layout :nilz - - def index - render :template => ActionView::Template::Text.new("Hello nilz!") - end - - def nilz() end - end - - class WithSymbolReturningObj < Base - layout :objekt - - def index - render :template => ActionView::Template::Text.new("Hello nilz!") - end - - def objekt - Object.new - end - end - - class WithSymbolAndNoMethod < Base - layout :no_method - - def index - render :template => ActionView::Template::Text.new("Hello boom!") - end - end - - class WithMissingLayout < Base - layout "missing" - - def index - render :template => ActionView::Template::Text.new("Hello missing!") - end - end - - class WithFalseLayout < Base - layout false - - def index - render :template => ActionView::Template::Text.new("Hello false!") - end - end - - class WithNilLayout < Base - layout nil - - def index - render :template => ActionView::Template::Text.new("Hello nil!") - end - end - - class WithOnlyConditional < WithStringImpliedChild - layout "overwrite", :only => :show - - def index - render :template => ActionView::Template::Text.new("Hello index!") - end - - def show - render :template => ActionView::Template::Text.new("Hello show!") - end - end - - class WithExceptConditional < WithStringImpliedChild - layout "overwrite", :except => :show - - def index - render :template => ActionView::Template::Text.new("Hello index!") - end - - def show - render :template => ActionView::Template::Text.new("Hello show!") - end - end - - class TestBase < ActiveSupport::TestCase - test "when no layout is specified, and no default is available, render without a layout" do - controller = Blank.new - controller.process(:index) - assert_equal "Hello blank!", controller.response_body - end - - test "when layout is specified as a string, render with that layout" do - controller = WithString.new - controller.process(:index) - assert_equal "With String Hello string!", controller.response_body - end - - test "when layout is overwriten by :default in render, render default layout" do - controller = WithString.new - controller.process(:overwrite_default) - assert_equal "With String Hello string!", controller.response_body - end - - test "when layout is overwriten by string in render, render new layout" do - controller = WithString.new - controller.process(:overwrite_string) - assert_equal "Overwrite Hello string!", controller.response_body - end - - test "when layout is overwriten by false in render, render no layout" do - controller = WithString.new - controller.process(:overwrite_false) - assert_equal "Hello string!", controller.response_body - end - - test "when text is rendered, render no layout" do - controller = WithString.new - controller.process(:overwrite_skip) - assert_equal "Hello text!", controller.response_body - end - - test "when layout is specified as a string, but the layout is missing, raise an exception" do - assert_raises(ActionView::MissingTemplate) { WithMissingLayout.new.process(:index) } - end - - test "when layout is specified as false, do not use a layout" do - controller = WithFalseLayout.new - controller.process(:index) - assert_equal "Hello false!", controller.response_body - end - - test "when layout is specified as nil, do not use a layout" do - controller = WithNilLayout.new - controller.process(:index) - assert_equal "Hello nil!", controller.response_body - end - - test "when layout is specified as a proc, do not leak any methods into controller's action_methods" do - assert_equal Set.new(['index']), WithProc.action_methods - end - - test "when layout is specified as a proc, call it and use the layout returned" do - controller = WithProc.new - controller.process(:index) - assert_equal "Overwrite Hello proc!", controller.response_body - end - - test "when layout is specified as a proc and the proc retuns nil, don't use a layout" do - controller = WithProcReturningNil.new - controller.process(:index) - assert_equal "Hello nil!", controller.response_body - end - - test "when layout is specified as a proc without parameters it works just the same" do - controller = WithZeroArityProc.new - controller.process(:index) - assert_equal "Overwrite Hello zero arity proc!", controller.response_body - end - - test "when layout is specified as a proc without parameters the block is evaluated in the context of an instance" do - controller = WithProcInContextOfInstance.new - controller.process(:index) - assert_equal "Overwrite Hello again zero arity proc!", controller.response_body - end - - test "when layout is specified as a symbol, call the requested method and use the layout returned" do - controller = WithSymbol.new - controller.process(:index) - assert_equal "Overwrite Hello symbol!", controller.response_body - end - - test "when layout is specified as a symbol and the method returns nil, don't use a layout" do - controller = WithSymbolReturningNil.new - controller.process(:index) - assert_equal "Hello nilz!", controller.response_body - end - - test "when the layout is specified as a symbol and the method doesn't exist, raise an exception" do - assert_raises(NameError) { WithSymbolAndNoMethod.new.process(:index) } - end - - test "when the layout is specified as a symbol and the method returns something besides a string/false/nil, raise an exception" do - assert_raises(ArgumentError) { WithSymbolReturningObj.new.process(:index) } - end - - test "when a child controller does not have a layout, use the parent controller layout" do - controller = WithStringChild.new - controller.process(:index) - assert_equal "With String Hello string!", controller.response_body - end - - test "when a child controller has specified a layout, use that layout and not the parent controller layout" do - controller = WithStringOverriddenChild.new - controller.process(:index) - assert_equal "With Override Hello string!", controller.response_body - end - - test "when a child controller has an implied layout, use that layout and not the parent controller layout" do - controller = WithStringImpliedChild.new - controller.process(:index) - assert_equal "With Implied Hello string!", controller.response_body - end - - test "when a grandchild has no layout specified, the child has an implied layout, and the " \ - "parent has specified a layout, use the child controller layout" do - controller = WithChildOfImplied.new - controller.process(:index) - assert_equal "With Implied Hello string!", controller.response_body - end - - test "when a grandchild has nil layout specified, the child has an implied layout, and the " \ - "parent has specified a layout, use the child controller layout" do - controller = WithGrandChildOfImplied.new - controller.process(:index) - assert_equal "With Grand Child Hello string!", controller.response_body - end - - test "raises an exception when specifying layout true" do - assert_raises ArgumentError do - Object.class_eval do - class ::BadFailLayout < AbstractControllerTests::Layouts::Base - layout true - end - end - end - end - - test "when specify an :only option which match current action name" do - controller = WithOnlyConditional.new - controller.process(:show) - assert_equal "Overwrite Hello show!", controller.response_body - end - - test "when specify an :only option which does not match current action name" do - controller = WithOnlyConditional.new - controller.process(:index) - assert_equal "With Implied Hello index!", controller.response_body - end - - test "when specify an :except option which match current action name" do - controller = WithExceptConditional.new - controller.process(:show) - assert_equal "With Implied Hello show!", controller.response_body - end - - test "when specify an :except option which does not match current action name" do - controller = WithExceptConditional.new - controller.process(:index) - assert_equal "Overwrite Hello index!", controller.response_body - end - - test "layout for anonymous controller" do - klass = Class.new(WithString) do - def index - render :text => 'index', :layout => true - end - end - - controller = klass.new - controller.process(:index) - assert_equal "With String index", controller.response_body - end - end - end -end diff --git a/actionpack/test/abstract/render_test.rb b/actionpack/test/abstract/render_test.rb deleted file mode 100644 index b9293d1241..0000000000 --- a/actionpack/test/abstract/render_test.rb +++ /dev/null @@ -1,102 +0,0 @@ -require 'abstract_unit' - -module AbstractController - module Testing - - class ControllerRenderer < AbstractController::Base - include AbstractController::Rendering - - def _prefixes - %w[renderer] - end - - self.view_paths = [ActionView::FixtureResolver.new( - "template.erb" => "With Template", - "renderer/default.erb" => "With Default", - "renderer/string.erb" => "With String", - "renderer/symbol.erb" => "With Symbol", - "string/with_path.erb" => "With String With Path", - "some/file.erb" => "With File" - )] - - def template - render :template => "template" - end - - def file - render :file => "some/file" - end - - def inline - render :inline => "With <%= :Inline %>" - end - - def text - render :text => "With Text" - end - - def default - render - end - - def string - render "string" - end - - def string_with_path - render "string/with_path" - end - - def symbol - render :symbol - end - end - - class TestRenderer < ActiveSupport::TestCase - - def setup - @controller = ControllerRenderer.new - end - - def test_render_template - @controller.process(:template) - assert_equal "With Template", @controller.response_body - end - - def test_render_file - @controller.process(:file) - assert_equal "With File", @controller.response_body - end - - def test_render_inline - @controller.process(:inline) - assert_equal "With Inline", @controller.response_body - end - - def test_render_text - @controller.process(:text) - assert_equal "With Text", @controller.response_body - end - - def test_render_default - @controller.process(:default) - assert_equal "With Default", @controller.response_body - end - - def test_render_string - @controller.process(:string) - assert_equal "With String", @controller.response_body - end - - def test_render_symbol - @controller.process(:symbol) - assert_equal "With Symbol", @controller.response_body - end - - def test_render_string_with_path - @controller.process(:string_with_path) - assert_equal "With String With Path", @controller.response_body - end - end - end -end diff --git a/actionpack/test/abstract/views/abstract_controller/testing/me3/formatted.html.erb b/actionpack/test/abstract/views/abstract_controller/testing/me3/formatted.html.erb deleted file mode 100644 index 785bf69191..0000000000 --- a/actionpack/test/abstract/views/abstract_controller/testing/me3/formatted.html.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from me3/formatted.html.erb
\ No newline at end of file diff --git a/actionpack/test/abstract/views/abstract_controller/testing/me3/index.erb b/actionpack/test/abstract/views/abstract_controller/testing/me3/index.erb deleted file mode 100644 index f079ad8204..0000000000 --- a/actionpack/test/abstract/views/abstract_controller/testing/me3/index.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from me3/index.erb
\ No newline at end of file diff --git a/actionpack/test/abstract/views/abstract_controller/testing/me4/index.erb b/actionpack/test/abstract/views/abstract_controller/testing/me4/index.erb deleted file mode 100644 index 89dce12bdc..0000000000 --- a/actionpack/test/abstract/views/abstract_controller/testing/me4/index.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from me4/index.erb
\ No newline at end of file diff --git a/actionpack/test/abstract/views/abstract_controller/testing/me5/index.erb b/actionpack/test/abstract/views/abstract_controller/testing/me5/index.erb deleted file mode 100644 index 84d0b7417e..0000000000 --- a/actionpack/test/abstract/views/abstract_controller/testing/me5/index.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from me5/index.erb
\ No newline at end of file diff --git a/actionpack/test/abstract/views/action_with_ivars.erb b/actionpack/test/abstract/views/action_with_ivars.erb deleted file mode 100644 index 8d8ae22fd7..0000000000 --- a/actionpack/test/abstract/views/action_with_ivars.erb +++ /dev/null @@ -1 +0,0 @@ -<%= @my_ivar %> from index_with_ivars.erb
\ No newline at end of file diff --git a/actionpack/test/abstract/views/helper_test.erb b/actionpack/test/abstract/views/helper_test.erb deleted file mode 100644 index 8ae45cc195..0000000000 --- a/actionpack/test/abstract/views/helper_test.erb +++ /dev/null @@ -1 +0,0 @@ -Hello <%= helpery_test %> : <%= included_method %>
\ No newline at end of file diff --git a/actionpack/test/abstract/views/index.erb b/actionpack/test/abstract/views/index.erb deleted file mode 100644 index cc1a8b8c85..0000000000 --- a/actionpack/test/abstract/views/index.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from index.erb
\ No newline at end of file diff --git a/actionpack/test/abstract/views/layouts/abstract_controller/testing/me4.erb b/actionpack/test/abstract/views/layouts/abstract_controller/testing/me4.erb deleted file mode 100644 index 172dd56569..0000000000 --- a/actionpack/test/abstract/views/layouts/abstract_controller/testing/me4.erb +++ /dev/null @@ -1 +0,0 @@ -Me4 Enter : <%= yield %> : Exit
\ No newline at end of file diff --git a/actionpack/test/abstract/views/layouts/application.erb b/actionpack/test/abstract/views/layouts/application.erb deleted file mode 100644 index 27317140ad..0000000000 --- a/actionpack/test/abstract/views/layouts/application.erb +++ /dev/null @@ -1 +0,0 @@ -Application Enter : <%= yield %> : Exit
\ No newline at end of file diff --git a/actionpack/test/abstract/views/naked_render.erb b/actionpack/test/abstract/views/naked_render.erb deleted file mode 100644 index 1b3d03878b..0000000000 --- a/actionpack/test/abstract/views/naked_render.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from naked_render.erb
\ No newline at end of file |