aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/abstract/collector_test.rb57
-rw-r--r--actionpack/test/abstract/layouts_test.rb16
-rw-r--r--actionpack/test/controller/helper_test.rb16
-rw-r--r--actionpack/test/dispatch/middleware_stack_test.rb6
-rw-r--r--actionpack/test/dispatch/routing_test.rb21
-rw-r--r--actionpack/test/fixtures/test/translation.erb1
-rw-r--r--actionpack/test/template/translation_helper_test.rb10
7 files changed, 112 insertions, 15 deletions
diff --git a/actionpack/test/abstract/collector_test.rb b/actionpack/test/abstract/collector_test.rb
new file mode 100644
index 0000000000..2ebcebbbb7
--- /dev/null
+++ b/actionpack/test/abstract/collector_test.rb
@@ -0,0 +1,57 @@
+require 'abstract_unit'
+
+module AbstractController
+ module Testing
+ class MyCollector
+ include Collector
+ attr_accessor :responses
+
+ def initialize
+ @responses = []
+ end
+
+ def custom(mime, *args, &block)
+ @responses << [mime, args, block]
+ end
+ end
+
+ class TestCollector < ActiveSupport::TestCase
+ test "responds to default mime types" do
+ collector = MyCollector.new
+ assert_respond_to collector, :html
+ assert_respond_to collector, :text
+ end
+
+ test "does not respond to unknown mime types" do
+ collector = MyCollector.new
+ assert !collector.respond_to?(:unknown)
+ end
+
+ test "register mime types on method missing" do
+ AbstractController::Collector.send(:remove_method, :js)
+ collector = MyCollector.new
+ assert !collector.respond_to?(:js)
+ collector.js
+ assert_respond_to collector, :js
+ end
+
+ test "does not register unknown mime types" do
+ collector = MyCollector.new
+ assert_raise NameError do
+ collector.unknown
+ end
+ end
+
+ test "generated methods call custom with args received" do
+ collector = MyCollector.new
+ collector.html
+ collector.text(:foo)
+ collector.js(:bar) { :baz }
+ assert_equal [Mime::HTML, [], nil], collector.responses[0]
+ assert_equal [Mime::TEXT, [:foo], nil], collector.responses[1]
+ assert_equal [Mime::JS, [:bar]], collector.responses[2][0,2]
+ assert_equal :baz, collector.responses[2][2].call
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb
index 5c96d1cfff..bf02e5a864 100644
--- a/actionpack/test/abstract/layouts_test.rb
+++ b/actionpack/test/abstract/layouts_test.rb
@@ -66,7 +66,15 @@ module AbstractControllerTests
class WithChildOfImplied < WithStringImpliedChild
end
-
+
+ class WithProc < Base
+ layout proc { |c| "omg" }
+
+ def index
+ render :_template => ActionView::Template::Text.new("Hello proc!")
+ end
+ end
+
class WithSymbol < Base
layout :hello
@@ -197,6 +205,12 @@ module AbstractControllerTests
controller.process(:index)
assert_equal "Hello nil!", controller.response_body
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 "OMGHI2U Hello 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
diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb
index fe0961e575..e53e62d1ff 100644
--- a/actionpack/test/controller/helper_test.rb
+++ b/actionpack/test/controller/helper_test.rb
@@ -31,7 +31,7 @@ module LocalAbcHelper
def c() end
end
-class HelperTest < Test::Unit::TestCase
+class HelperTest < ActiveSupport::TestCase
class TestController < ActionController::Base
attr_accessor :delegate_attr
def delegate_method() end
@@ -135,6 +135,18 @@ class HelperTest < Test::Unit::TestCase
assert methods.include?('foobar')
end
+ # TODO Add this deprecation back before Rails 3.0 final release
+ # def test_deprecation
+ # assert_deprecated do
+ # ActionController::Base.helpers_dir = "some/foo/bar"
+ # end
+ # assert_deprecated do
+ # assert_equal ["some/foo/bar"], ActionController::Base.helpers_dir
+ # end
+ # ensure
+ # ActionController::Base.helpers_path = [File.dirname(__FILE__) + '/../fixtures/helpers']
+ # end
+
private
def expected_helper_methods
TestHelper.instance_methods.map {|m| m.to_s }
@@ -154,7 +166,7 @@ class HelperTest < Test::Unit::TestCase
end
-class IsolatedHelpersTest < Test::Unit::TestCase
+class IsolatedHelpersTest < ActiveSupport::TestCase
class A < ActionController::Base
def index
render :inline => '<%= shout %>'
diff --git a/actionpack/test/dispatch/middleware_stack_test.rb b/actionpack/test/dispatch/middleware_stack_test.rb
index f4e18308ae..7cf6365af3 100644
--- a/actionpack/test/dispatch/middleware_stack_test.rb
+++ b/actionpack/test/dispatch/middleware_stack_test.rb
@@ -87,4 +87,10 @@ class MiddlewareStackTest < ActiveSupport::TestCase
end
assert_equal [:foo], @stack.last.send(:build_args)
end
+
+ test "lazy compares so unloaded constants can be loaded" do
+ @stack.use "UnknownMiddleware"
+ @stack.use :"MiddlewareStackTest::BazMiddleware"
+ assert @stack.include?("::MiddlewareStackTest::BazMiddleware")
+ end
end
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 6dccabdb3f..dfe824fd70 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -141,19 +141,18 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
resources :rooms
end
- scope '(:locale)', :locale => /en|pl/ do
- resources :descriptions
- end
+ match '/info' => 'projects#info', :as => 'info'
namespace :admin do
- scope '(/:locale)', :locale => /en|pl/ do
+ scope '(:locale)', :locale => /en|pl/ do
resources :descriptions
end
end
- match '/info' => 'projects#info', :as => 'info'
-
- root :to => 'projects#index'
+ scope '(:locale)', :locale => /en|pl/ do
+ resources :descriptions
+ root :to => 'projects#index'
+ end
end
end
@@ -660,6 +659,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_optional_scoped_root
+ with_test_routes do
+ assert_equal '/en', root_path("en")
+ get '/en'
+ assert_equal 'projects#index', @response.body
+ end
+ end
+
def test_optional_scoped_path
with_test_routes do
assert_equal '/en/descriptions', descriptions_path("en")
diff --git a/actionpack/test/fixtures/test/translation.erb b/actionpack/test/fixtures/test/translation.erb
new file mode 100644
index 0000000000..81a837d1ff
--- /dev/null
+++ b/actionpack/test/fixtures/test/translation.erb
@@ -0,0 +1 @@
+<%= t('.helper') %> \ No newline at end of file
diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb
index d67d2c7911..4b73c44f7e 100644
--- a/actionpack/test/template/translation_helper_test.rb
+++ b/actionpack/test/template/translation_helper_test.rb
@@ -1,9 +1,9 @@
require 'abstract_unit'
-class TranslationHelperTest < Test::Unit::TestCase
+class TranslationHelperTest < ActiveSupport::TestCase
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TranslationHelper
-
+
attr_reader :request
def setup
end
@@ -25,8 +25,8 @@ class TranslationHelperTest < Test::Unit::TestCase
end
def test_scoping_by_partial
- expects(:template).returns(stub(:path_without_format_and_extension => "people/index"))
- I18n.expects(:translate).with("people.index.foo", :locale => 'en', :raise => true).returns("")
- translate ".foo", :locale => 'en'
+ I18n.expects(:translate).with("test.translation.helper", :raise => true).returns("helper")
+ @view = ActionView::Base.new(ActionController::Base.view_paths, {})
+ assert_equal "helper", @view.render(:file => "test/translation")
end
end