From 32b42e26209894684dc3432c5463e05ca8fadc82 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 9 Oct 2013 19:30:44 +0200 Subject: FakeController is not required in AV --- actionview/test/lib/controller/fake_controllers.rb | 35 ---------------------- 1 file changed, 35 deletions(-) delete mode 100644 actionview/test/lib/controller/fake_controllers.rb (limited to 'actionview') diff --git a/actionview/test/lib/controller/fake_controllers.rb b/actionview/test/lib/controller/fake_controllers.rb deleted file mode 100644 index 1a2863b689..0000000000 --- a/actionview/test/lib/controller/fake_controllers.rb +++ /dev/null @@ -1,35 +0,0 @@ -class ContentController < ActionController::Base; end - -module Admin - class AccountsController < ActionController::Base; end - class PostsController < ActionController::Base; end - class StuffController < ActionController::Base; end - class UserController < ActionController::Base; end - class UsersController < ActionController::Base; end -end - -module Api - class UsersController < ActionController::Base; end - class ProductsController < ActionController::Base; end -end - -class AccountController < ActionController::Base; end -class ArchiveController < ActionController::Base; end -class ArticlesController < ActionController::Base; end -class BarController < ActionController::Base; end -class BlogController < ActionController::Base; end -class BooksController < ActionController::Base; end -class CarsController < ActionController::Base; end -class CcController < ActionController::Base; end -class CController < ActionController::Base; end -class FooController < ActionController::Base; end -class GeocodeController < ActionController::Base; end -class NewsController < ActionController::Base; end -class NotesController < ActionController::Base; end -class PagesController < ActionController::Base; end -class PeopleController < ActionController::Base; end -class PostsController < ActionController::Base; end -class SubpathBooksController < ActionController::Base; end -class SymbolsController < ActionController::Base; end -class UserController < ActionController::Base; end -class UsersController < ActionController::Base; end -- cgit v1.2.3 From 64eb39a5b929de9ab33e4d22a2cfc927f609a8f3 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 9 Oct 2013 20:09:18 +0200 Subject: Moved viewpathstest into actionview/test/actionpack/controller These test were not running at all, Now it will run as a tests part. --- .../test/actionpack/controller/view_paths_test.rb | 174 +++++++++++++++++++++ actionview/test/lib/controller/view_paths_test.rb | 174 --------------------- 2 files changed, 174 insertions(+), 174 deletions(-) create mode 100644 actionview/test/actionpack/controller/view_paths_test.rb delete mode 100644 actionview/test/lib/controller/view_paths_test.rb (limited to 'actionview') diff --git a/actionview/test/actionpack/controller/view_paths_test.rb b/actionview/test/actionpack/controller/view_paths_test.rb new file mode 100644 index 0000000000..c6e7a523b9 --- /dev/null +++ b/actionview/test/actionpack/controller/view_paths_test.rb @@ -0,0 +1,174 @@ +require 'abstract_unit' + +class ViewLoadPathsTest < ActionController::TestCase + class TestController < ActionController::Base + def self.controller_path() "test" end + + before_action :add_view_path, only: :hello_world_at_request_time + + def hello_world() end + def hello_world_at_request_time() render(:action => 'hello_world') end + + private + def add_view_path + prepend_view_path "#{FIXTURE_LOAD_PATH}/override" + end + end + + module Test + class SubController < ActionController::Base + layout 'test/sub' + def hello_world; render(:template => 'test/hello_world'); end + end + end + + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @controller = TestController.new + @paths = TestController.view_paths + end + + def teardown + TestController.view_paths = @paths + end + + def expand(array) + array.map {|x| File.expand_path(x.to_s)} + end + + def assert_paths(*paths) + controller = paths.first.is_a?(Class) ? paths.shift : @controller + assert_equal expand(paths), controller.view_paths.map { |p| p.to_s } + end + + def test_template_load_path_was_set_correctly + assert_paths FIXTURE_LOAD_PATH + end + + def test_controller_appends_view_path_correctly + @controller.append_view_path 'foo' + assert_paths(FIXTURE_LOAD_PATH, "foo") + + @controller.append_view_path(%w(bar baz)) + assert_paths(FIXTURE_LOAD_PATH, "foo", "bar", "baz") + + @controller.append_view_path(FIXTURE_LOAD_PATH) + assert_paths(FIXTURE_LOAD_PATH, "foo", "bar", "baz", FIXTURE_LOAD_PATH) + end + + def test_controller_prepends_view_path_correctly + @controller.prepend_view_path 'baz' + assert_paths("baz", FIXTURE_LOAD_PATH) + + @controller.prepend_view_path(%w(foo bar)) + assert_paths "foo", "bar", "baz", FIXTURE_LOAD_PATH + + @controller.prepend_view_path(FIXTURE_LOAD_PATH) + assert_paths FIXTURE_LOAD_PATH, "foo", "bar", "baz", FIXTURE_LOAD_PATH + end + + def test_template_appends_view_path_correctly + @controller.instance_variable_set :@template, ActionView::Base.new(TestController.view_paths, {}, @controller) + class_view_paths = TestController.view_paths + + @controller.append_view_path 'foo' + assert_paths FIXTURE_LOAD_PATH, "foo" + + @controller.append_view_path(%w(bar baz)) + assert_paths FIXTURE_LOAD_PATH, "foo", "bar", "baz" + assert_paths TestController, *class_view_paths + end + + def test_template_prepends_view_path_correctly + @controller.instance_variable_set :@template, ActionView::Base.new(TestController.view_paths, {}, @controller) + class_view_paths = TestController.view_paths + + @controller.prepend_view_path 'baz' + assert_paths "baz", FIXTURE_LOAD_PATH + + @controller.prepend_view_path(%w(foo bar)) + assert_paths "foo", "bar", "baz", FIXTURE_LOAD_PATH + assert_paths TestController, *class_view_paths + end + + def test_view_paths + get :hello_world + assert_response :success + assert_equal "Hello world!", @response.body + end + + def test_view_paths_override + TestController.prepend_view_path "#{FIXTURE_LOAD_PATH}/override" + get :hello_world + assert_response :success + assert_equal "Hello overridden world!", @response.body + end + + def test_view_paths_override_for_layouts_in_controllers_with_a_module + @controller = Test::SubController.new + Test::SubController.view_paths = [ "#{FIXTURE_LOAD_PATH}/override", FIXTURE_LOAD_PATH, "#{FIXTURE_LOAD_PATH}/override2" ] + get :hello_world + assert_response :success + assert_equal "layout: Hello overridden world!", @response.body + end + + def test_view_paths_override_at_request_time + get :hello_world_at_request_time + assert_response :success + assert_equal "Hello overridden world!", @response.body + end + + def test_decorate_view_paths_with_custom_resolver + decorator_class = Class.new(ActionView::PathResolver) do + def initialize(path_set) + @path_set = path_set + end + + def find_all(*args) + @path_set.find_all(*args).collect do |template| + ::ActionView::Template.new( + "Decorated body", + template.identifier, + template.handler, + { + :virtual_path => template.virtual_path, + :format => template.formats + } + ) + end + end + end + + decorator = decorator_class.new(TestController.view_paths) + TestController.view_paths = ActionView::PathSet.new.push(decorator) + + get :hello_world + assert_response :success + assert_equal "Decorated body", @response.body + end + + def test_inheritance + original_load_paths = ActionController::Base.view_paths + + self.class.class_eval %{ + class A < ActionController::Base; end + class B < A; end + class C < ActionController::Base; end + } + + A.view_paths = ['a/path'] + + assert_paths A, "a/path" + assert_paths A, *B.view_paths + assert_paths C, *original_load_paths + + C.view_paths = [] + assert_nothing_raised { C.append_view_path 'c/path' } + assert_paths C, "c/path" + end + + def test_lookup_context_accessor + assert_equal ["test"], TestController.new.lookup_context.prefixes + end +end diff --git a/actionview/test/lib/controller/view_paths_test.rb b/actionview/test/lib/controller/view_paths_test.rb deleted file mode 100644 index c6e7a523b9..0000000000 --- a/actionview/test/lib/controller/view_paths_test.rb +++ /dev/null @@ -1,174 +0,0 @@ -require 'abstract_unit' - -class ViewLoadPathsTest < ActionController::TestCase - class TestController < ActionController::Base - def self.controller_path() "test" end - - before_action :add_view_path, only: :hello_world_at_request_time - - def hello_world() end - def hello_world_at_request_time() render(:action => 'hello_world') end - - private - def add_view_path - prepend_view_path "#{FIXTURE_LOAD_PATH}/override" - end - end - - module Test - class SubController < ActionController::Base - layout 'test/sub' - def hello_world; render(:template => 'test/hello_world'); end - end - end - - def setup - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - @controller = TestController.new - @paths = TestController.view_paths - end - - def teardown - TestController.view_paths = @paths - end - - def expand(array) - array.map {|x| File.expand_path(x.to_s)} - end - - def assert_paths(*paths) - controller = paths.first.is_a?(Class) ? paths.shift : @controller - assert_equal expand(paths), controller.view_paths.map { |p| p.to_s } - end - - def test_template_load_path_was_set_correctly - assert_paths FIXTURE_LOAD_PATH - end - - def test_controller_appends_view_path_correctly - @controller.append_view_path 'foo' - assert_paths(FIXTURE_LOAD_PATH, "foo") - - @controller.append_view_path(%w(bar baz)) - assert_paths(FIXTURE_LOAD_PATH, "foo", "bar", "baz") - - @controller.append_view_path(FIXTURE_LOAD_PATH) - assert_paths(FIXTURE_LOAD_PATH, "foo", "bar", "baz", FIXTURE_LOAD_PATH) - end - - def test_controller_prepends_view_path_correctly - @controller.prepend_view_path 'baz' - assert_paths("baz", FIXTURE_LOAD_PATH) - - @controller.prepend_view_path(%w(foo bar)) - assert_paths "foo", "bar", "baz", FIXTURE_LOAD_PATH - - @controller.prepend_view_path(FIXTURE_LOAD_PATH) - assert_paths FIXTURE_LOAD_PATH, "foo", "bar", "baz", FIXTURE_LOAD_PATH - end - - def test_template_appends_view_path_correctly - @controller.instance_variable_set :@template, ActionView::Base.new(TestController.view_paths, {}, @controller) - class_view_paths = TestController.view_paths - - @controller.append_view_path 'foo' - assert_paths FIXTURE_LOAD_PATH, "foo" - - @controller.append_view_path(%w(bar baz)) - assert_paths FIXTURE_LOAD_PATH, "foo", "bar", "baz" - assert_paths TestController, *class_view_paths - end - - def test_template_prepends_view_path_correctly - @controller.instance_variable_set :@template, ActionView::Base.new(TestController.view_paths, {}, @controller) - class_view_paths = TestController.view_paths - - @controller.prepend_view_path 'baz' - assert_paths "baz", FIXTURE_LOAD_PATH - - @controller.prepend_view_path(%w(foo bar)) - assert_paths "foo", "bar", "baz", FIXTURE_LOAD_PATH - assert_paths TestController, *class_view_paths - end - - def test_view_paths - get :hello_world - assert_response :success - assert_equal "Hello world!", @response.body - end - - def test_view_paths_override - TestController.prepend_view_path "#{FIXTURE_LOAD_PATH}/override" - get :hello_world - assert_response :success - assert_equal "Hello overridden world!", @response.body - end - - def test_view_paths_override_for_layouts_in_controllers_with_a_module - @controller = Test::SubController.new - Test::SubController.view_paths = [ "#{FIXTURE_LOAD_PATH}/override", FIXTURE_LOAD_PATH, "#{FIXTURE_LOAD_PATH}/override2" ] - get :hello_world - assert_response :success - assert_equal "layout: Hello overridden world!", @response.body - end - - def test_view_paths_override_at_request_time - get :hello_world_at_request_time - assert_response :success - assert_equal "Hello overridden world!", @response.body - end - - def test_decorate_view_paths_with_custom_resolver - decorator_class = Class.new(ActionView::PathResolver) do - def initialize(path_set) - @path_set = path_set - end - - def find_all(*args) - @path_set.find_all(*args).collect do |template| - ::ActionView::Template.new( - "Decorated body", - template.identifier, - template.handler, - { - :virtual_path => template.virtual_path, - :format => template.formats - } - ) - end - end - end - - decorator = decorator_class.new(TestController.view_paths) - TestController.view_paths = ActionView::PathSet.new.push(decorator) - - get :hello_world - assert_response :success - assert_equal "Decorated body", @response.body - end - - def test_inheritance - original_load_paths = ActionController::Base.view_paths - - self.class.class_eval %{ - class A < ActionController::Base; end - class B < A; end - class C < ActionController::Base; end - } - - A.view_paths = ['a/path'] - - assert_paths A, "a/path" - assert_paths A, *B.view_paths - assert_paths C, *original_load_paths - - C.view_paths = [] - assert_nothing_raised { C.append_view_path 'c/path' } - assert_paths C, "c/path" - end - - def test_lookup_context_accessor - assert_equal ["test"], TestController.new.lookup_context.prefixes - end -end -- cgit v1.2.3