From a79790e1a5733694baef3d03d8d79b76948a9d69 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 31 Aug 2009 23:08:20 -0500 Subject: rack-test 0.4.2 has rack 1.1.pre goodies, we'll use it instead --- actionpack/test/dispatch/test_request_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/test_request_test.rb b/actionpack/test/dispatch/test_request_test.rb index 5da02b2ea6..b8e340e055 100644 --- a/actionpack/test/dispatch/test_request_test.rb +++ b/actionpack/test/dispatch/test_request_test.rb @@ -5,7 +5,7 @@ class TestRequestTest < ActiveSupport::TestCase env = ActionDispatch::TestRequest.new.env assert_equal "GET", env.delete("REQUEST_METHOD") - assert_equal "off", env.delete("HTTPS") + assert_equal nil, env.delete("HTTPS") assert_equal "http", env.delete("rack.url_scheme") assert_equal "example.org", env.delete("SERVER_NAME") assert_equal "80", env.delete("SERVER_PORT") @@ -18,7 +18,7 @@ class TestRequestTest < ActiveSupport::TestCase assert_equal "0.0.0.0", env.delete("REMOTE_ADDR") assert_equal "Rails Testing", env.delete("HTTP_USER_AGENT") - assert_equal [1, 0], env.delete("rack.version") + assert_equal [0, 1], env.delete("rack.version") assert_equal "", env.delete("rack.input").string assert_kind_of StringIO, env.delete("rack.errors") assert_equal true, env.delete("rack.multithread") -- cgit v1.2.3 From a5588ffc08bd2860a39d7cb457aefa88dc08fd1a Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Tue, 1 Sep 2009 01:25:39 -0400 Subject: Activate rack-test gem before it's required. This shouldn't be necessary, but should fix the build for now --- actionpack/test/abstract_unit.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 07ba37c51c..07dc282105 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -14,6 +14,8 @@ $stderr.puts "Running old tests on new_base" require 'test/unit' require 'active_support' +gem "rack-test" + require 'active_support/test_case' require 'action_controller' require 'fixture_template' -- cgit v1.2.3 From c5f6e038daf2221ddd5a7534e68f4158d84a5975 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 1 Sep 2009 10:27:19 -0500 Subject: ActionPack test helpers need to activate rack gem --- actionpack/test/abstract_unit.rb | 7 ++++--- actionpack/test/new_base/test_helper.rb | 4 ++++ actionpack/test/old_base/abstract_unit.rb | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 07dc282105..a5222fc96d 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -11,11 +11,12 @@ ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') ENV['new_base'] = "true" $stderr.puts "Running old tests on new_base" +require 'rubygems' +gem "rack", "~> 1.0.0" +gem "rack-test", "~> 0.4.2" + require 'test/unit' require 'active_support' - -gem "rack-test" - require 'active_support/test_case' require 'action_controller' require 'fixture_template' diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb index b7ccd3db8d..0833e1a11d 100644 --- a/actionpack/test/new_base/test_helper.rb +++ b/actionpack/test/new_base/test_helper.rb @@ -2,6 +2,10 @@ $:.unshift(File.dirname(__FILE__) + '/../../lib') $:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib') $:.unshift(File.dirname(__FILE__) + '/../lib') +require 'rubygems' +gem "rack", "~> 1.0.0" +gem "rack-test", "~> 0.4.2" + require 'test/unit' require 'active_support' require 'active_support/test_case' diff --git a/actionpack/test/old_base/abstract_unit.rb b/actionpack/test/old_base/abstract_unit.rb index 3301041a41..b80050bd48 100644 --- a/actionpack/test/old_base/abstract_unit.rb +++ b/actionpack/test/old_base/abstract_unit.rb @@ -8,6 +8,9 @@ $:.unshift(File.dirname(__FILE__) + '/fixtures/helpers') $:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers') require 'rubygems' +gem "rack", "~> 1.0.0" +gem "rack-test", "~> 0.4.2" + require 'yaml' require 'stringio' require 'test/unit' -- cgit v1.2.3 From 66a4585f8830d8f37e62a63df3d095b6284b2a35 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Tue, 1 Sep 2009 15:54:29 -0700 Subject: Fix the */* with Net::HTTP bug [#3100 state:resolved] --- actionpack/test/controller/view_paths_test.rb | 2 +- actionpack/test/lib/fixture_template.rb | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb index c732d1c910..05d2c8407c 100644 --- a/actionpack/test/controller/view_paths_test.rb +++ b/actionpack/test/controller/view_paths_test.rb @@ -43,7 +43,7 @@ class ViewLoadPathsTest < ActionController::TestCase end def expand(array) - array.map {|x| File.expand_path(x)} + array.map {|x| File.expand_path(x.to_s)} end def assert_paths(*paths) diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/test/lib/fixture_template.rb index 8da92180d1..9a9abb691d 100644 --- a/actionpack/test/lib/fixture_template.rb +++ b/actionpack/test/lib/fixture_template.rb @@ -38,10 +38,13 @@ module ActionView #:nodoc: extensions = "" [:locales, :formats].each do |k| - extensions << if exts = details[k] - '(?:' + exts.map {|e| "\\.#{Regexp.escape(e.to_s)}"}.join('|') + ')?' + # TODO: OMG NO + if details[k] == [:"*/*"] + extensions << formats_regexp if k == :formats + elsif exts = details[k] + extensions << '(?:' + exts.map {|e| "\\.#{Regexp.escape(e.to_s)}"}.join('|') + ')?' else - k == :formats ? formats_regexp : '' + extensions << formats_regexp if k == :formats end end -- cgit v1.2.3 From e0f1a7dc191ffebc9f6cadb6232e567fee8aa491 Mon Sep 17 00:00:00 2001 From: Jay Pignata Date: Thu, 3 Sep 2009 11:50:01 -0500 Subject: If session_options[:id] is requested when using CookieStore, unmarshal the session to access it [#2268 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/dispatch/session/cookie_store_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index 0723a76d2b..d695be0be4 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -30,7 +30,7 @@ class CookieStoreTest < ActionController::IntegrationTest end def get_session_id - render :text => "foo: #{session[:foo].inspect}; id: #{request.session_options[:id]}" + render :text => "id: #{request.session_options[:id]}" end def call_reset_session @@ -119,7 +119,7 @@ class CookieStoreTest < ActionController::IntegrationTest get '/get_session_id' assert_response :success - assert_equal "foo: \"bar\"; id: #{session_id}", response.body + assert_equal "id: #{session_id}", response.body end end -- cgit v1.2.3 From f3fc5c4b5f36db37edc8ab553a35b06b48226c0a Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Wed, 2 Sep 2009 15:00:22 -0700 Subject: Refactor ActionView::Resolver --- actionpack/test/lib/fixture_template.rb | 66 ++++------------------ actionpack/test/new_base/render_file_test.rb | 2 +- .../test/template/compiled_templates_test.rb | 3 + 3 files changed, 16 insertions(+), 55 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/test/lib/fixture_template.rb index 9a9abb691d..0a365b3a7e 100644 --- a/actionpack/test/lib/fixture_template.rb +++ b/actionpack/test/lib/fixture_template.rb @@ -1,70 +1,28 @@ module ActionView #:nodoc: - class FixtureResolver < Resolver + class FixtureResolver < PathResolver def initialize(hash = {}, options = {}) super(options) @hash = hash end - def find_templates(name, details, prefix, partial) - if regexp = details_to_regexp(name, details, prefix, partial) - cached(regexp) do - templates = [] - @hash.select { |k,v| k =~ regexp }.each do |path, source| - templates << Template.new(source, path, *path_to_details(path)) - end - templates.sort_by {|t| -t.details.values.compact.size } - end - end - end - private - def formats_regexp - @formats_regexp ||= begin - formats = Mime::SET.symbols - '(?:' + formats.map { |l| "\\.#{Regexp.escape(l.to_s)}" }.join('|') + ')?' - end - end - - def handler_regexp - e = TemplateHandlers.extensions.map{|h| "\\.#{Regexp.escape(h.to_s)}"}.join("|") - "(?:#{e})" + def or_extensions(array) + "(?:" << array.map {|e| e && Regexp.escape(".#{e}")}.join("|") << ")" end - def details_to_regexp(name, details, prefix, partial) - path = "" - path << "#{prefix}/" unless prefix.empty? - path << (partial ? "_#{name}" : name) - - extensions = "" - [:locales, :formats].each do |k| - # TODO: OMG NO - if details[k] == [:"*/*"] - extensions << formats_regexp if k == :formats - elsif exts = details[k] - extensions << '(?:' + exts.map {|e| "\\.#{Regexp.escape(e.to_s)}"}.join('|') + ')?' - else - extensions << formats_regexp if k == :formats - end + def query(path, exts) + query = Regexp.escape(path) + exts.each do |ext| + query << '(?:' << ext.map {|e| e && Regexp.escape(".#{e}") }.join('|') << ')' end - %r'^#{Regexp.escape(path)}#{extensions}#{handler_regexp}$' - end - - # TODO: fix me - # :api: plugin - def path_to_details(path) - # [:erb, :format => :html, :locale => :en, :partial => true/false] - if m = path.match(%r'(_)?[\w-]+((?:\.[\w-]+)*)\.(\w+)$') - partial = m[1] == '_' - details = (m[2]||"").split('.').reject { |e| e.empty? } - handler = Template.handler_class_for_extension(m[3]) - - format = Mime[details.last] && details.pop.to_sym - locale = details.last && details.pop.to_sym - - return handler, :format => format, :locale => locale, :partial => partial + templates = [] + @hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source| + templates << Template.new(source, path, *path_to_details(path)) end + templates.sort_by {|t| -t.details.values.compact.size } end + end end \ No newline at end of file diff --git a/actionpack/test/new_base/render_file_test.rb b/actionpack/test/new_base/render_file_test.rb index 769949be0c..8d7f49dbc2 100644 --- a/actionpack/test/new_base/render_file_test.rb +++ b/actionpack/test/new_base/render_file_test.rb @@ -3,7 +3,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") module RenderFile class BasicController < ActionController::Base - self.view_paths = "." + self.view_paths = File.dirname(__FILE__) def index render :file => File.join(File.dirname(__FILE__), *%w[.. fixtures test hello_world]) diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index 7734e6da73..632988bb2e 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -14,6 +14,9 @@ class CompiledTemplatesTest < Test::Unit::TestCase assert_equal "two", render(:file => "test/render_file_with_locals_and_default.erb", :locals => { :secret => "two" }) end + # This is broken in 1.8.6 (not supported in Rails 3.0) because the cache uses a Hash + # key. Since Ruby 1.8.6 implements Hash#hash using the hash's object_id, it will never + # successfully get a cache hit here. def test_template_changes_are_not_reflected_with_cached_templates assert_equal "Hello world!", render(:file => "test/hello_world.erb") modify_template "test/hello_world.erb", "Goodbye world!" do -- cgit v1.2.3 From f61dc0ef6511e585f0b6a8d02b00c17b2388b04a Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 3 Sep 2009 11:40:03 -0700 Subject: Remove a useless method in the fixture template class --- actionpack/test/lib/fixture_template.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/test/lib/fixture_template.rb index 0a365b3a7e..6b9e7c5270 100644 --- a/actionpack/test/lib/fixture_template.rb +++ b/actionpack/test/lib/fixture_template.rb @@ -7,10 +7,6 @@ module ActionView #:nodoc: private - def or_extensions(array) - "(?:" << array.map {|e| e && Regexp.escape(".#{e}")}.join("|") << ")" - end - def query(path, exts) query = Regexp.escape(path) exts.each do |ext| -- cgit v1.2.3 From 4b6321efa9be103ca1e00c13dd9d955b076dd31e Mon Sep 17 00:00:00 2001 From: Sam Pohlenz Date: Thu, 3 Sep 2009 14:00:40 -0500 Subject: Don't raise exceptions for missing javascript_include_tag or stylesheet_link_tag sources unless the :cache or :concat options are given. [#2738 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/template/asset_tag_helper_test.rb | 62 +++++++++++++++++++++-- 1 file changed, 58 insertions(+), 4 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 28f9d48671..83fc6a282c 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -213,11 +213,11 @@ class AssetTagHelperTest < ActionView::TestCase end def test_javascript_include_tag_with_missing_source - assert_raise(Errno::ENOENT) { + assert_nothing_raised { javascript_include_tag('missing_security_guard') } - assert_raise(Errno::ENOENT) { + assert_nothing_raised { javascript_include_tag(:defaults, 'missing_security_guard') } @@ -276,7 +276,7 @@ class AssetTagHelperTest < ActionView::TestCase end def test_stylesheet_link_tag_with_missing_source - assert_raise(Errno::ENOENT) { + assert_nothing_raised { stylesheet_link_tag('missing_security_guard') } @@ -639,6 +639,40 @@ class AssetTagHelperTest < ActionView::TestCase assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) end + def test_caching_javascript_include_tag_when_caching_on_and_missing_javascript_file + ENV["RAILS_ASSET_ID"] = "" + ActionController::Base.perform_caching = true + + assert_raise(Errno::ENOENT) { + javascript_include_tag('bank', 'robber', 'missing_security_guard', :cache => true) + } + + assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) + + assert_raise(Errno::ENOENT) { + javascript_include_tag('bank', 'robber', 'missing_security_guard', :cache => "money") + } + + assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) + end + + def test_caching_javascript_include_tag_when_caching_off_and_missing_javascript_file + ENV["RAILS_ASSET_ID"] = "" + ActionController::Base.perform_caching = false + + assert_raise(Errno::ENOENT) { + javascript_include_tag('bank', 'robber', 'missing_security_guard', :cache => true) + } + + assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) + + assert_raise(Errno::ENOENT) { + javascript_include_tag('bank', 'robber', 'missing_security_guard', :cache => "money") + } + + assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) + end + def test_caching_stylesheet_link_tag_when_caching_on ENV["RAILS_ASSET_ID"] = "" ActionController::Base.asset_host = 'http://a0.example.com' @@ -709,7 +743,6 @@ class AssetTagHelperTest < ActionView::TestCase def test_caching_stylesheet_link_tag_when_caching_on_and_missing_css_file ENV["RAILS_ASSET_ID"] = "" - ActionController::Base.asset_host = 'http://a0.example.com' ActionController::Base.perform_caching = true assert_raise(Errno::ENOENT) { @@ -729,6 +762,27 @@ class AssetTagHelperTest < ActionView::TestCase FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) end + def test_caching_stylesheet_link_tag_when_caching_off_and_missing_css_file + ENV["RAILS_ASSET_ID"] = "" + ActionController::Base.perform_caching = false + + assert_raise(Errno::ENOENT) { + stylesheet_link_tag('bank', 'robber', 'missing_security_guard', :cache => true) + } + + assert ! File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) + + assert_raise(Errno::ENOENT) { + stylesheet_link_tag('bank', 'robber', 'missing_security_guard', :cache => "money") + } + + assert ! File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) + + ensure + FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) + FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) + end + def test_caching_stylesheet_link_tag_when_caching_on_with_proc_asset_host ENV["RAILS_ASSET_ID"] = "" ActionController::Base.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" } -- cgit v1.2.3 From e3744166ec0b98b76175ee70bda8051fb05690e7 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 3 Sep 2009 12:41:28 -0700 Subject: Refactor ActionController to use find_template and template_exists? --- actionpack/test/abstract_controller/abstract_controller_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb index 7991436703..3b4046a424 100644 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ b/actionpack/test/abstract_controller/abstract_controller_test.rb @@ -148,10 +148,10 @@ module AbstractController private def self.layout(formats) begin - view_paths.find(name.underscore, {:formats => formats}, "layouts") + find_template(name.underscore, {:formats => formats}, :_prefix => "layouts") rescue ActionView::MissingTemplate begin - view_paths.find("application", {:formats => formats}, "layouts") + find_template("application", {:formats => formats}, :_prefix => "layouts") rescue ActionView::MissingTemplate end end -- cgit v1.2.3 From 487ee41d2fe9216cd7dd194d747b5d3252180ba9 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 3 Sep 2009 12:58:43 -0700 Subject: Test for previous commit (we wrote it first, I swear) --- actionpack/test/new_base/content_negotiation_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 actionpack/test/new_base/content_negotiation_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/new_base/content_negotiation_test.rb b/actionpack/test/new_base/content_negotiation_test.rb new file mode 100644 index 0000000000..d2f732738d --- /dev/null +++ b/actionpack/test/new_base/content_negotiation_test.rb @@ -0,0 +1,18 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") + +module ContentNegotiation + + # This has no layout and it works + class BasicController < ActionController::Base + self.view_paths = [ActionView::FixtureResolver.new( + "content_negotiation/basic/hello.html.erb" => "Hello world <%= request.formats %>!" + )] + end + + class TestContentNegotiation < SimpleRouteCase + test "A */* Accept header will return HTML" do + get "/content_negotiation/basic/hello", {}, "HTTP_ACCEPT" => "*/*" + assert_body "Hello world */*!" + end + end +end \ No newline at end of file -- cgit v1.2.3 From c3accd7ded9ceaaecad55a2b04940e1f0631a614 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 5 Sep 2009 19:39:33 -0500 Subject: Fix failing isolated routing test --- actionpack/test/controller/routing_test.rb | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index d20684296f..17f5e86a56 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -1781,23 +1781,23 @@ class RouteSetTest < ActiveSupport::TestCase end def test_default_route_recognition - expected = {:controller => 'accounts', :action => 'show', :id => '10'} - assert_equal expected, default_route_set.recognize_path('/accounts/show/10') - assert_equal expected, default_route_set.recognize_path('/accounts/show/10/') + expected = {:controller => 'pages', :action => 'show', :id => '10'} + assert_equal expected, default_route_set.recognize_path('/pages/show/10') + assert_equal expected, default_route_set.recognize_path('/pages/show/10/') expected[:id] = 'jamis' - assert_equal expected, default_route_set.recognize_path('/accounts/show/jamis/') + assert_equal expected, default_route_set.recognize_path('/pages/show/jamis/') expected.delete :id - assert_equal expected, default_route_set.recognize_path('/accounts/show') - assert_equal expected, default_route_set.recognize_path('/accounts/show/') + assert_equal expected, default_route_set.recognize_path('/pages/show') + assert_equal expected, default_route_set.recognize_path('/pages/show/') expected[:action] = 'index' - assert_equal expected, default_route_set.recognize_path('/accounts/') - assert_equal expected, default_route_set.recognize_path('/accounts') + assert_equal expected, default_route_set.recognize_path('/pages/') + assert_equal expected, default_route_set.recognize_path('/pages') assert_raise(ActionController::RoutingError) { default_route_set.recognize_path('/') } - assert_raise(ActionController::RoutingError) { default_route_set.recognize_path('/accounts/how/goood/it/is/to/be/free') } + assert_raise(ActionController::RoutingError) { default_route_set.recognize_path('/pages/how/goood/it/is/to/be/free') } end def test_default_route_should_omit_default_action @@ -1813,15 +1813,15 @@ class RouteSetTest < ActiveSupport::TestCase end def test_default_route_should_uri_escape_pluses - expected = { :controller => 'accounts', :action => 'show', :id => 'hello world' } - assert_equal expected, default_route_set.recognize_path('/accounts/show/hello world') - assert_equal expected, default_route_set.recognize_path('/accounts/show/hello%20world') - assert_equal '/accounts/show/hello%20world', default_route_set.generate(expected, expected) + expected = { :controller => 'pages', :action => 'show', :id => 'hello world' } + assert_equal expected, default_route_set.recognize_path('/pages/show/hello world') + assert_equal expected, default_route_set.recognize_path('/pages/show/hello%20world') + assert_equal '/pages/show/hello%20world', default_route_set.generate(expected, expected) expected[:id] = 'hello+world' - assert_equal expected, default_route_set.recognize_path('/accounts/show/hello+world') - assert_equal expected, default_route_set.recognize_path('/accounts/show/hello%2Bworld') - assert_equal '/accounts/show/hello+world', default_route_set.generate(expected, expected) + assert_equal expected, default_route_set.recognize_path('/pages/show/hello+world') + assert_equal expected, default_route_set.recognize_path('/pages/show/hello%2Bworld') + assert_equal '/pages/show/hello+world', default_route_set.generate(expected, expected) end def test_parameter_shell -- cgit v1.2.3 From 1c02fc295dc8281b8c3352bdd95869d5421aff08 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 6 Sep 2009 21:19:29 -0500 Subject: Fix isolated running of ActionPackAssertionTest --- actionpack/test/controller/action_pack_assertions_test.rb | 1 + actionpack/test/lib/controller/fake_controllers.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 453812c128..901cb940ea 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'action_controller/vendor/html-scanner' +require 'controller/fake_controllers' # a controller class to facilitate the tests class ActionPackAssertionsController < ActionController::Base diff --git a/actionpack/test/lib/controller/fake_controllers.rb b/actionpack/test/lib/controller/fake_controllers.rb index 6e02e2d21b..d41547b902 100644 --- a/actionpack/test/lib/controller/fake_controllers.rb +++ b/actionpack/test/lib/controller/fake_controllers.rb @@ -9,7 +9,7 @@ module Admin class UserController < ActionController::Base; end class NewsFeedController < ActionController::Base; end end - +class ElsewhereController < ActionController::Base; end # For speed test class SpeedController < ActionController::Base; end -- cgit v1.2.3 From 9f47f8d892ee35a08b5556acc4ddbe93b0461cfd Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 6 Sep 2009 21:42:05 -0500 Subject: Fix isolated running of AddressesTest --- actionpack/test/controller/addresses_render_test.rb | 8 ++------ actionpack/test/lib/controller/fake_controllers.rb | 1 + 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/addresses_render_test.rb b/actionpack/test/controller/addresses_render_test.rb index 2d2a2745b0..c1cd22113d 100644 --- a/actionpack/test/controller/addresses_render_test.rb +++ b/actionpack/test/controller/addresses_render_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'logger' +require 'controller/fake_controllers' class Address def Address.count(conditions = nil, join = nil) @@ -15,13 +16,8 @@ class Address end end -class AddressesTestController < ActionController::Base - def self.controller_name; "addresses"; end - def self.controller_path; "addresses"; end -end - class AddressesTest < ActionController::TestCase - tests AddressesTestController + tests AddressesController def setup super diff --git a/actionpack/test/lib/controller/fake_controllers.rb b/actionpack/test/lib/controller/fake_controllers.rb index d41547b902..e7589e29ca 100644 --- a/actionpack/test/lib/controller/fake_controllers.rb +++ b/actionpack/test/lib/controller/fake_controllers.rb @@ -10,6 +10,7 @@ module Admin class NewsFeedController < ActionController::Base; end end class ElsewhereController < ActionController::Base; end +class AddressesController < ActionController::Base; end # For speed test class SpeedController < ActionController::Base; end -- cgit v1.2.3 From ab8aac09d654c710d8bf4b6410c60ea98e5fd5dc Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 6 Sep 2009 22:01:58 -0500 Subject: Need to reset session in internal integration tests after altering the route set --- actionpack/test/controller/integration_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 197ba0c69c..93f5bfa272 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -371,6 +371,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest c.connect "/:action" end end + reset! yield end end -- cgit v1.2.3 From c531bd66651639c25cc8d1b90dd6b56e5db3581b Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 6 Sep 2009 22:29:29 -0500 Subject: Cleanup hacky routing with controller_path in url helper tests. This doesn't work in real life anyway. --- actionpack/test/lib/controller/fake_controllers.rb | 2 +- actionpack/test/template/url_helper_test.rb | 118 ++++++++++----------- 2 files changed, 57 insertions(+), 63 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/lib/controller/fake_controllers.rb b/actionpack/test/lib/controller/fake_controllers.rb index e7589e29ca..b96e91f4f7 100644 --- a/actionpack/test/lib/controller/fake_controllers.rb +++ b/actionpack/test/lib/controller/fake_controllers.rb @@ -11,6 +11,7 @@ module Admin end class ElsewhereController < ActionController::Base; end class AddressesController < ActionController::Base; end +class SessionsController < ActionController::Base; end # For speed test class SpeedController < ActionController::Base; end @@ -25,7 +26,6 @@ class UsersController < SpeedController; end class SettingsController < SpeedController; end class ChannelsController < SpeedController; end class ChannelVideosController < SpeedController; end -class SessionsController < SpeedController; end class LostPasswordsController < SpeedController; end class PagesController < SpeedController; end diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 0e24fbd24d..44f1925653 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -367,25 +367,25 @@ class UrlHelperTest < ActionView::TestCase end end -class UrlHelperWithControllerTest < ActionView::TestCase - class UrlHelperController < ActionController::Base - def self.controller_path; 'url_helper_with_controller' end - - def show_url_for - render :inline => "<%= url_for :controller => 'url_helper_with_controller', :action => 'show_url_for' %>" - end +class UrlHelperController < ActionController::Base + def self.controller_path; 'url_helper_with_controller' end - def show_named_route - render :inline => "<%= show_named_route_#{params[:kind]} %>" - end + def show_url_for + render :inline => "<%= url_for :controller => 'url_helper_with_controller', :action => 'show_url_for' %>" + end - def nil_url_for - render :inline => '<%= url_for(nil) %>' - end + def show_named_route + render :inline => "<%= show_named_route_#{params[:kind]} %>" + end - def rescue_action(e) raise e end + def nil_url_for + render :inline => '<%= url_for(nil) %>' end + def rescue_action(e) raise e end +end + +class UrlHelperWithControllerTest < ActionView::TestCase tests ActionView::Helpers::UrlHelper def setup @@ -416,7 +416,7 @@ class UrlHelperWithControllerTest < ActionView::TestCase def test_url_for_nil_returns_current_path get :nil_url_for - assert_equal '/url_helper_with_controller/nil_url_for', @response.body + assert_equal '/url_helper/nil_url_for', @response.body end def test_named_route_should_show_host_and_path_using_controller_default_url_options @@ -436,35 +436,33 @@ class UrlHelperWithControllerTest < ActionView::TestCase def with_url_helper_routing with_routing do |set| set.draw do |map| - map.show_named_route 'url_helper_with_controller/show_named_route', :controller => 'url_helper_with_controller', :action => 'show_named_route' + map.show_named_route 'url_helper_with_controller/show_named_route', :controller => 'url_helper', :action => 'show_named_route' end yield end end end -class LinkToUnlessCurrentWithControllerTest < ActionView::TestCase - class TasksController < ActionController::Base - def self.controller_path; 'tasks' end - - def index - render_default - end +class TasksController < ActionController::Base + def index + render_default + end - def show - render_default - end + def show + render_default + end - def rescue_action(e) raise e end + def rescue_action(e) raise e end - protected - def render_default - render :inline => - "<%= link_to_unless_current(\"tasks\", tasks_path) %>\n" + - "<%= link_to_unless_current(\"tasks\", tasks_url) %>" - end - end + protected + def render_default + render :inline => + "<%= link_to_unless_current(\"tasks\", tasks_path) %>\n" + + "<%= link_to_unless_current(\"tasks\", tasks_url) %>" + end +end +class LinkToUnlessCurrentWithControllerTest < ActionView::TestCase tests ActionView::Helpers::UrlHelper def setup @@ -537,41 +535,37 @@ class Session end end -class PolymorphicControllerTest < ActionView::TestCase - class WorkshopsController < ActionController::Base - def self.controller_path; 'workshops' end - - def index - @workshop = Workshop.new(1, true) - render :inline => "<%= url_for(@workshop) %>\n<%= link_to('Workshop', @workshop) %>" - end - - def show - @workshop = Workshop.new(params[:id], false) - render :inline => "<%= url_for(@workshop) %>\n<%= link_to('Workshop', @workshop) %>" - end - - def rescue_action(e) raise e end +class WorkshopsController < ActionController::Base + def index + @workshop = Workshop.new(1, true) + render :inline => "<%= url_for(@workshop) %>\n<%= link_to('Workshop', @workshop) %>" end - class SessionsController < ActionController::Base - def self.controller_path; 'sessions' end + def show + @workshop = Workshop.new(params[:id], false) + render :inline => "<%= url_for(@workshop) %>\n<%= link_to('Workshop', @workshop) %>" + end - def index - @workshop = Workshop.new(params[:workshop_id], false) - @session = Session.new(1, true) - render :inline => "<%= url_for([@workshop, @session]) %>\n<%= link_to('Session', [@workshop, @session]) %>" - end + def rescue_action(e) raise e end +end - def show - @workshop = Workshop.new(params[:workshop_id], false) - @session = Session.new(params[:id], false) - render :inline => "<%= url_for([@workshop, @session]) %>\n<%= link_to('Session', [@workshop, @session]) %>" - end +class SessionsController < ActionController::Base + def index + @workshop = Workshop.new(params[:workshop_id], false) + @session = Session.new(1, true) + render :inline => "<%= url_for([@workshop, @session]) %>\n<%= link_to('Session', [@workshop, @session]) %>" + end - def rescue_action(e) raise e end + def show + @workshop = Workshop.new(params[:workshop_id], false) + @session = Session.new(params[:id], false) + render :inline => "<%= url_for([@workshop, @session]) %>\n<%= link_to('Session', [@workshop, @session]) %>" end + def rescue_action(e) raise e end +end + +class PolymorphicControllerTest < ActionView::TestCase tests ActionView::Helpers::UrlHelper def setup -- cgit v1.2.3 From 2ae84e04aa18f6b35c628349c8c816fe1538cd70 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 6 Sep 2009 23:02:55 -0500 Subject: Add fake controllers for url rewriter tests --- actionpack/test/controller/url_rewriter_test.rb | 1 + actionpack/test/lib/controller/fake_controllers.rb | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index 9b8d07222b..4c4bf9ade4 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'controller/fake_controllers' ActionController::UrlRewriter diff --git a/actionpack/test/lib/controller/fake_controllers.rb b/actionpack/test/lib/controller/fake_controllers.rb index b96e91f4f7..22729188a2 100644 --- a/actionpack/test/lib/controller/fake_controllers.rb +++ b/actionpack/test/lib/controller/fake_controllers.rb @@ -12,6 +12,11 @@ end class ElsewhereController < ActionController::Base; end class AddressesController < ActionController::Base; end class SessionsController < ActionController::Base; end +class FooController < ActionController::Base; end +class CController < ActionController::Base; end +class HiController < ActionController::Base; end +class BraveController < ActionController::Base; end +class ImageController < ActionController::Base; end # For speed test class SpeedController < ActionController::Base; end -- cgit v1.2.3 From 314e18aba24709310a60b5fe2b1930fe1ef3ed51 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 6 Sep 2009 23:09:47 -0500 Subject: Need to reset session for AR session tests after altering the route set --- actionpack/test/activerecord/active_record_store_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/test') diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb index a46ce7a0aa..19d9c955a5 100644 --- a/actionpack/test/activerecord/active_record_store_test.rb +++ b/actionpack/test/activerecord/active_record_store_test.rb @@ -176,6 +176,7 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest c.connect "/:action" end end + reset_app! yield end end -- cgit v1.2.3 From 1a0f822037c408a392ffa7b6e1ecbe5951ab48db Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 6 Sep 2009 23:21:04 -0500 Subject: Use draw/connect mapper api instead of directly using add_named_route --- actionpack/test/controller/routing_test.rb | 46 ++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 17f5e86a56..1aabf71cad 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -232,14 +232,18 @@ class LegacyRouteSetTests < Test::Unit::TestCase end def test_basic_named_route - rs.add_named_route :home, '', :controller => 'content', :action => 'list' + rs.draw do |map| + map.home '', :controller => 'content', :action => 'list' + end x = setup_for_named_route assert_equal("http://test.host/", x.send(:home_url)) end def test_basic_named_route_with_relative_url_root - rs.add_named_route :home, '', :controller => 'content', :action => 'list' + rs.draw do |map| + map.home '', :controller => 'content', :action => 'list' + end x = setup_for_named_route ActionController::Base.relative_url_root = "/foo" assert_equal("http://test.host/foo/", @@ -249,14 +253,18 @@ class LegacyRouteSetTests < Test::Unit::TestCase end def test_named_route_with_option - rs.add_named_route :page, 'page/:title', :controller => 'content', :action => 'show_page' + rs.draw do |map| + map.page 'page/:title', :controller => 'content', :action => 'show_page' + end x = setup_for_named_route assert_equal("http://test.host/page/new%20stuff", x.send(:page_url, :title => 'new stuff')) end def test_named_route_with_default - rs.add_named_route :page, 'page/:title', :controller => 'content', :action => 'show_page', :title => 'AboutPage' + rs.draw do |map| + map.page 'page/:title', :controller => 'content', :action => 'show_page', :title => 'AboutPage' + end x = setup_for_named_route assert_equal("http://test.host/page/AboutRails", x.send(:page_url, :title => "AboutRails")) @@ -264,36 +272,46 @@ class LegacyRouteSetTests < Test::Unit::TestCase end def test_named_route_with_name_prefix - rs.add_named_route :page, 'page', :controller => 'content', :action => 'show_page', :name_prefix => 'my_' + rs.draw do |map| + map.page 'page', :controller => 'content', :action => 'show_page', :name_prefix => 'my_' + end x = setup_for_named_route assert_equal("http://test.host/page", x.send(:my_page_url)) end def test_named_route_with_path_prefix - rs.add_named_route :page, 'page', :controller => 'content', :action => 'show_page', :path_prefix => 'my' + rs.draw do |map| + map.page 'page', :controller => 'content', :action => 'show_page', :path_prefix => 'my' + end x = setup_for_named_route assert_equal("http://test.host/my/page", x.send(:page_url)) end def test_named_route_with_blank_path_prefix - rs.add_named_route :page, 'page', :controller => 'content', :action => 'show_page', :path_prefix => '' + rs.draw do |map| + map.page 'page', :controller => 'content', :action => 'show_page', :path_prefix => '' + end x = setup_for_named_route assert_equal("http://test.host/page", x.send(:page_url)) end def test_named_route_with_nested_controller - rs.add_named_route :users, 'admin/user', :controller => 'admin/user', :action => 'index' + rs.draw do |map| + map.users 'admin/user', :controller => 'admin/user', :action => 'index' + end x = setup_for_named_route assert_equal("http://test.host/admin/user", x.send(:users_url)) end def test_optimised_named_route_call_never_uses_url_for - rs.add_named_route :users, 'admin/user', :controller => '/admin/user', :action => 'index' - rs.add_named_route :user, 'admin/user/:id', :controller=>'/admin/user', :action=>'show' + rs.draw do |map| + map.users 'admin/user', :controller => '/admin/user', :action => 'index' + map.user 'admin/user/:id', :controller=>'/admin/user', :action=>'show' + end x = setup_for_named_route x.expects(:url_for).never x.send(:users_url) @@ -303,7 +321,9 @@ class LegacyRouteSetTests < Test::Unit::TestCase end def test_optimised_named_route_with_host - rs.add_named_route :pages, 'pages', :controller => 'content', :action => 'show_page', :host => 'foo.com' + rs.draw do |map| + map.pages 'pages', :controller => 'content', :action => 'show_page', :host => 'foo.com' + end x = setup_for_named_route x.expects(:url_for).with(:host => 'foo.com', :only_path => false, :controller => 'content', :action => 'show_page', :use_route => :pages).once x.send(:pages_url) @@ -378,7 +398,9 @@ class LegacyRouteSetTests < Test::Unit::TestCase end def test_paths_slashes_unescaped_with_ordered_parameters - rs.add_named_route :path, '/file/*path', :controller => 'content' + rs.draw do |map| + map.path '/file/*path', :controller => 'content' + end # No / to %2F in URI, only for query params. x = setup_for_named_route -- cgit v1.2.3 From f024aabee37520e8c894a83710fc121c0056dd2b Mon Sep 17 00:00:00 2001 From: Nathaniel Talbott Date: Thu, 10 Sep 2009 21:15:18 -0400 Subject: Fix filtering parameters when there are Fixnum or other un-dupable values. [#3184 state:committed] Signed-off-by: Jeremy Kemper --- actionpack/test/controller/filter_params_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/filter_params_test.rb b/actionpack/test/controller/filter_params_test.rb index f7864745eb..19232c6bc9 100644 --- a/actionpack/test/controller/filter_params_test.rb +++ b/actionpack/test/controller/filter_params_test.rb @@ -35,6 +35,7 @@ class FilterParamTest < ActionController::TestCase test_hashes = [[{},{},[]], [{'foo'=>nil},{'foo'=>nil},[]], [{'foo'=>'bar'},{'foo'=>'bar'},[]], + [{'foo'=>1},{'foo'=>1},[]], [{'foo'=>'bar'},{'foo'=>'bar'},%w'food'], [{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'], [{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'], -- cgit v1.2.3 From 1b78e9bba3bd39c4669ff6c640b7df069185c22c Mon Sep 17 00:00:00 2001 From: Andrew France Date: Sat, 11 Jul 2009 16:38:35 +0200 Subject: Allow fields_for on a nested_attributes association to accept an explicit collection to be used. [#2648 state:resolved] Signed-off-by: Eloy Duran --- actionpack/test/template/form_helper_test.rb | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 8fd018f86d..be15b06372 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -784,6 +784,42 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_nested_fields_for_with_an_empty_supplied_attributes_collection + form_for(:post, @post) do |f| + concat f.text_field(:title) + f.fields_for(:comments, []) do |cf| + concat cf.text_field(:name) + end + end + + expected = '
' + + '' + + '
' + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_existing_records_on_a_supplied_nested_attributes_collection + @post.comments = Array.new(2) { |id| Comment.new(id + 1) } + + form_for(:post, @post) do |f| + concat f.text_field(:title) + f.fields_for(:comments, @post.comments) do |cf| + concat cf.text_field(:name) + end + end + + expected = '
' + + '' + + '' + + '' + + '' + + '' + + '
' + + assert_dom_equal expected, output_buffer + end + def test_nested_fields_for_on_a_nested_attributes_collection_association_yields_only_builder @post.comments = [Comment.new(321), Comment.new] yielded_comments = [] -- cgit v1.2.3 From 7152a4e9a654ccd0b9fefdcf34dc6aac655a727a Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sat, 12 Sep 2009 13:51:15 -0500 Subject: Add per-controller middleware --- actionpack/test/new_base/middleware_test.rb | 77 +++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 actionpack/test/new_base/middleware_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/new_base/middleware_test.rb b/actionpack/test/new_base/middleware_test.rb new file mode 100644 index 0000000000..15aef270e2 --- /dev/null +++ b/actionpack/test/new_base/middleware_test.rb @@ -0,0 +1,77 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") + +module MiddlewareTest + class MyMiddleware + def initialize(app) + @app = app + end + + def call(env) + result = @app.call(env) + result[1]["Middleware-Test"] = "Success" + result[1]["Middleware-Order"] = "First" + result + end + end + + class ExclaimerMiddleware + def initialize(app) + @app = app + end + + def call(env) + result = @app.call(env) + result[1]["Middleware-Order"] << "!" + result + end + end + + class MyController < ActionController::Metal + use MyMiddleware + + middleware.insert_before MyMiddleware, ExclaimerMiddleware + + def index + self.response_body = "Hello World" + end + end + + class InheritedController < MyController + end + + module MiddlewareTests + extend ActiveSupport::Testing::Declarative + + test "middleware that is 'use'd is called as part of the Rack application" do + result = @app.call(env_for("/")) + assert_equal "Hello World", result[2] + assert_equal "Success", result[1]["Middleware-Test"] + end + + test "the middleware stack is exposed as 'middleware' in the controller" do + result = @app.call(env_for("/")) + assert_equal "First!", result[1]["Middleware-Order"] + end + end + + class TestMiddleware < ActiveSupport::TestCase + include MiddlewareTests + + def setup + @app = MyController.action(:index) + end + + def env_for(url) + Rack::MockRequest.env_for(url) + end + end + + class TestInheritedMiddleware < TestMiddleware + def setup + @app = InheritedController.action(:index) + end + + test "middleware inherits" do + end + end +end -- cgit v1.2.3 From ddb4600ce608b14f9fa07bf1196b78e1d43ad999 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sat, 12 Sep 2009 15:22:11 -0500 Subject: Get ActionPack's test running on bundled gems. This should make running tests on new machines, as well as CI, work well. --- actionpack/test/abstract_unit.rb | 9 ++------- actionpack/test/new_base/test_helper.rb | 5 +---- 2 files changed, 3 insertions(+), 11 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index a5222fc96d..528180ae32 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -1,20 +1,15 @@ $:.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') $:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers') +require File.join(File.dirname(__FILE__), "..", "vendor", "gems", "environment") + ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') ENV['new_base'] = "true" $stderr.puts "Running old tests on new_base" -require 'rubygems' -gem "rack", "~> 1.0.0" -gem "rack-test", "~> 0.4.2" - require 'test/unit' require 'active_support' require 'active_support/test_case' diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb index 0833e1a11d..5a901ab9d8 100644 --- a/actionpack/test/new_base/test_helper.rb +++ b/actionpack/test/new_base/test_helper.rb @@ -1,10 +1,7 @@ $:.unshift(File.dirname(__FILE__) + '/../../lib') -$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib') $:.unshift(File.dirname(__FILE__) + '/../lib') -require 'rubygems' -gem "rack", "~> 1.0.0" -gem "rack-test", "~> 0.4.2" +require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "vendor", "gems", "environment")) require 'test/unit' require 'active_support' -- cgit v1.2.3 From a9f5f4bb451a0e0c666dc694a870371e7cc3ee99 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 13 Sep 2009 12:42:13 -0500 Subject: Don't force test suite to use bundler --- actionpack/test/abstract_unit.rb | 6 +++++- actionpack/test/new_base/test_helper.rb | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 528180ae32..d88e5cea82 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -1,9 +1,13 @@ $:.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') $:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers') -require File.join(File.dirname(__FILE__), "..", "vendor", "gems", "environment") +bundler = File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment') +require bundler if File.exist?("#{bundler}.rb") ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb index 5a901ab9d8..33ea519e77 100644 --- a/actionpack/test/new_base/test_helper.rb +++ b/actionpack/test/new_base/test_helper.rb @@ -1,7 +1,9 @@ $:.unshift(File.dirname(__FILE__) + '/../../lib') +$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib') $:.unshift(File.dirname(__FILE__) + '/../lib') -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "vendor", "gems", "environment")) +bundler = File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'gems', 'environment') +require bundler if File.exist?("#{bundler}.rb") require 'test/unit' require 'active_support' -- cgit v1.2.3 From 25f4129151070f8c237ea3092a5da59253a1a2fc Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 13 Sep 2009 12:58:49 -0500 Subject: Need to declare optional dependencies from AS --- actionpack/test/abstract_controller/test_helper.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_controller/test_helper.rb b/actionpack/test/abstract_controller/test_helper.rb index ba4302d914..18e4d3c0e5 100644 --- a/actionpack/test/abstract_controller/test_helper.rb +++ b/actionpack/test/abstract_controller/test_helper.rb @@ -2,6 +2,9 @@ $:.unshift(File.dirname(__FILE__) + '/../../lib') $:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib') $:.unshift(File.dirname(__FILE__) + '/../lib') +bundler = File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'gems', 'environment') +require bundler if File.exist?("#{bundler}.rb") + require 'rubygems' require 'test/unit' require 'active_support' -- cgit v1.2.3 From 48c81f52d41879827ca4a84deaaf4459d290c85b Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 13 Sep 2009 15:34:17 -0500 Subject: Remove dead old base abstract unit --- actionpack/test/old_base/abstract_unit.rb | 46 ------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 actionpack/test/old_base/abstract_unit.rb (limited to 'actionpack/test') diff --git a/actionpack/test/old_base/abstract_unit.rb b/actionpack/test/old_base/abstract_unit.rb deleted file mode 100644 index b80050bd48..0000000000 --- a/actionpack/test/old_base/abstract_unit.rb +++ /dev/null @@ -1,46 +0,0 @@ -if ENV['new_base'] - puts *caller - raise 'new_base/abstract_unit already loaded' -end -$:.unshift(File.dirname(__FILE__) + '/../lib') -$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib') -$:.unshift(File.dirname(__FILE__) + '/fixtures/helpers') -$:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers') - -require 'rubygems' -gem "rack", "~> 1.0.0" -gem "rack-test", "~> 0.4.2" - -require 'yaml' -require 'stringio' -require 'test/unit' - -begin - require 'ruby-debug' - Debugger.settings[:autoeval] = true - Debugger.start -rescue LoadError - # Debugging disabled. `gem install ruby-debug` to enable. -end - -require 'action_controller' -require 'action_controller/testing/process' -require 'action_view/test_case' - -$tags[:old_base] = true - -# Show backtraces for deprecated behavior for quicker cleanup. -ActiveSupport::Deprecation.debug = true - -ActionController::Base.logger = nil -ActionController::Routing::Routes.reload rescue nil - -ActionController::Base.session_store = nil - -# Register danish language for testing -I18n.backend.store_translations 'da', {} -I18n.backend.store_translations 'pt-BR', {} -ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort - -FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') -ActionController::Base.view_paths = FIXTURE_LOAD_PATH -- cgit v1.2.3 From 6d214c953b74c40d6247dfd2d4526991a0f99f5c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 13 Sep 2009 16:30:27 -0500 Subject: Merge abstract_controller/test_helper and new_base/test_helper since they are expected to run in the same testing sandbox --- .../abstract_controller_test.rb | 2 +- .../test/abstract_controller/callbacks_test.rb | 4 +- actionpack/test/abstract_controller/helper_test.rb | 2 +- .../test/abstract_controller/layouts_test.rb | 2 +- actionpack/test/abstract_controller/test_helper.rb | 24 ----- actionpack/test/abstract_unit2.rb | 119 +++++++++++++++++++++ actionpack/test/active_record_unit.rb | 104 ++++++++++++++++++ actionpack/test/lib/active_record_unit.rb | 104 ------------------ actionpack/test/new_base/base_test.rb | 4 +- .../test/new_base/content_negotiation_test.rb | 4 +- actionpack/test/new_base/content_type_test.rb | 2 +- actionpack/test/new_base/etag_test.rb | 4 +- actionpack/test/new_base/metal_test.rb | 3 +- actionpack/test/new_base/middleware_test.rb | 2 +- actionpack/test/new_base/redirect_test.rb | 1 - actionpack/test/new_base/render_action_test.rb | 4 +- actionpack/test/new_base/render_file_test.rb | 4 +- .../test/new_base/render_implicit_action_test.rb | 4 +- actionpack/test/new_base/render_layout_test.rb | 4 +- actionpack/test/new_base/render_partial_test.rb | 4 +- actionpack/test/new_base/render_rjs_test.rb | 4 +- actionpack/test/new_base/render_template_test.rb | 4 +- actionpack/test/new_base/render_test.rb | 4 +- actionpack/test/new_base/render_text_test.rb | 4 +- actionpack/test/new_base/render_xml_test.rb | 4 +- actionpack/test/new_base/test_helper.rb | 113 ------------------- actionpack/test/runner | 8 -- 27 files changed, 257 insertions(+), 285 deletions(-) delete mode 100644 actionpack/test/abstract_controller/test_helper.rb create mode 100644 actionpack/test/abstract_unit2.rb create mode 100644 actionpack/test/active_record_unit.rb delete mode 100644 actionpack/test/lib/active_record_unit.rb delete mode 100644 actionpack/test/new_base/redirect_test.rb delete mode 100644 actionpack/test/new_base/test_helper.rb delete mode 100755 actionpack/test/runner (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb index 3b4046a424..0e6cfba5b5 100644 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ b/actionpack/test/abstract_controller/abstract_controller_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module AbstractController module Testing diff --git a/actionpack/test/abstract_controller/callbacks_test.rb b/actionpack/test/abstract_controller/callbacks_test.rb index 8f62adce8c..98656c0c70 100644 --- a/actionpack/test/abstract_controller/callbacks_test.rb +++ b/actionpack/test/abstract_controller/callbacks_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module AbstractController module Testing @@ -235,4 +235,4 @@ module AbstractController end end -end \ No newline at end of file +end diff --git a/actionpack/test/abstract_controller/helper_test.rb b/actionpack/test/abstract_controller/helper_test.rb index 34a10cecc9..4c013137f9 100644 --- a/actionpack/test/abstract_controller/helper_test.rb +++ b/actionpack/test/abstract_controller/helper_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module AbstractController module Testing diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract_controller/layouts_test.rb index 995aac7fad..bee3b5c556 100644 --- a/actionpack/test/abstract_controller/layouts_test.rb +++ b/actionpack/test/abstract_controller/layouts_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' require 'active_support/core_ext/class/removal' module AbstractControllerTests diff --git a/actionpack/test/abstract_controller/test_helper.rb b/actionpack/test/abstract_controller/test_helper.rb deleted file mode 100644 index 18e4d3c0e5..0000000000 --- a/actionpack/test/abstract_controller/test_helper.rb +++ /dev/null @@ -1,24 +0,0 @@ -$:.unshift(File.dirname(__FILE__) + '/../../lib') -$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib') -$:.unshift(File.dirname(__FILE__) + '/../lib') - -bundler = File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'gems', 'environment') -require bundler if File.exist?("#{bundler}.rb") - -require 'rubygems' -require 'test/unit' -require 'active_support' -require 'active_support/test_case' -require 'abstract_controller' -require 'action_view' -require 'action_view/base' -require 'action_dispatch' -require 'fixture_template' - -begin - require 'ruby-debug' - Debugger.settings[:autoeval] = true - Debugger.start -rescue LoadError - # Debugging disabled. `gem install ruby-debug` to enable. -end diff --git a/actionpack/test/abstract_unit2.rb b/actionpack/test/abstract_unit2.rb new file mode 100644 index 0000000000..5bda38243c --- /dev/null +++ b/actionpack/test/abstract_unit2.rb @@ -0,0 +1,119 @@ +# TODO: Unify with abstract_unit + +$:.unshift(File.dirname(__FILE__) + '/../lib') +$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib') +$:.unshift(File.dirname(__FILE__) + '/../lib') +$:.unshift(File.dirname(__FILE__) + '/lib') + +bundler = File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'gems', 'environment') +require bundler if File.exist?("#{bundler}.rb") + +require 'test/unit' +require 'active_support' +require 'active_support/test_case' +require 'abstract_controller' +require 'action_view' +require 'action_view/base' +require 'action_dispatch' +require 'fixture_template' + +begin + require 'ruby-debug' + Debugger.settings[:autoeval] = true + Debugger.start +rescue LoadError + # Debugging disabled. `gem install ruby-debug` to enable. +end + +require 'action_controller' +require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late + +require 'action_controller/testing/process' +require 'action_controller/testing/integration' + +module Rails + def self.env + x = Object.new + def x.test?() true end + x + end +end + +# Temporary base class +class Rack::TestCase < ActionController::IntegrationTest + setup do + ActionController::Base.session_options[:key] = "abc" + ActionController::Base.session_options[:secret] = ("*" * 30) + end + + def app + @app ||= ActionController::Dispatcher.new + end + + def self.testing(klass = nil) + if klass + @testing = "/#{klass.name.underscore}".sub!(/_controller$/, '') + else + @testing + end + end + + def get(thing, *args) + if thing.is_a?(Symbol) + super("#{self.class.testing}/#{thing}", *args) + else + super + end + end + + def assert_body(body) + assert_equal body, Array.wrap(response.body).join + end + + def assert_status(code) + assert_equal code, response.status + end + + def assert_response(body, status = 200, headers = {}) + assert_body body + assert_status status + headers.each do |header, value| + assert_header header, value + end + end + + def assert_content_type(type) + assert_equal type, response.headers["Content-Type"] + end + + def assert_header(name, value) + assert_equal value, response.headers[name] + end +end + +class ::ApplicationController < ActionController::Base +end + +module ActionController + class << Routing + def possible_controllers + @@possible_controllers ||= [] + end + end + + class Base + def self.inherited(klass) + name = klass.name.underscore.sub(/_controller$/, '') + ActionController::Routing.possible_controllers << name unless name.blank? + super + end + end +end + +class SimpleRouteCase < Rack::TestCase + setup do + ActionController::Routing::Routes.draw do |map| + map.connect ':controller/:action/:id' + end + end +end diff --git a/actionpack/test/active_record_unit.rb b/actionpack/test/active_record_unit.rb new file mode 100644 index 0000000000..9e0c66055d --- /dev/null +++ b/actionpack/test/active_record_unit.rb @@ -0,0 +1,104 @@ +require 'abstract_unit' + +# Define the essentials +class ActiveRecordTestConnector + cattr_accessor :able_to_connect + cattr_accessor :connected + + # Set our defaults + self.connected = false + self.able_to_connect = true +end + +# Try to grab AR +if defined?(ActiveRecord) && defined?(Fixtures) + $stderr.puts 'Active Record is already loaded, running tests' +else + $stderr.print 'Attempting to load Active Record... ' + begin + PATH_TO_AR = "#{File.dirname(__FILE__)}/../../activerecord/lib" + raise LoadError, "#{PATH_TO_AR} doesn't exist" unless File.directory?(PATH_TO_AR) + $LOAD_PATH.unshift PATH_TO_AR + require 'active_record' + require 'active_record/fixtures' + $stderr.puts 'success' + rescue LoadError => e + $stderr.print "failed. Skipping Active Record assertion tests: #{e}" + ActiveRecordTestConnector.able_to_connect = false + end +end +$stderr.flush + + +# Define the rest of the connector +class ActiveRecordTestConnector + class << self + def setup + unless self.connected || !self.able_to_connect + setup_connection + load_schema + require_fixture_models + self.connected = true + end + rescue Exception => e # errors from ActiveRecord setup + $stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}" + #$stderr.puts " #{e.backtrace.join("\n ")}\n" + self.able_to_connect = false + end + + private + def setup_connection + if Object.const_defined?(:ActiveRecord) + defaults = { :database => ':memory:' } + begin + adapter = defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' + options = defaults.merge :adapter => adapter, :timeout => 500 + ActiveRecord::Base.establish_connection(options) + ActiveRecord::Base.configurations = { 'sqlite3_ar_integration' => options } + ActiveRecord::Base.connection + rescue Exception # errors from establishing a connection + $stderr.puts 'SQLite 3 unavailable; trying SQLite 2.' + options = defaults.merge :adapter => 'sqlite' + ActiveRecord::Base.establish_connection(options) + ActiveRecord::Base.configurations = { 'sqlite2_ar_integration' => options } + ActiveRecord::Base.connection + end + + Object.send(:const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')) unless Object.const_defined?(:QUOTED_TYPE) + else + raise "Can't setup connection since ActiveRecord isn't loaded." + end + end + + # Load actionpack sqlite tables + def load_schema + File.read(File.dirname(__FILE__) + "/fixtures/db_definitions/sqlite.sql").split(';').each do |sql| + ActiveRecord::Base.connection.execute(sql) unless sql.blank? + end + end + + def require_fixture_models + Dir.glob(File.dirname(__FILE__) + "/fixtures/*.rb").each {|f| require f} + end + end +end + +class ActiveRecordTestCase < ActionController::TestCase + include ActiveRecord::TestFixtures + + # Set our fixture path + if ActiveRecordTestConnector.able_to_connect + self.fixture_path = [FIXTURE_LOAD_PATH] + self.use_transactional_fixtures = false + end + + def self.fixtures(*args) + super if ActiveRecordTestConnector.connected + end + + def run(*args) + super if ActiveRecordTestConnector.connected + end +end + +ActiveRecordTestConnector.setup diff --git a/actionpack/test/lib/active_record_unit.rb b/actionpack/test/lib/active_record_unit.rb deleted file mode 100644 index 1ba308e9d7..0000000000 --- a/actionpack/test/lib/active_record_unit.rb +++ /dev/null @@ -1,104 +0,0 @@ -require 'abstract_unit' - -# Define the essentials -class ActiveRecordTestConnector - cattr_accessor :able_to_connect - cattr_accessor :connected - - # Set our defaults - self.connected = false - self.able_to_connect = true -end - -# Try to grab AR -if defined?(ActiveRecord) && defined?(Fixtures) - $stderr.puts 'Active Record is already loaded, running tests' -else - $stderr.print 'Attempting to load Active Record... ' - begin - PATH_TO_AR = "#{File.dirname(__FILE__)}/../../../activerecord/lib" - raise LoadError, "#{PATH_TO_AR} doesn't exist" unless File.directory?(PATH_TO_AR) - $LOAD_PATH.unshift PATH_TO_AR - require 'active_record' - require 'active_record/fixtures' - $stderr.puts 'success' - rescue LoadError => e - $stderr.print "failed. Skipping Active Record assertion tests: #{e}" - ActiveRecordTestConnector.able_to_connect = false - end -end -$stderr.flush - - -# Define the rest of the connector -class ActiveRecordTestConnector - class << self - def setup - unless self.connected || !self.able_to_connect - setup_connection - load_schema - require_fixture_models - self.connected = true - end - rescue Exception => e # errors from ActiveRecord setup - $stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}" - #$stderr.puts " #{e.backtrace.join("\n ")}\n" - self.able_to_connect = false - end - - private - def setup_connection - if Object.const_defined?(:ActiveRecord) - defaults = { :database => ':memory:' } - begin - adapter = defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' - options = defaults.merge :adapter => adapter, :timeout => 500 - ActiveRecord::Base.establish_connection(options) - ActiveRecord::Base.configurations = { 'sqlite3_ar_integration' => options } - ActiveRecord::Base.connection - rescue Exception # errors from establishing a connection - $stderr.puts 'SQLite 3 unavailable; trying SQLite 2.' - options = defaults.merge :adapter => 'sqlite' - ActiveRecord::Base.establish_connection(options) - ActiveRecord::Base.configurations = { 'sqlite2_ar_integration' => options } - ActiveRecord::Base.connection - end - - Object.send(:const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')) unless Object.const_defined?(:QUOTED_TYPE) - else - raise "Can't setup connection since ActiveRecord isn't loaded." - end - end - - # Load actionpack sqlite tables - def load_schema - File.read(File.dirname(__FILE__) + "/../fixtures/db_definitions/sqlite.sql").split(';').each do |sql| - ActiveRecord::Base.connection.execute(sql) unless sql.blank? - end - end - - def require_fixture_models - Dir.glob(File.dirname(__FILE__) + "/../fixtures/*.rb").each {|f| require f} - end - end -end - -class ActiveRecordTestCase < ActionController::TestCase - include ActiveRecord::TestFixtures - - # Set our fixture path - if ActiveRecordTestConnector.able_to_connect - self.fixture_path = [FIXTURE_LOAD_PATH] - self.use_transactional_fixtures = false - end - - def self.fixtures(*args) - super if ActiveRecordTestConnector.connected - end - - def run(*args) - super if ActiveRecordTestConnector.connected - end -end - -ActiveRecordTestConnector.setup diff --git a/actionpack/test/new_base/base_test.rb b/actionpack/test/new_base/base_test.rb index 1b2e917ced..3a559c9cb6 100644 --- a/actionpack/test/new_base/base_test.rb +++ b/actionpack/test/new_base/base_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' # Tests the controller dispatching happy path module Dispatching @@ -65,4 +65,4 @@ module Dispatching assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name end end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/content_negotiation_test.rb b/actionpack/test/new_base/content_negotiation_test.rb index d2f732738d..a2f9df597f 100644 --- a/actionpack/test/new_base/content_negotiation_test.rb +++ b/actionpack/test/new_base/content_negotiation_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module ContentNegotiation @@ -15,4 +15,4 @@ module ContentNegotiation assert_body "Hello world */*!" end end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/content_type_test.rb b/actionpack/test/new_base/content_type_test.rb index ceee508224..7e95c715a0 100644 --- a/actionpack/test/new_base/content_type_test.rb +++ b/actionpack/test/new_base/content_type_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module ContentType class BaseController < ActionController::Base diff --git a/actionpack/test/new_base/etag_test.rb b/actionpack/test/new_base/etag_test.rb index 3a69e7dac4..64ae10b7a7 100644 --- a/actionpack/test/new_base/etag_test.rb +++ b/actionpack/test/new_base/etag_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module Etags class BasicController < ActionController::Base @@ -43,4 +43,4 @@ module Etags %("#{Digest::MD5.hexdigest(text)}") end end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/metal_test.rb b/actionpack/test/new_base/metal_test.rb index 2b7720863a..613d03446c 100644 --- a/actionpack/test/new_base/metal_test.rb +++ b/actionpack/test/new_base/metal_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module MetalTest class MetalMiddleware < ActionController::Middleware @@ -41,4 +41,3 @@ module MetalTest end end end - diff --git a/actionpack/test/new_base/middleware_test.rb b/actionpack/test/new_base/middleware_test.rb index 15aef270e2..ecca7e51eb 100644 --- a/actionpack/test/new_base/middleware_test.rb +++ b/actionpack/test/new_base/middleware_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module MiddlewareTest class MyMiddleware diff --git a/actionpack/test/new_base/redirect_test.rb b/actionpack/test/new_base/redirect_test.rb deleted file mode 100644 index e591ebd05f..0000000000 --- a/actionpack/test/new_base/redirect_test.rb +++ /dev/null @@ -1 +0,0 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") \ No newline at end of file diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb index dfa7cc2141..72a16e3b67 100644 --- a/actionpack/test/new_base/render_action_test.rb +++ b/actionpack/test/new_base/render_action_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module RenderAction # This has no layout and it works @@ -317,4 +317,4 @@ module RenderActionWithBothLayouts assert_status 200 end end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/render_file_test.rb b/actionpack/test/new_base/render_file_test.rb index 8d7f49dbc2..7067baca18 100644 --- a/actionpack/test/new_base/render_file_test.rb +++ b/actionpack/test/new_base/render_file_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module RenderFile @@ -107,4 +107,4 @@ module RenderFile end end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/render_implicit_action_test.rb b/actionpack/test/new_base/render_implicit_action_test.rb index fd96e1955f..03b9ff6eeb 100644 --- a/actionpack/test/new_base/render_implicit_action_test.rb +++ b/actionpack/test/new_base/render_implicit_action_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module RenderImplicitAction class SimpleController < ::ApplicationController @@ -25,4 +25,4 @@ module RenderImplicitAction assert_status 200 end end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/render_layout_test.rb b/actionpack/test/new_base/render_layout_test.rb index 933eef58e7..0dfbae4e9d 100644 --- a/actionpack/test/new_base/render_layout_test.rb +++ b/actionpack/test/new_base/render_layout_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module ControllerLayouts class ImplicitController < ::ApplicationController @@ -98,4 +98,4 @@ module ControllerLayouts end end end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/render_partial_test.rb b/actionpack/test/new_base/render_partial_test.rb index bbb98a0c01..ff775dbfd7 100644 --- a/actionpack/test/new_base/render_partial_test.rb +++ b/actionpack/test/new_base/render_partial_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module RenderPartial @@ -24,4 +24,4 @@ module RenderPartial end end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/render_rjs_test.rb b/actionpack/test/new_base/render_rjs_test.rb index 3d3e516905..eecc275b1e 100644 --- a/actionpack/test/new_base/render_rjs_test.rb +++ b/actionpack/test/new_base/render_rjs_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module RenderRjs @@ -42,4 +42,4 @@ module RenderRjs end end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/render_template_test.rb b/actionpack/test/new_base/render_template_test.rb index 967cbd07b0..5637565dac 100644 --- a/actionpack/test/new_base/render_template_test.rb +++ b/actionpack/test/new_base/render_template_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module RenderTemplate class WithoutLayoutController < ActionController::Base @@ -167,4 +167,4 @@ module RenderTemplate end end end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb index 5783b4766a..94820f1c9c 100644 --- a/actionpack/test/new_base/render_test.rb +++ b/actionpack/test/new_base/render_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module Render class BlankRenderController < ActionController::Base @@ -82,4 +82,4 @@ module Render assert_body "Controller Name: blank_render" end end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/render_text_test.rb b/actionpack/test/new_base/render_text_test.rb index 84f77432c9..23660ed101 100644 --- a/actionpack/test/new_base/render_text_test.rb +++ b/actionpack/test/new_base/render_text_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module RenderText class SimpleController < ActionController::Base @@ -134,4 +134,4 @@ module RenderText assert_status 200 end end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/render_xml_test.rb b/actionpack/test/new_base/render_xml_test.rb index a3890ddfb2..86a7d9c8a5 100644 --- a/actionpack/test/new_base/render_xml_test.rb +++ b/actionpack/test/new_base/render_xml_test.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") +require 'abstract_unit2' module RenderXml @@ -8,4 +8,4 @@ module RenderXml "render_xml/basic/with_render_erb" => "Hello world!" )] end -end \ No newline at end of file +end diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb deleted file mode 100644 index 33ea519e77..0000000000 --- a/actionpack/test/new_base/test_helper.rb +++ /dev/null @@ -1,113 +0,0 @@ -$:.unshift(File.dirname(__FILE__) + '/../../lib') -$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib') -$:.unshift(File.dirname(__FILE__) + '/../lib') - -bundler = File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'gems', 'environment') -require bundler if File.exist?("#{bundler}.rb") - -require 'test/unit' -require 'active_support' -require 'active_support/test_case' -require 'action_view' -require 'fixture_template' - -begin - require 'ruby-debug' - Debugger.settings[:autoeval] = true - Debugger.start -rescue LoadError - # Debugging disabled. `gem install ruby-debug` to enable. -end - -require 'action_controller' -require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late - -require 'action_controller/testing/process' -require 'action_controller/testing/integration' - -module Rails - def self.env - x = Object.new - def x.test?() true end - x - end -end - -# Temporary base class -class Rack::TestCase < ActionController::IntegrationTest - setup do - ActionController::Base.session_options[:key] = "abc" - ActionController::Base.session_options[:secret] = ("*" * 30) - end - - def app - @app ||= ActionController::Dispatcher.new - end - - def self.testing(klass = nil) - if klass - @testing = "/#{klass.name.underscore}".sub!(/_controller$/, '') - else - @testing - end - end - - def get(thing, *args) - if thing.is_a?(Symbol) - super("#{self.class.testing}/#{thing}", *args) - else - super - end - end - - def assert_body(body) - assert_equal body, Array.wrap(response.body).join - end - - def assert_status(code) - assert_equal code, response.status - end - - def assert_response(body, status = 200, headers = {}) - assert_body body - assert_status status - headers.each do |header, value| - assert_header header, value - end - end - - def assert_content_type(type) - assert_equal type, response.headers["Content-Type"] - end - - def assert_header(name, value) - assert_equal value, response.headers[name] - end -end - -class ::ApplicationController < ActionController::Base -end - -module ActionController - class << Routing - def possible_controllers - @@possible_controllers ||= [] - end - end - - class Base - def self.inherited(klass) - name = klass.name.underscore.sub(/_controller$/, '') - ActionController::Routing.possible_controllers << name unless name.blank? - super - end - end -end - -class SimpleRouteCase < Rack::TestCase - setup do - ActionController::Routing::Routes.draw do |map| - map.connect ':controller/:action/:id' - end - end -end diff --git a/actionpack/test/runner b/actionpack/test/runner deleted file mode 100755 index c2bbe63c75..0000000000 --- a/actionpack/test/runner +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env ruby - - -ARGV.each do |arg| - Dir["#{Dir.pwd}/#{arg}/**/*_test.rb"].each do |file| - require file - end -end \ No newline at end of file -- cgit v1.2.3 From 076d7f885ed808a061c1d161f00fc81465b3b4da Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 13 Sep 2009 16:37:30 -0500 Subject: AP tests: detect missing dependencies and automatically run bundler --- actionpack/test/abstract_unit.rb | 4 ++-- actionpack/test/abstract_unit2.rb | 4 ++-- actionpack/test/bundler_helper.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 actionpack/test/bundler_helper.rb (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index d88e5cea82..f1914217f4 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -6,8 +6,8 @@ $:.unshift(File.dirname(__FILE__) + '/lib') $:.unshift(File.dirname(__FILE__) + '/fixtures/helpers') $:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers') -bundler = File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment') -require bundler if File.exist?("#{bundler}.rb") +require 'bundler_helper' +ensure_requirable %w( rack rack/test sqlite3 builder memcache tzinfo ) ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') diff --git a/actionpack/test/abstract_unit2.rb b/actionpack/test/abstract_unit2.rb index 5bda38243c..0a98d8edc2 100644 --- a/actionpack/test/abstract_unit2.rb +++ b/actionpack/test/abstract_unit2.rb @@ -5,8 +5,8 @@ $:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib') $:.unshift(File.dirname(__FILE__) + '/../lib') $:.unshift(File.dirname(__FILE__) + '/lib') -bundler = File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'gems', 'environment') -require bundler if File.exist?("#{bundler}.rb") +require 'bundler_helper' +ensure_requirable %w( rack rack/test ) require 'test/unit' require 'active_support' diff --git a/actionpack/test/bundler_helper.rb b/actionpack/test/bundler_helper.rb new file mode 100644 index 0000000000..5f3e982f19 --- /dev/null +++ b/actionpack/test/bundler_helper.rb @@ -0,0 +1,30 @@ +BUNDLER_ENV_FILE = File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment') + +def load_bundled_gems + load_bundled_gems! if File.exist?("#{BUNDLER_ENV_FILE}.rb") +end + +def load_bundled_gems! + puts "Checking if the bundled testing requirements are up to date..." + + result = system "gem bundle" + unless result + puts "The gem bundler is not installed. Installing." + system "gem install bundler" + system "gem bundle" + end + + require BUNDLER_ENV_FILE +end + +def ensure_requirable(libs) + load_bundled_gems + + begin + libs.each { |lib| require lib } + rescue LoadError => e + puts "Missing required libs to run test" + puts e.message + load_bundled_gems! + end +end -- cgit v1.2.3 From 213c920e4f0b1efeaccc4377dfebb41a5873efcf Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 13 Sep 2009 17:28:44 -0500 Subject: Define weblog controller for url helper test --- actionpack/test/lib/controller/fake_controllers.rb | 1 + actionpack/test/template/url_helper_test.rb | 1 + 2 files changed, 2 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/lib/controller/fake_controllers.rb b/actionpack/test/lib/controller/fake_controllers.rb index 22729188a2..5dcca2e148 100644 --- a/actionpack/test/lib/controller/fake_controllers.rb +++ b/actionpack/test/lib/controller/fake_controllers.rb @@ -17,6 +17,7 @@ class CController < ActionController::Base; end class HiController < ActionController::Base; end class BraveController < ActionController::Base; end class ImageController < ActionController::Base; end +class WeblogController < ActionController::Base; end # For speed test class SpeedController < ActionController::Base; end diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 44f1925653..447d520ef1 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -1,5 +1,6 @@ # encoding: utf-8 require 'abstract_unit' +require 'controller/fake_controllers' RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port, :env) -- cgit v1.2.3 From a3fcfd819b85e89286ffe9dfc3a3f22555cd55fc Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 13 Sep 2009 17:52:33 -0500 Subject: Need to reset session for AP rescue tests after altering the route set --- actionpack/test/controller/rescue_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 490a4ff3b3..23408712e9 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -359,6 +359,7 @@ class RescueTest < ActionController::IntegrationTest map.connect 'invalid', :controller => "rescue_test/test", :action => 'invalid' map.connect 'b00m', :controller => "rescue_test/test", :action => 'b00m' end + reset! yield end end -- cgit v1.2.3 From a0e43073e22bab9c4aaafa419f00c2032f8d28fd Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 13 Sep 2009 18:43:16 -0500 Subject: Rewrite resource routing tests that are coupled to the router implementation --- actionpack/test/controller/resources_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 0b639e363d..5b47de19ae 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -135,7 +135,7 @@ class ResourcesTest < ActionController::TestCase def test_with_custom_conditions with_restful_routing :messages, :conditions => { :subdomain => 'app' } do - assert_equal 'app', ActionController::Routing::Routes.named_routes.routes[:messages].conditions[:subdomain] + assert ActionController::Routing::Routes.recognize_path("/messages", :method => :get, :subdomain => 'app') end end @@ -1130,7 +1130,8 @@ class ResourcesTest < ActionController::TestCase map.resource :product end - assert_equal :get, set.named_routes.routes[:product].conditions[:method] + assert_routing '/product', :controller => 'products', :action => 'show' + assert set.recognize_path("/product", :method => :get) end end -- cgit v1.2.3 From b2f0b8cbda74cc89834b2db749fb0fbe44f5d8f2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 13 Sep 2009 22:55:46 -0500 Subject: Rollback AS bundler work and improve activation of vendored dependencies --- actionpack/test/abstract_unit.rb | 2 +- actionpack/test/template/form_options_helper_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index f1914217f4..7776bd0704 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -7,7 +7,7 @@ $:.unshift(File.dirname(__FILE__) + '/fixtures/helpers') $:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers') require 'bundler_helper' -ensure_requirable %w( rack rack/test sqlite3 builder memcache tzinfo ) +ensure_requirable %w( rack rack/test sqlite3 ) ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index aa40e46aa8..f3cdab05bf 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'tzinfo' +require 'active_support/vendor/tzinfo' TZInfo::Timezone.cattr_reader :loaded_zones -- cgit v1.2.3 From 988a614dd289ea27d41f8ab0d76a3b64124768b1 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 13 Sep 2009 23:33:54 -0500 Subject: Don't run `gem bundle` by default --- actionpack/test/bundler_helper.rb | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/bundler_helper.rb b/actionpack/test/bundler_helper.rb index 5f3e982f19..1e379b9a9b 100644 --- a/actionpack/test/bundler_helper.rb +++ b/actionpack/test/bundler_helper.rb @@ -1,30 +1,11 @@ -BUNDLER_ENV_FILE = File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment') - -def load_bundled_gems - load_bundled_gems! if File.exist?("#{BUNDLER_ENV_FILE}.rb") -end - -def load_bundled_gems! - puts "Checking if the bundled testing requirements are up to date..." - - result = system "gem bundle" - unless result - puts "The gem bundler is not installed. Installing." - system "gem install bundler" - system "gem bundle" - end - - require BUNDLER_ENV_FILE -end - def ensure_requirable(libs) - load_bundled_gems + bundler = File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment') + require bundler if File.exist?("#{bundler}.rb") begin libs.each { |lib| require lib } rescue LoadError => e - puts "Missing required libs to run test" puts e.message - load_bundled_gems! + exit 1 end end -- cgit v1.2.3 From ec36edff2de634122645eeaf9b9f9f85f25a19cc Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 13 Sep 2009 21:52:18 -0700 Subject: Use abort --- actionpack/test/bundler_helper.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/bundler_helper.rb b/actionpack/test/bundler_helper.rb index 1e379b9a9b..f7357bdb41 100644 --- a/actionpack/test/bundler_helper.rb +++ b/actionpack/test/bundler_helper.rb @@ -5,7 +5,6 @@ def ensure_requirable(libs) begin libs.each { |lib| require lib } rescue LoadError => e - puts e.message - exit 1 + abort e.message end end -- cgit v1.2.3 From 90d7ae23c6f5a7e914d8b9fd74481ac61b6c4fb9 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Sep 2009 10:05:46 -0500 Subject: Remove global exception catching from ApplicationController. It was severely broken since it was ported to NewBase and is causing problems with normal exception catching. A replacement is coming soon. --- actionpack/test/controller/rescue_test.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 23408712e9..e8ca1ad0ee 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -331,18 +331,18 @@ class RescueTest < ActionController::IntegrationTest end end - test 'rescue routing exceptions' do - assert_equal 1, ApplicationController.rescue_handlers.length - - begin - with_test_routing do - get '/no_way' - assert_equal 'no way', response.body - end - ensure - ActionController::Base.rescue_handlers.clear - end - end + # test 'rescue routing exceptions' do + # assert_equal 1, ApplicationController.rescue_handlers.length + # + # begin + # with_test_routing do + # get '/no_way' + # assert_equal 'no way', response.body + # end + # ensure + # ActionController::Base.rescue_handlers.clear + # end + # end test 'unrescued exception' do with_test_routing do -- cgit v1.2.3 From 52aeb8d2e72223f9b40b0193c151c252a3f4fb09 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Sep 2009 16:33:15 -0500 Subject: Beef up AD::Rescue to replace global exception handling lost in ApplicationController --- actionpack/test/controller/rescue_test.rb | 35 ++++++++++++------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index e8ca1ad0ee..09eddfe4a7 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -227,12 +227,6 @@ class ControllerInheritanceRescueControllerTest < ActionController::TestCase end end -class ApplicationController < ActionController::Base - rescue_from ActionController::RoutingError do - render :text => 'no way' - end -end - class RescueControllerTest < ActionController::TestCase def test_rescue_handler get :not_authorized @@ -331,24 +325,21 @@ class RescueTest < ActionController::IntegrationTest end end - # test 'rescue routing exceptions' do - # assert_equal 1, ApplicationController.rescue_handlers.length - # - # begin - # with_test_routing do - # get '/no_way' - # assert_equal 'no way', response.body - # end - # ensure - # ActionController::Base.rescue_handlers.clear - # end - # end + test 'rescue routing exceptions' do + app = ActionDispatch::Rescue.new(ActionController::Routing::Routes) do + rescue_from ActionController::RoutingError, lambda { |env| [200, {"Content-Type" => "text/html"}, "Gotcha!"] } + end + @integration_session = open_session(app) + + get '/b00m' + assert_equal "Gotcha!", response.body + end test 'unrescued exception' do - with_test_routing do - get '/b00m' - assert_match(/Action Controller: Exception caught/, response.body) - end + app = ActionDispatch::Rescue.new(ActionController::Routing::Routes) + @integration_session = open_session(app) + + assert_raise(ActionController::RoutingError) { get '/b00m' } end private -- cgit v1.2.3 From 5bc47a93b7c700f246e9469880af82ad4844717b Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 11:56:11 -0500 Subject: Make sure caching test is using a generatable url --- actionpack/test/controller/caching_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 82c790bc19..25e035cb49 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -441,8 +441,8 @@ class ActionCacheTest < ActionController::TestCase def test_correct_content_type_is_returned_for_cache_hit # run it twice to cache it the first time - get :index, :id => 'content-type.xml' - get :index, :id => 'content-type.xml' + get :index, :id => 'content-type', :format => 'xml' + get :index, :id => 'content-type', :format => 'xml' assert_equal 'application/xml', @response.content_type end -- cgit v1.2.3 From a6f19a155a0c9accb31ae12a24ff9145cce271b0 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 11:57:56 -0500 Subject: There is only one base now --- actionpack/test/abstract_unit.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 7776bd0704..78f326e341 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -12,7 +12,6 @@ ensure_requirable %w( rack rack/test sqlite3 ) ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') ENV['new_base'] = "true" -$stderr.puts "Running old tests on new_base" require 'test/unit' require 'active_support' -- cgit v1.2.3 From f05b1e5eb1829be47bf9581ca6666229e01d597c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 12:10:41 -0500 Subject: All on one abstract_unit --- .../abstract_controller_test.rb | 2 +- .../test/abstract_controller/callbacks_test.rb | 2 +- actionpack/test/abstract_controller/helper_test.rb | 2 +- .../test/abstract_controller/layouts_test.rb | 2 +- actionpack/test/abstract_unit.rb | 76 ++++++++++++- actionpack/test/abstract_unit2.rb | 119 --------------------- actionpack/test/new_base/base_test.rb | 2 +- .../test/new_base/content_negotiation_test.rb | 2 +- actionpack/test/new_base/content_type_test.rb | 2 +- actionpack/test/new_base/etag_test.rb | 2 +- actionpack/test/new_base/metal_test.rb | 2 +- actionpack/test/new_base/middleware_test.rb | 2 +- actionpack/test/new_base/render_action_test.rb | 2 +- actionpack/test/new_base/render_file_test.rb | 2 +- .../test/new_base/render_implicit_action_test.rb | 2 +- actionpack/test/new_base/render_layout_test.rb | 2 +- actionpack/test/new_base/render_partial_test.rb | 2 +- actionpack/test/new_base/render_rjs_test.rb | 2 +- actionpack/test/new_base/render_template_test.rb | 2 +- actionpack/test/new_base/render_test.rb | 2 +- actionpack/test/new_base/render_text_test.rb | 2 +- actionpack/test/new_base/render_xml_test.rb | 2 +- 22 files changed, 92 insertions(+), 143 deletions(-) delete mode 100644 actionpack/test/abstract_unit2.rb (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb index 0e6cfba5b5..524381509d 100644 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ b/actionpack/test/abstract_controller/abstract_controller_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module AbstractController module Testing diff --git a/actionpack/test/abstract_controller/callbacks_test.rb b/actionpack/test/abstract_controller/callbacks_test.rb index 98656c0c70..0ce1dc506b 100644 --- a/actionpack/test/abstract_controller/callbacks_test.rb +++ b/actionpack/test/abstract_controller/callbacks_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module AbstractController module Testing diff --git a/actionpack/test/abstract_controller/helper_test.rb b/actionpack/test/abstract_controller/helper_test.rb index 4c013137f9..5a363c9aa5 100644 --- a/actionpack/test/abstract_controller/helper_test.rb +++ b/actionpack/test/abstract_controller/helper_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module AbstractController module Testing diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract_controller/layouts_test.rb index bee3b5c556..453d31826e 100644 --- a/actionpack/test/abstract_controller/layouts_test.rb +++ b/actionpack/test/abstract_controller/layouts_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' require 'active_support/core_ext/class/removal' module AbstractControllerTests diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 78f326e341..1aa4dcb741 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -16,15 +16,17 @@ ENV['new_base'] = "true" require 'test/unit' require 'active_support' require 'active_support/test_case' +require 'abstract_controller' require 'action_controller' +require 'action_view' +require 'action_view/base' +require 'action_dispatch' +require 'active_model' require 'fixture_template' require 'action_controller/testing/process' -require 'action_view/test_case' require 'action_controller/testing/integration' +require 'action_view/test_case' require 'active_support/dependencies' -require 'active_model' - -$tags[:new_base] = true begin require 'ruby-debug' @@ -34,6 +36,8 @@ rescue LoadError # Debugging disabled. `gem install ruby-debug` to enable. end +require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late + ActiveSupport::Dependencies.hook! # Show backtraces for deprecated behavior for quicker cleanup. @@ -56,6 +60,61 @@ module ActionView end end +# Temporary base class +class Rack::TestCase < ActionController::IntegrationTest + setup do + ActionController::Base.session_options[:key] = "abc" + ActionController::Base.session_options[:secret] = ("*" * 30) + end + + def app + @app ||= ActionController::Dispatcher.new + end + + def self.testing(klass = nil) + if klass + @testing = "/#{klass.name.underscore}".sub!(/_controller$/, '') + else + @testing + end + end + + def get(thing, *args) + if thing.is_a?(Symbol) + super("#{self.class.testing}/#{thing}", *args) + else + super + end + end + + def assert_body(body) + assert_equal body, Array.wrap(response.body).join + end + + def assert_status(code) + assert_equal code, response.status + end + + def assert_response(body, status = 200, headers = {}) + assert_body body + assert_status status + headers.each do |header, value| + assert_header header, value + end + end + + def assert_content_type(type) + assert_equal type, response.headers["Content-Type"] + end + + def assert_header(name, value) + assert_equal value, response.headers[name] + end +end + +class ::ApplicationController < ActionController::Base +end + module ActionController Base.session = { :key => '_testing_session', @@ -132,3 +191,12 @@ module ActionController end end end + + +class SimpleRouteCase < Rack::TestCase + setup do + ActionController::Routing::Routes.draw do |map| + map.connect ':controller/:action/:id' + end + end +end diff --git a/actionpack/test/abstract_unit2.rb b/actionpack/test/abstract_unit2.rb deleted file mode 100644 index 0a98d8edc2..0000000000 --- a/actionpack/test/abstract_unit2.rb +++ /dev/null @@ -1,119 +0,0 @@ -# TODO: Unify with abstract_unit - -$:.unshift(File.dirname(__FILE__) + '/../lib') -$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib') -$:.unshift(File.dirname(__FILE__) + '/../lib') -$:.unshift(File.dirname(__FILE__) + '/lib') - -require 'bundler_helper' -ensure_requirable %w( rack rack/test ) - -require 'test/unit' -require 'active_support' -require 'active_support/test_case' -require 'abstract_controller' -require 'action_view' -require 'action_view/base' -require 'action_dispatch' -require 'fixture_template' - -begin - require 'ruby-debug' - Debugger.settings[:autoeval] = true - Debugger.start -rescue LoadError - # Debugging disabled. `gem install ruby-debug` to enable. -end - -require 'action_controller' -require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late - -require 'action_controller/testing/process' -require 'action_controller/testing/integration' - -module Rails - def self.env - x = Object.new - def x.test?() true end - x - end -end - -# Temporary base class -class Rack::TestCase < ActionController::IntegrationTest - setup do - ActionController::Base.session_options[:key] = "abc" - ActionController::Base.session_options[:secret] = ("*" * 30) - end - - def app - @app ||= ActionController::Dispatcher.new - end - - def self.testing(klass = nil) - if klass - @testing = "/#{klass.name.underscore}".sub!(/_controller$/, '') - else - @testing - end - end - - def get(thing, *args) - if thing.is_a?(Symbol) - super("#{self.class.testing}/#{thing}", *args) - else - super - end - end - - def assert_body(body) - assert_equal body, Array.wrap(response.body).join - end - - def assert_status(code) - assert_equal code, response.status - end - - def assert_response(body, status = 200, headers = {}) - assert_body body - assert_status status - headers.each do |header, value| - assert_header header, value - end - end - - def assert_content_type(type) - assert_equal type, response.headers["Content-Type"] - end - - def assert_header(name, value) - assert_equal value, response.headers[name] - end -end - -class ::ApplicationController < ActionController::Base -end - -module ActionController - class << Routing - def possible_controllers - @@possible_controllers ||= [] - end - end - - class Base - def self.inherited(klass) - name = klass.name.underscore.sub(/_controller$/, '') - ActionController::Routing.possible_controllers << name unless name.blank? - super - end - end -end - -class SimpleRouteCase < Rack::TestCase - setup do - ActionController::Routing::Routes.draw do |map| - map.connect ':controller/:action/:id' - end - end -end diff --git a/actionpack/test/new_base/base_test.rb b/actionpack/test/new_base/base_test.rb index 3a559c9cb6..effde324bc 100644 --- a/actionpack/test/new_base/base_test.rb +++ b/actionpack/test/new_base/base_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' # Tests the controller dispatching happy path module Dispatching diff --git a/actionpack/test/new_base/content_negotiation_test.rb b/actionpack/test/new_base/content_negotiation_test.rb index a2f9df597f..c43cb677f8 100644 --- a/actionpack/test/new_base/content_negotiation_test.rb +++ b/actionpack/test/new_base/content_negotiation_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module ContentNegotiation diff --git a/actionpack/test/new_base/content_type_test.rb b/actionpack/test/new_base/content_type_test.rb index 7e95c715a0..898d0bb9f3 100644 --- a/actionpack/test/new_base/content_type_test.rb +++ b/actionpack/test/new_base/content_type_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module ContentType class BaseController < ActionController::Base diff --git a/actionpack/test/new_base/etag_test.rb b/actionpack/test/new_base/etag_test.rb index 64ae10b7a7..d5b7942ab6 100644 --- a/actionpack/test/new_base/etag_test.rb +++ b/actionpack/test/new_base/etag_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module Etags class BasicController < ActionController::Base diff --git a/actionpack/test/new_base/metal_test.rb b/actionpack/test/new_base/metal_test.rb index 613d03446c..e1d46b906e 100644 --- a/actionpack/test/new_base/metal_test.rb +++ b/actionpack/test/new_base/metal_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module MetalTest class MetalMiddleware < ActionController::Middleware diff --git a/actionpack/test/new_base/middleware_test.rb b/actionpack/test/new_base/middleware_test.rb index ecca7e51eb..ada0215b1a 100644 --- a/actionpack/test/new_base/middleware_test.rb +++ b/actionpack/test/new_base/middleware_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module MiddlewareTest class MyMiddleware diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb index 72a16e3b67..d5896c1ebd 100644 --- a/actionpack/test/new_base/render_action_test.rb +++ b/actionpack/test/new_base/render_action_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module RenderAction # This has no layout and it works diff --git a/actionpack/test/new_base/render_file_test.rb b/actionpack/test/new_base/render_file_test.rb index 7067baca18..c4098855e6 100644 --- a/actionpack/test/new_base/render_file_test.rb +++ b/actionpack/test/new_base/render_file_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module RenderFile diff --git a/actionpack/test/new_base/render_implicit_action_test.rb b/actionpack/test/new_base/render_implicit_action_test.rb index 03b9ff6eeb..2b78fa7d4f 100644 --- a/actionpack/test/new_base/render_implicit_action_test.rb +++ b/actionpack/test/new_base/render_implicit_action_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module RenderImplicitAction class SimpleController < ::ApplicationController diff --git a/actionpack/test/new_base/render_layout_test.rb b/actionpack/test/new_base/render_layout_test.rb index 0dfbae4e9d..f840a47ecf 100644 --- a/actionpack/test/new_base/render_layout_test.rb +++ b/actionpack/test/new_base/render_layout_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module ControllerLayouts class ImplicitController < ::ApplicationController diff --git a/actionpack/test/new_base/render_partial_test.rb b/actionpack/test/new_base/render_partial_test.rb index ff775dbfd7..7c2c20e1c7 100644 --- a/actionpack/test/new_base/render_partial_test.rb +++ b/actionpack/test/new_base/render_partial_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module RenderPartial diff --git a/actionpack/test/new_base/render_rjs_test.rb b/actionpack/test/new_base/render_rjs_test.rb index eecc275b1e..9c6416bbe0 100644 --- a/actionpack/test/new_base/render_rjs_test.rb +++ b/actionpack/test/new_base/render_rjs_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module RenderRjs diff --git a/actionpack/test/new_base/render_template_test.rb b/actionpack/test/new_base/render_template_test.rb index 5637565dac..3b24c2d75a 100644 --- a/actionpack/test/new_base/render_template_test.rb +++ b/actionpack/test/new_base/render_template_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module RenderTemplate class WithoutLayoutController < ActionController::Base diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb index 94820f1c9c..804be79d17 100644 --- a/actionpack/test/new_base/render_test.rb +++ b/actionpack/test/new_base/render_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module Render class BlankRenderController < ActionController::Base diff --git a/actionpack/test/new_base/render_text_test.rb b/actionpack/test/new_base/render_text_test.rb index 23660ed101..f5839ee16f 100644 --- a/actionpack/test/new_base/render_text_test.rb +++ b/actionpack/test/new_base/render_text_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module RenderText class SimpleController < ActionController::Base diff --git a/actionpack/test/new_base/render_xml_test.rb b/actionpack/test/new_base/render_xml_test.rb index 86a7d9c8a5..d044738a78 100644 --- a/actionpack/test/new_base/render_xml_test.rb +++ b/actionpack/test/new_base/render_xml_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module RenderXml -- cgit v1.2.3 From 12b3799448119a2cd5732670ad7e3cc9ce5707d0 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 12:50:14 -0500 Subject: Avoid conflicts with another ContentTypeController used in testing --- actionpack/test/controller/content_type_test.rb | 15 +++++++-------- .../render_default_content_types_for_respond_to.xml.erb | 1 - .../fixtures/content_type/render_default_for_rhtml.rhtml | 1 - .../test/fixtures/content_type/render_default_for_rjs.rjs | 1 - .../fixtures/content_type/render_default_for_rxml.rxml | 1 - .../render_default_content_types_for_respond_to.xml.erb | 1 + .../old_content_type/render_default_for_rhtml.rhtml | 1 + .../fixtures/old_content_type/render_default_for_rjs.rjs | 1 + .../old_content_type/render_default_for_rxml.rxml | 1 + 9 files changed, 11 insertions(+), 12 deletions(-) delete mode 100644 actionpack/test/fixtures/content_type/render_default_content_types_for_respond_to.xml.erb delete mode 100644 actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml delete mode 100644 actionpack/test/fixtures/content_type/render_default_for_rjs.rjs delete mode 100644 actionpack/test/fixtures/content_type/render_default_for_rxml.rxml create mode 100644 actionpack/test/fixtures/old_content_type/render_default_content_types_for_respond_to.xml.erb create mode 100644 actionpack/test/fixtures/old_content_type/render_default_for_rhtml.rhtml create mode 100644 actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs create mode 100644 actionpack/test/fixtures/old_content_type/render_default_for_rxml.rxml (limited to 'actionpack/test') diff --git a/actionpack/test/controller/content_type_test.rb b/actionpack/test/controller/content_type_test.rb index c249788c67..e5ffe20ecc 100644 --- a/actionpack/test/controller/content_type_test.rb +++ b/actionpack/test/controller/content_type_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' -class ContentTypeController < ActionController::Base +class OldContentTypeController < ActionController::Base # :ported: def render_content_type_from_body response.content_type = Mime::RSS @@ -56,7 +56,7 @@ class ContentTypeController < ActionController::Base end class ContentTypeTest < ActionController::TestCase - tests ContentTypeController + tests OldContentTypeController def setup super @@ -73,11 +73,11 @@ class ContentTypeTest < ActionController::TestCase end def test_render_changed_charset_default - ContentTypeController.default_charset = "utf-16" + OldContentTypeController.default_charset = "utf-16" get :render_defaults assert_equal "utf-16", @response.charset assert_equal Mime::HTML, @response.content_type - ContentTypeController.default_charset = "utf-8" + OldContentTypeController.default_charset = "utf-8" end # :ported: @@ -109,12 +109,12 @@ class ContentTypeTest < ActionController::TestCase end def test_nil_default_for_rhtml - ContentTypeController.default_charset = nil + OldContentTypeController.default_charset = nil get :render_default_for_rhtml assert_equal Mime::HTML, @response.content_type assert_nil @response.charset, @response.headers.inspect ensure - ContentTypeController.default_charset = "utf-8" + OldContentTypeController.default_charset = "utf-8" end def test_default_for_rhtml @@ -143,8 +143,7 @@ class ContentTypeTest < ActionController::TestCase end class AcceptBasedContentTypeTest < ActionController::TestCase - - tests ContentTypeController + tests OldContentTypeController def setup super diff --git a/actionpack/test/fixtures/content_type/render_default_content_types_for_respond_to.xml.erb b/actionpack/test/fixtures/content_type/render_default_content_types_for_respond_to.xml.erb deleted file mode 100644 index 25dc746886..0000000000 --- a/actionpack/test/fixtures/content_type/render_default_content_types_for_respond_to.xml.erb +++ /dev/null @@ -1 +0,0 @@ -world \ No newline at end of file diff --git a/actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml b/actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml deleted file mode 100644 index c7926d48bb..0000000000 --- a/actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml +++ /dev/null @@ -1 +0,0 @@ -<%= 'hello world!' %> \ No newline at end of file diff --git a/actionpack/test/fixtures/content_type/render_default_for_rjs.rjs b/actionpack/test/fixtures/content_type/render_default_for_rjs.rjs deleted file mode 100644 index 8d614d04ad..0000000000 --- a/actionpack/test/fixtures/content_type/render_default_for_rjs.rjs +++ /dev/null @@ -1 +0,0 @@ -page.alert 'hello world!' \ No newline at end of file diff --git a/actionpack/test/fixtures/content_type/render_default_for_rxml.rxml b/actionpack/test/fixtures/content_type/render_default_for_rxml.rxml deleted file mode 100644 index 598d62e2fc..0000000000 --- a/actionpack/test/fixtures/content_type/render_default_for_rxml.rxml +++ /dev/null @@ -1 +0,0 @@ -xml.p "Hello world!" \ No newline at end of file diff --git a/actionpack/test/fixtures/old_content_type/render_default_content_types_for_respond_to.xml.erb b/actionpack/test/fixtures/old_content_type/render_default_content_types_for_respond_to.xml.erb new file mode 100644 index 0000000000..25dc746886 --- /dev/null +++ b/actionpack/test/fixtures/old_content_type/render_default_content_types_for_respond_to.xml.erb @@ -0,0 +1 @@ +world \ No newline at end of file diff --git a/actionpack/test/fixtures/old_content_type/render_default_for_rhtml.rhtml b/actionpack/test/fixtures/old_content_type/render_default_for_rhtml.rhtml new file mode 100644 index 0000000000..c7926d48bb --- /dev/null +++ b/actionpack/test/fixtures/old_content_type/render_default_for_rhtml.rhtml @@ -0,0 +1 @@ +<%= 'hello world!' %> \ No newline at end of file diff --git a/actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs b/actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs new file mode 100644 index 0000000000..8d614d04ad --- /dev/null +++ b/actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs @@ -0,0 +1 @@ +page.alert 'hello world!' \ No newline at end of file diff --git a/actionpack/test/fixtures/old_content_type/render_default_for_rxml.rxml b/actionpack/test/fixtures/old_content_type/render_default_for_rxml.rxml new file mode 100644 index 0000000000..598d62e2fc --- /dev/null +++ b/actionpack/test/fixtures/old_content_type/render_default_for_rxml.rxml @@ -0,0 +1 @@ +xml.p "Hello world!" \ No newline at end of file -- cgit v1.2.3 From 355e2350ca5ce203acfb7f71914339e289b37570 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 12:51:28 -0500 Subject: All on one base, don't need this --- actionpack/test/abstract_unit.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 1aa4dcb741..3bd08e04f7 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -11,8 +11,6 @@ ensure_requirable %w( rack rack/test sqlite3 ) ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') -ENV['new_base'] = "true" - require 'test/unit' require 'active_support' require 'active_support/test_case' @@ -192,7 +190,6 @@ module ActionController end end - class SimpleRouteCase < Rack::TestCase setup do ActionController::Routing::Routes.draw do |map| -- cgit v1.2.3 From db0af8075d84ceb086ebad2e0b6f839fe588ddc2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 12:52:52 -0500 Subject: Avoid conflict with a "MetalTest" module used in tests --- actionpack/test/controller/integration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 93f5bfa272..9f56bbfd46 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -377,7 +377,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest end end -class MetalTest < ActionController::IntegrationTest +class MetalIntegrationTest < ActionController::IntegrationTest class Poller def self.call(env) if env["PATH_INFO"] =~ /^\/success/ -- cgit v1.2.3 From 0540781539508e09e5db176edfc72031773b0dc7 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 13:04:12 -0500 Subject: Namespace TestControllers inside their test case class --- actionpack/test/controller/render_js_test.rb | 38 ++-- actionpack/test/controller/render_json_test.rb | 58 +++--- actionpack/test/controller/render_other_test.rb | 251 ++++++++++++------------ actionpack/test/controller/render_xml_test.rb | 68 ++++--- 4 files changed, 216 insertions(+), 199 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_js_test.rb b/actionpack/test/controller/render_js_test.rb index bc850de733..491c98a0fd 100644 --- a/actionpack/test/controller/render_js_test.rb +++ b/actionpack/test/controller/render_js_test.rb @@ -2,23 +2,27 @@ require 'abstract_unit' require 'controller/fake_models' require 'pathname' -class TestController < ActionController::Base - protect_from_forgery +class RenderJSTest < ActionController::TestCase + class TestController < ActionController::Base + protect_from_forgery - def render_vanilla_js_hello - render :js => "alert('hello')" - end - - def greeting - # let's just rely on the template + def self.controller_path + 'test' + end + + def render_vanilla_js_hello + render :js => "alert('hello')" + end + + def greeting + # let's just rely on the template + end + + def show_partial + render :partial => 'partial' + end end - - def show_partial - render :partial => 'partial' - end -end -class RenderTest < ActionController::TestCase tests TestController def test_render_vanilla_js @@ -26,14 +30,14 @@ class RenderTest < ActionController::TestCase assert_equal "alert('hello')", @response.body assert_equal "text/javascript", @response.content_type end - + def test_render_with_default_from_accept_header xhr :get, :greeting assert_equal "$(\"body\").visualEffect(\"highlight\");", @response.body end - + def test_should_render_js_partial xhr :get, :show_partial, :format => 'js' assert_equal 'partial js', @response.body end -end \ No newline at end of file +end diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb index 233b2dfd89..3938fc7061 100644 --- a/actionpack/test/controller/render_json_test.rb +++ b/actionpack/test/controller/render_json_test.rb @@ -2,35 +2,39 @@ require 'abstract_unit' require 'controller/fake_models' require 'pathname' -class TestController < ActionController::Base - protect_from_forgery - - def render_json_nil - render :json => nil - end +class RenderJsonTest < ActionController::TestCase + class TestController < ActionController::Base + protect_from_forgery - def render_json_hello_world - render :json => ActiveSupport::JSON.encode(:hello => 'world') - end + def self.controller_path + 'test' + end - def render_json_hello_world_with_callback - render :json => ActiveSupport::JSON.encode(:hello => 'world'), :callback => 'alert' - end + def render_json_nil + render :json => nil + end - def render_json_with_custom_content_type - render :json => ActiveSupport::JSON.encode(:hello => 'world'), :content_type => 'text/javascript' - end + def render_json_hello_world + render :json => ActiveSupport::JSON.encode(:hello => 'world') + end - def render_symbol_json - render :json => ActiveSupport::JSON.encode(:hello => 'world') - end + def render_json_hello_world_with_callback + render :json => ActiveSupport::JSON.encode(:hello => 'world'), :callback => 'alert' + end - def render_json_with_render_to_string - render :json => {:hello => render_to_string(:partial => 'partial')} - end -end + def render_json_with_custom_content_type + render :json => ActiveSupport::JSON.encode(:hello => 'world'), :content_type => 'text/javascript' + end + + def render_symbol_json + render :json => ActiveSupport::JSON.encode(:hello => 'world') + end + + def render_json_with_render_to_string + render :json => {:hello => render_to_string(:partial => 'partial')} + end + end -class RenderTest < ActionController::TestCase tests TestController def setup @@ -40,8 +44,8 @@ class RenderTest < ActionController::TestCase @controller.logger = Logger.new(nil) @request.host = "www.nextangle.com" - end - + end + def test_render_json_nil get :render_json_nil assert_equal 'null', @response.body @@ -76,5 +80,5 @@ class RenderTest < ActionController::TestCase get :render_json_with_render_to_string assert_equal '{"hello":"partial html"}', @response.body assert_equal 'application/json', @response.content_type - end -end \ No newline at end of file + end +end diff --git a/actionpack/test/controller/render_other_test.rb b/actionpack/test/controller/render_other_test.rb index 05645e47fa..51c3c55545 100644 --- a/actionpack/test/controller/render_other_test.rb +++ b/actionpack/test/controller/render_other_test.rb @@ -2,139 +2,144 @@ require 'abstract_unit' require 'controller/fake_models' require 'pathname' -class TestController < ActionController::Base - protect_from_forgery - layout :determine_layout +class RenderOtherTest < ActionController::TestCase + class TestController < ActionController::Base + protect_from_forgery - module RenderTestHelper - def rjs_helper_method_from_module - page.visual_effect :highlight + def self.controller_path + 'test' end - end - helper RenderTestHelper - helper do - def rjs_helper_method(value) - page.visual_effect :highlight, value + layout :determine_layout + + module RenderTestHelper + def rjs_helper_method_from_module + page.visual_effect :highlight + end end - end - def enum_rjs_test - render :update do |page| - page.select('.product').each do |value| - page.rjs_helper_method_from_module - page.rjs_helper_method(value) - page.sortable(value, :url => { :action => "order" }) - page.draggable(value) + helper RenderTestHelper + helper do + def rjs_helper_method(value) + page.visual_effect :highlight, value end end - end - - def render_explicit_html_template - end - - def render_custom_code_rjs - render :update, :status => 404 do |page| - page.replace :foo, :partial => 'partial' + + def enum_rjs_test + render :update do |page| + page.select('.product').each do |value| + page.rjs_helper_method_from_module + page.rjs_helper_method(value) + page.sortable(value, :url => { :action => "order" }) + page.draggable(value) + end + end end - end - - def render_implicit_html_template - end - - def render_js_with_explicit_template - @project_id = 4 - render :template => 'test/delete_with_js' - end - def render_js_with_explicit_action_template - @project_id = 4 - render :action => 'delete_with_js' - end - - def delete_with_js - @project_id = 4 - end - - def update_page - render :update do |page| - page.replace_html 'balance', '$37,000,000.00' - page.visual_effect :highlight, 'balance' + def render_explicit_html_template + end + + def render_custom_code_rjs + render :update, :status => 404 do |page| + page.replace :foo, :partial => 'partial' + end end - end - def update_page_with_instance_variables - @money = '$37,000,000.00' - @div_id = 'balance' - render :update do |page| - page.replace_html @div_id, @money - page.visual_effect :highlight, @div_id + def render_implicit_html_template end - end - def update_page_with_view_method - render :update do |page| - page.replace_html 'person', pluralize(2, 'person') + def render_js_with_explicit_template + @project_id = 4 + render :template => 'test/delete_with_js' end - end - - def partial_as_rjs - render :update do |page| - page.replace :foo, :partial => 'partial' + + def render_js_with_explicit_action_template + @project_id = 4 + render :action => 'delete_with_js' end - end - def respond_to_partial_as_rjs - respond_to do |format| - format.js do - render :update do |page| - page.replace :foo, :partial => 'partial' - end + def delete_with_js + @project_id = 4 + end + + def update_page + render :update do |page| + page.replace_html 'balance', '$37,000,000.00' + page.visual_effect :highlight, 'balance' end end - end - - def render_alternate_default - # For this test, the method "default_render" is overridden: - @alternate_default_render = lambda do + + def update_page_with_instance_variables + @money = '$37,000,000.00' + @div_id = 'balance' + render :update do |page| + page.replace_html @div_id, @money + page.visual_effect :highlight, @div_id + end + end + + def update_page_with_view_method + render :update do |page| + page.replace_html 'person', pluralize(2, 'person') + end + end + + def partial_as_rjs render :update do |page| page.replace :foo, :partial => 'partial' end end - end - -private - def default_render - if @alternate_default_render - @alternate_default_render.call - else - super + + def respond_to_partial_as_rjs + respond_to do |format| + format.js do + render :update do |page| + page.replace :foo, :partial => 'partial' + end + end + end end - end - def determine_layout - case action_name - when "hello_world", "layout_test", "rendering_without_layout", - "rendering_nothing_on_layout", "render_text_hello_world", - "render_text_hello_world_with_layout", - "hello_world_with_layout_false", - "partial_only", "partial_only_with_layout", - "accessing_params_in_template", - "accessing_params_in_template_with_layout", - "render_with_explicit_template", - "render_with_explicit_string_template", - "update_page", "update_page_with_instance_variables" - - "layouts/standard" - when "action_talk_to_layout", "layout_overriding_layout" - "layouts/talk_from_action" - when "render_implicit_html_template_from_xhr_request" - (request.xhr? ? 'layouts/xhr' : 'layouts/standard') - end - end -end + def render_alternate_default + # For this test, the method "default_render" is overridden: + @alternate_default_render = lambda do + render :update do |page| + page.replace :foo, :partial => 'partial' + end + end + end + + private + def default_render + if @alternate_default_render + @alternate_default_render.call + else + super + end + end + + def determine_layout + case action_name + when "hello_world", "layout_test", "rendering_without_layout", + "rendering_nothing_on_layout", "render_text_hello_world", + "render_text_hello_world_with_layout", + "hello_world_with_layout_false", + "partial_only", "partial_only_with_layout", + "accessing_params_in_template", + "accessing_params_in_template_with_layout", + "render_with_explicit_template", + "render_with_explicit_string_template", + "update_page", "update_page_with_instance_variables" + + "layouts/standard" + when "action_talk_to_layout", "layout_overriding_layout" + "layouts/talk_from_action" + when "render_implicit_html_template_from_xhr_request" + (request.xhr? ? 'layouts/xhr' : 'layouts/standard') + end + end + end -class RenderTest < ActionController::TestCase tests TestController def setup @@ -144,8 +149,8 @@ class RenderTest < ActionController::TestCase @controller.logger = Logger.new(nil) @request.host = "www.nextangle.com" - end - + end + def test_enum_rjs_test ActiveSupport::SecureRandom.stubs(:base64).returns("asdf") get :enum_rjs_test @@ -153,13 +158,13 @@ class RenderTest < ActionController::TestCase $$(".product").each(function(value, index) { new Effect.Highlight(element,{}); new Effect.Highlight(value,{}); - Sortable.create(value, {onUpdate:function(){new Ajax.Request('/test/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(value) + '&authenticity_token=' + encodeURIComponent('asdf')})}}); + Sortable.create(value, {onUpdate:function(){new Ajax.Request('/render_other_test/test/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(value) + '&authenticity_token=' + encodeURIComponent('asdf')})}}); new Draggable(value, {}); }); }.gsub(/^ /, '').strip assert_equal body, @response.body end - + def test_explicitly_rendering_an_html_template_with_implicit_html_template_renders_should_be_possible_from_an_rjs_template [:js, "js"].each do |format| assert_nothing_raised do @@ -167,14 +172,14 @@ class RenderTest < ActionController::TestCase assert_equal %(document.write("Hello world\\n");), @response.body end end - end - + end + def test_render_custom_code_rjs get :render_custom_code_rjs assert_response 404 assert_equal %(Element.replace("foo", "partial html");), @response.body end - + def test_render_in_an_rjs_template_should_pick_html_templates_when_available [:js, "js"].each do |format| assert_nothing_raised do @@ -183,7 +188,7 @@ class RenderTest < ActionController::TestCase end end end - + def test_render_rjs_template_explicitly get :render_js_with_explicit_template assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body @@ -193,12 +198,12 @@ class RenderTest < ActionController::TestCase get :render_js_with_explicit_action_template assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body end - + def test_render_rjs_with_default get :delete_with_js assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body end - + def test_update_page get :update_page assert_template nil @@ -219,8 +224,8 @@ class RenderTest < ActionController::TestCase assert_template nil assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"] assert_match /2 people/, @response.body - end - + end + def test_should_render_html_formatted_partial_with_rjs xhr :get, :partial_as_rjs assert_equal %(Element.replace("foo", "partial html");), @response.body @@ -230,9 +235,9 @@ class RenderTest < ActionController::TestCase xhr :get, :respond_to_partial_as_rjs assert_equal %(Element.replace("foo", "partial html");), @response.body end - + def test_should_render_with_alternate_default_render xhr :get, :render_alternate_default assert_equal %(Element.replace("foo", "partial html");), @response.body - end -end \ No newline at end of file + end +end diff --git a/actionpack/test/controller/render_xml_test.rb b/actionpack/test/controller/render_xml_test.rb index e96e8a4d57..68a52c3e8c 100644 --- a/actionpack/test/controller/render_xml_test.rb +++ b/actionpack/test/controller/render_xml_test.rb @@ -2,37 +2,41 @@ require 'abstract_unit' require 'controller/fake_models' require 'pathname' -class TestController < ActionController::Base - protect_from_forgery +class RenderXmlTest < ActionController::TestCase + class TestController < ActionController::Base + protect_from_forgery - def render_with_location - render :xml => "", :location => "http://example.com", :status => 201 - end + def self.controller_path + 'test' + end - def render_with_object_location - customer = Customer.new("Some guy", 1) - render :xml => "", :location => customer, :status => :created - end + def render_with_location + render :xml => "", :location => "http://example.com", :status => 201 + end - def render_with_to_xml - to_xmlable = Class.new do - def to_xml - "" - end - end.new + def render_with_object_location + customer = Customer.new("Some guy", 1) + render :xml => "", :location => customer, :status => :created + end - render :xml => to_xmlable - end - - def formatted_xml_erb + def render_with_to_xml + to_xmlable = Class.new do + def to_xml + "" + end + end.new + + render :xml => to_xmlable + end + + def formatted_xml_erb + end + + def render_xml_with_custom_content_type + render :xml => "", :content_type => "application/atomsvc+xml" + end end - - def render_xml_with_custom_content_type - render :xml => "", :content_type => "application/atomsvc+xml" - end -end -class RenderTest < ActionController::TestCase tests TestController def setup @@ -42,8 +46,8 @@ class RenderTest < ActionController::TestCase @controller.logger = Logger.new(nil) @request.host = "www.nextangle.com" - end - + end + def test_rendering_with_location_should_set_header get :render_with_location assert_equal "http://example.com", @response.headers["Location"] @@ -53,7 +57,7 @@ class RenderTest < ActionController::TestCase get :render_with_to_xml assert_equal "", @response.body end - + def test_rendering_with_object_location_should_set_header_with_url_for with_routing do |set| set.draw do |map| @@ -65,19 +69,19 @@ class RenderTest < ActionController::TestCase assert_equal "http://www.nextangle.com/customers/1", @response.headers["Location"] end end - + def test_should_render_formatted_xml_erb_template get :formatted_xml_erb, :format => :xml assert_equal 'passed formatted xml erb', @response.body end - + def test_should_render_xml_but_keep_custom_content_type get :render_xml_with_custom_content_type assert_equal "application/atomsvc+xml", @response.content_type end - + def test_should_use_implicit_content_type get :implicit_content_type, :format => 'atom' assert_equal Mime::ATOM, @response.content_type - end + end end -- cgit v1.2.3 From 69192bee2da198de1bf59fbc0646e59f68e10751 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 13:12:54 -0500 Subject: Merge bundler helper into abstract_unit --- actionpack/test/abstract_unit.rb | 10 ++++++++-- actionpack/test/bundler_helper.rb | 10 ---------- 2 files changed, 8 insertions(+), 12 deletions(-) delete mode 100644 actionpack/test/bundler_helper.rb (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 3bd08e04f7..b9293ffb9f 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -6,8 +6,14 @@ $:.unshift(File.dirname(__FILE__) + '/lib') $:.unshift(File.dirname(__FILE__) + '/fixtures/helpers') $:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers') -require 'bundler_helper' -ensure_requirable %w( rack rack/test sqlite3 ) +bundler = File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment') +require bundler if File.exist?("#{bundler}.rb") + +begin + %w( rack rack/test sqlite3 ).each { |lib| require lib } +rescue LoadError => e + abort e.message +end ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') diff --git a/actionpack/test/bundler_helper.rb b/actionpack/test/bundler_helper.rb deleted file mode 100644 index f7357bdb41..0000000000 --- a/actionpack/test/bundler_helper.rb +++ /dev/null @@ -1,10 +0,0 @@ -def ensure_requirable(libs) - bundler = File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment') - require bundler if File.exist?("#{bundler}.rb") - - begin - libs.each { |lib| require lib } - rescue LoadError => e - abort e.message - end -end -- cgit v1.2.3 From f1c8f07be8c055fdcfd5b5a08b5781e21f24e428 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 13:14:22 -0500 Subject: Follow short name convention for test folder and just call it "abstract" --- .../test/abstract/abstract_controller_test.rb | 245 +++++++++++++++++++++ actionpack/test/abstract/callbacks_test.rb | 238 ++++++++++++++++++++ actionpack/test/abstract/helper_test.rb | 44 ++++ actionpack/test/abstract/layouts_test.rb | 235 ++++++++++++++++++++ .../testing/me3/formatted.html.erb | 1 + .../abstract_controller/testing/me3/index.erb | 1 + .../abstract_controller/testing/me4/index.erb | 1 + .../abstract_controller/testing/me5/index.erb | 1 + .../test/abstract/views/action_with_ivars.erb | 1 + actionpack/test/abstract/views/helper_test.erb | 1 + actionpack/test/abstract/views/index.erb | 1 + .../layouts/abstract_controller/testing/me4.erb | 1 + .../test/abstract/views/layouts/application.erb | 1 + actionpack/test/abstract/views/naked_render.erb | 1 + .../abstract_controller_test.rb | 245 --------------------- .../test/abstract_controller/callbacks_test.rb | 238 -------------------- actionpack/test/abstract_controller/helper_test.rb | 44 ---- .../test/abstract_controller/layouts_test.rb | 235 -------------------- .../testing/me3/formatted.html.erb | 1 - .../abstract_controller/testing/me3/index.erb | 1 - .../abstract_controller/testing/me4/index.erb | 1 - .../abstract_controller/testing/me5/index.erb | 1 - .../views/action_with_ivars.erb | 1 - .../test/abstract_controller/views/helper_test.erb | 1 - .../test/abstract_controller/views/index.erb | 1 - .../layouts/abstract_controller/testing/me4.erb | 1 - .../views/layouts/application.erb | 1 - .../abstract_controller/views/naked_render.erb | 1 - 28 files changed, 772 insertions(+), 772 deletions(-) create mode 100644 actionpack/test/abstract/abstract_controller_test.rb create mode 100644 actionpack/test/abstract/callbacks_test.rb create mode 100644 actionpack/test/abstract/helper_test.rb create mode 100644 actionpack/test/abstract/layouts_test.rb create mode 100644 actionpack/test/abstract/views/abstract_controller/testing/me3/formatted.html.erb create mode 100644 actionpack/test/abstract/views/abstract_controller/testing/me3/index.erb create mode 100644 actionpack/test/abstract/views/abstract_controller/testing/me4/index.erb create mode 100644 actionpack/test/abstract/views/abstract_controller/testing/me5/index.erb create mode 100644 actionpack/test/abstract/views/action_with_ivars.erb create mode 100644 actionpack/test/abstract/views/helper_test.erb create mode 100644 actionpack/test/abstract/views/index.erb create mode 100644 actionpack/test/abstract/views/layouts/abstract_controller/testing/me4.erb create mode 100644 actionpack/test/abstract/views/layouts/application.erb create mode 100644 actionpack/test/abstract/views/naked_render.erb delete mode 100644 actionpack/test/abstract_controller/abstract_controller_test.rb delete mode 100644 actionpack/test/abstract_controller/callbacks_test.rb delete mode 100644 actionpack/test/abstract_controller/helper_test.rb delete mode 100644 actionpack/test/abstract_controller/layouts_test.rb delete mode 100644 actionpack/test/abstract_controller/views/abstract_controller/testing/me3/formatted.html.erb delete mode 100644 actionpack/test/abstract_controller/views/abstract_controller/testing/me3/index.erb delete mode 100644 actionpack/test/abstract_controller/views/abstract_controller/testing/me4/index.erb delete mode 100644 actionpack/test/abstract_controller/views/abstract_controller/testing/me5/index.erb delete mode 100644 actionpack/test/abstract_controller/views/action_with_ivars.erb delete mode 100644 actionpack/test/abstract_controller/views/helper_test.erb delete mode 100644 actionpack/test/abstract_controller/views/index.erb delete mode 100644 actionpack/test/abstract_controller/views/layouts/abstract_controller/testing/me4.erb delete mode 100644 actionpack/test/abstract_controller/views/layouts/application.erb delete mode 100644 actionpack/test/abstract_controller/views/naked_render.erb (limited to 'actionpack/test') diff --git a/actionpack/test/abstract/abstract_controller_test.rb b/actionpack/test/abstract/abstract_controller_test.rb new file mode 100644 index 0000000000..524381509d --- /dev/null +++ b/actionpack/test/abstract/abstract_controller_test.rb @@ -0,0 +1,245 @@ +require 'abstract_unit' + +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::RenderingController + + def _prefix() end + + def render(options = {}) + if options.is_a?(String) + options = {:_template_name => options} + end + + options[:_prefix] = _prefix + 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 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_name => "naked_render.erb" + end + + def rendering_to_string + self.response_body = render_to_string :_template_name => "naked_render.erb" + 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 "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 _prefix + 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 Layouts + + private + def self.layout(formats) + begin + find_template(name.underscore, {:formats => formats}, :_prefix => "layouts") + rescue ActionView::MissingTemplate + begin + find_template("application", {:formats => formats}, :_prefix => "layouts") + rescue ActionView::MissingTemplate + end + 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 Me5 < WithLayouts + def index + render + end + end + + class TestLayouts < ActiveSupport::TestCase + test "layouts are included" do + controller = Me4.new + result = 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 respond_to_action? returns true" do + assert_dispatch RespondToActionController, "success", :index + end + + test "raises ActionNotFound if method is defined but respond_to_action? returns false" do + assert_raise(ActionNotFound) { RespondToActionController.new.process(:fail) } + end + end + + end +end diff --git a/actionpack/test/abstract/callbacks_test.rb b/actionpack/test/abstract/callbacks_test.rb new file mode 100644 index 0000000000..0ce1dc506b --- /dev/null +++ b/actionpack/test/abstract/callbacks_test.rb @@ -0,0 +1,238 @@ +require 'abstract_unit' + +module AbstractController + module Testing + + class ControllerWithCallbacks < AbstractController::Base + include AbstractController::Callbacks + end + + class Callback1 < ControllerWithCallbacks + set_callback :process_action, :before, :first + + def first + @text = "Hello world" + end + + def index + self.response_body = @text + end + end + + class TestCallbacks1 < ActiveSupport::TestCase + test "basic callbacks work" do + controller = Callback1.new + result = controller.process(:index) + assert_equal "Hello world", controller.response_body + end + end + + class Callback2 < ControllerWithCallbacks + before_filter :first + after_filter :second + around_filter :aroundz + + def first + @text = "Hello world" + end + + def second + @second = "Goodbye" + end + + def aroundz + @aroundz = "FIRST" + yield + @aroundz << "SECOND" + end + + def index + self.response_body = @text + end + end + + class TestCallbacks2 < ActiveSupport::TestCase + def setup + @controller = Callback2.new + end + + test "before_filter works" do + result = @controller.process(:index) + assert_equal "Hello world", @controller.response_body + end + + test "after_filter works" do + @controller.process(:index) + assert_equal "Goodbye", @controller.instance_variable_get("@second") + end + + test "around_filter works" do + @controller.process(:index) + assert_equal "FIRSTSECOND", @controller.instance_variable_get("@aroundz") + end + end + + class Callback3 < ControllerWithCallbacks + before_filter do |c| + c.instance_variable_set("@text", "Hello world") + end + + after_filter do |c| + c.instance_variable_set("@second", "Goodbye") + end + + def index + self.response_body = @text + end + end + + class TestCallbacks3 < ActiveSupport::TestCase + def setup + @controller = Callback3.new + end + + test "before_filter works with procs" do + result = @controller.process(:index) + assert_equal "Hello world", @controller.response_body + end + + test "after_filter works with procs" do + result = @controller.process(:index) + assert_equal "Goodbye", @controller.instance_variable_get("@second") + end + end + + class CallbacksWithConditions < ControllerWithCallbacks + before_filter :list, :only => :index + before_filter :authenticate, :except => :index + + def index + self.response_body = @list.join(", ") + end + + def sekrit_data + self.response_body = (@list + [@authenticated]).join(", ") + end + + private + def list + @list = ["Hello", "World"] + end + + def authenticate + @list = [] + @authenticated = "true" + end + end + + class TestCallbacksWithConditions < ActiveSupport::TestCase + def setup + @controller = CallbacksWithConditions.new + end + + test "when :only is specified, a before filter is triggered on that action" do + @controller.process(:index) + assert_equal "Hello, World", @controller.response_body + end + + test "when :only is specified, a before filter is not triggered on other actions" do + @controller.process(:sekrit_data) + assert_equal "true", @controller.response_body + end + + test "when :except is specified, an after filter is not triggered on that action" do + result = @controller.process(:index) + assert_nil @controller.instance_variable_get("@authenticated") + end + end + + class CallbacksWithArrayConditions < ControllerWithCallbacks + before_filter :list, :only => [:index, :listy] + before_filter :authenticate, :except => [:index, :listy] + + def index + self.response_body = @list.join(", ") + end + + def sekrit_data + self.response_body = (@list + [@authenticated]).join(", ") + end + + private + def list + @list = ["Hello", "World"] + end + + def authenticate + @list = [] + @authenticated = "true" + end + end + + class TestCallbacksWithArrayConditions < ActiveSupport::TestCase + def setup + @controller = CallbacksWithArrayConditions.new + end + + test "when :only is specified with an array, a before filter is triggered on that action" do + result = @controller.process(:index) + assert_equal "Hello, World", @controller.response_body + end + + test "when :only is specified with an array, a before filter is not triggered on other actions" do + result = @controller.process(:sekrit_data) + assert_equal "true", @controller.response_body + end + + test "when :except is specified with an array, an after filter is not triggered on that action" do + result = @controller.process(:index) + assert_nil @controller.instance_variable_get("@authenticated") + end + end + + class ChangedConditions < Callback2 + before_filter :first, :only => :index + + def not_index + self.response_body = @text.to_s + end + end + + class TestCallbacksWithChangedConditions < ActiveSupport::TestCase + def setup + @controller = ChangedConditions.new + end + + test "when a callback is modified in a child with :only, it works for the :only action" do + result = @controller.process(:index) + assert_equal "Hello world", @controller.response_body + end + + test "when a callback is modified in a child with :only, it does not work for other actions" do + result = @controller.process(:not_index) + assert_equal "", @controller.response_body + end + end + + class SetsResponseBody < ControllerWithCallbacks + before_filter :set_body + + def index + self.response_body = "Fail" + end + + def set_body + self.response_body = "Success" + end + end + + class TestHalting < ActiveSupport::TestCase + test "when a callback sets the response body, the action should not be invoked" do + controller = SetsResponseBody.new + controller.process(:index) + assert_equal "Success", controller.response_body + end + end + + end +end diff --git a/actionpack/test/abstract/helper_test.rb b/actionpack/test/abstract/helper_test.rb new file mode 100644 index 0000000000..5a363c9aa5 --- /dev/null +++ b/actionpack/test/abstract/helper_test.rb @@ -0,0 +1,44 @@ +require 'abstract_unit' + +module AbstractController + module Testing + + class ControllerWithHelpers < AbstractController::Base + include AbstractController::RenderingController + include Helpers + + def render(string) + super(:_template_name => string) + end + + append_view_path File.expand_path(File.join(File.dirname(__FILE__), "views")) + end + + module HelperyTest + def included_method + "Included" + end + end + + class MyHelpers1 < ControllerWithHelpers + helper(HelperyTest) do + def helpery_test + "World" + end + end + + def index + render "helper_test.erb" + end + end + + class TestHelpers < ActiveSupport::TestCase + def test_helpers + controller = MyHelpers1.new + controller.process(:index) + assert_equal "Hello World : Included", controller.response_body + end + end + + end +end diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb new file mode 100644 index 0000000000..453d31826e --- /dev/null +++ b/actionpack/test/abstract/layouts_test.rb @@ -0,0 +1,235 @@ +require 'abstract_unit' +require 'active_support/core_ext/class/removal' + +module AbstractControllerTests + module Layouts + + # Base controller for these tests + class Base < AbstractController::Base + include AbstractController::RenderingController + include AbstractController::Layouts + + 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" => + "With Implied <%= yield %>", + "layouts/omg.erb" => "OMGHI2U <%= yield %>", + "layouts/with_false_layout.erb" => "False Layout <%= yield %>" + )] + + def self.controller_path + @controller_path ||= self.name.sub(/Controller$/, '').underscore + end + + def controller_path() self.class.controller_path end + + def render_to_body(options) + options[:_layout] = _default_layout({}) + super + end + end + + class Blank < Base + self.view_paths = [] + + def index + render :_template => ActionView::TextTemplate.new("Hello blank!") + end + end + + class WithString < Base + layout "hello" + + def index + render :_template => ActionView::TextTemplate.new("Hello string!") + end + end + + class WithStringChild < WithString + end + + class WithStringOverriddenChild < WithString + layout "hello_override" + end + + class WithNilChild < WithString + layout nil + end + + class WithStringImpliedChild < WithString + end + + class WithChildOfImplied < WithStringImpliedChild + end + + class WithSymbol < Base + layout :hello + + def index + render :_template => ActionView::TextTemplate.new("Hello symbol!") + end + private + def hello + "omg" + end + end + + class WithSymbolReturningString < Base + layout :no_hello + + def index + render :_template => ActionView::TextTemplate.new("Hello missing symbol!") + end + private + def no_hello + nil + end + end + + class WithSymbolReturningNil < Base + layout :nilz + + def index + render :_template => ActionView::TextTemplate.new("Hello nilz!") + end + + def nilz() end + end + + class WithSymbolReturningObj < Base + layout :objekt + + def index + render :_template => ActionView::TextTemplate.new("Hello nilz!") + end + + def objekt + Object.new + end + end + + class WithSymbolAndNoMethod < Base + layout :omg_no_method + + def index + render :_template => ActionView::TextTemplate.new("Hello boom!") + end + end + + class WithMissingLayout < Base + layout "missing" + + def index + render :_template => ActionView::TextTemplate.new("Hello missing!") + end + end + + class WithFalseLayout < Base + layout false + + def index + render :_template => ActionView::TextTemplate.new("Hello false!") + end + end + + class WithNilLayout < Base + layout nil + + def index + render :_template => ActionView::TextTemplate.new("Hello nil!") + 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 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 symbol, call the requested method and use the layout returned" do + controller = WithSymbol.new + controller.process(:index) + assert_equal "OMGHI2U 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(NoMethodError, /:nilz/) { 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 child controller specifies layout nil, do not use the parent layout" do + controller = WithNilChild.new + controller.process(:index) + assert_equal "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 "raises an exception when specifying layout true" do + assert_raises ArgumentError do + Object.class_eval do + class ::BadOmgFailLolLayout < AbstractControllerTests::Layouts::Base + layout true + end + end + end + 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 new file mode 100644 index 0000000000..785bf69191 --- /dev/null +++ b/actionpack/test/abstract/views/abstract_controller/testing/me3/formatted.html.erb @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..f079ad8204 --- /dev/null +++ b/actionpack/test/abstract/views/abstract_controller/testing/me3/index.erb @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..89dce12bdc --- /dev/null +++ b/actionpack/test/abstract/views/abstract_controller/testing/me4/index.erb @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..84d0b7417e --- /dev/null +++ b/actionpack/test/abstract/views/abstract_controller/testing/me5/index.erb @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..8d8ae22fd7 --- /dev/null +++ b/actionpack/test/abstract/views/action_with_ivars.erb @@ -0,0 +1 @@ +<%= @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 new file mode 100644 index 0000000000..8ae45cc195 --- /dev/null +++ b/actionpack/test/abstract/views/helper_test.erb @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..cc1a8b8c85 --- /dev/null +++ b/actionpack/test/abstract/views/index.erb @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..172dd56569 --- /dev/null +++ b/actionpack/test/abstract/views/layouts/abstract_controller/testing/me4.erb @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..27317140ad --- /dev/null +++ b/actionpack/test/abstract/views/layouts/application.erb @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..1b3d03878b --- /dev/null +++ b/actionpack/test/abstract/views/naked_render.erb @@ -0,0 +1 @@ +Hello from naked_render.erb \ No newline at end of file diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb deleted file mode 100644 index 524381509d..0000000000 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ /dev/null @@ -1,245 +0,0 @@ -require 'abstract_unit' - -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::RenderingController - - def _prefix() end - - def render(options = {}) - if options.is_a?(String) - options = {:_template_name => options} - end - - options[:_prefix] = _prefix - 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 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_name => "naked_render.erb" - end - - def rendering_to_string - self.response_body = render_to_string :_template_name => "naked_render.erb" - 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 "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 _prefix - 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 Layouts - - private - def self.layout(formats) - begin - find_template(name.underscore, {:formats => formats}, :_prefix => "layouts") - rescue ActionView::MissingTemplate - begin - find_template("application", {:formats => formats}, :_prefix => "layouts") - rescue ActionView::MissingTemplate - end - 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 Me5 < WithLayouts - def index - render - end - end - - class TestLayouts < ActiveSupport::TestCase - test "layouts are included" do - controller = Me4.new - result = 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 respond_to_action? returns true" do - assert_dispatch RespondToActionController, "success", :index - end - - test "raises ActionNotFound if method is defined but respond_to_action? returns false" do - assert_raise(ActionNotFound) { RespondToActionController.new.process(:fail) } - end - end - - end -end diff --git a/actionpack/test/abstract_controller/callbacks_test.rb b/actionpack/test/abstract_controller/callbacks_test.rb deleted file mode 100644 index 0ce1dc506b..0000000000 --- a/actionpack/test/abstract_controller/callbacks_test.rb +++ /dev/null @@ -1,238 +0,0 @@ -require 'abstract_unit' - -module AbstractController - module Testing - - class ControllerWithCallbacks < AbstractController::Base - include AbstractController::Callbacks - end - - class Callback1 < ControllerWithCallbacks - set_callback :process_action, :before, :first - - def first - @text = "Hello world" - end - - def index - self.response_body = @text - end - end - - class TestCallbacks1 < ActiveSupport::TestCase - test "basic callbacks work" do - controller = Callback1.new - result = controller.process(:index) - assert_equal "Hello world", controller.response_body - end - end - - class Callback2 < ControllerWithCallbacks - before_filter :first - after_filter :second - around_filter :aroundz - - def first - @text = "Hello world" - end - - def second - @second = "Goodbye" - end - - def aroundz - @aroundz = "FIRST" - yield - @aroundz << "SECOND" - end - - def index - self.response_body = @text - end - end - - class TestCallbacks2 < ActiveSupport::TestCase - def setup - @controller = Callback2.new - end - - test "before_filter works" do - result = @controller.process(:index) - assert_equal "Hello world", @controller.response_body - end - - test "after_filter works" do - @controller.process(:index) - assert_equal "Goodbye", @controller.instance_variable_get("@second") - end - - test "around_filter works" do - @controller.process(:index) - assert_equal "FIRSTSECOND", @controller.instance_variable_get("@aroundz") - end - end - - class Callback3 < ControllerWithCallbacks - before_filter do |c| - c.instance_variable_set("@text", "Hello world") - end - - after_filter do |c| - c.instance_variable_set("@second", "Goodbye") - end - - def index - self.response_body = @text - end - end - - class TestCallbacks3 < ActiveSupport::TestCase - def setup - @controller = Callback3.new - end - - test "before_filter works with procs" do - result = @controller.process(:index) - assert_equal "Hello world", @controller.response_body - end - - test "after_filter works with procs" do - result = @controller.process(:index) - assert_equal "Goodbye", @controller.instance_variable_get("@second") - end - end - - class CallbacksWithConditions < ControllerWithCallbacks - before_filter :list, :only => :index - before_filter :authenticate, :except => :index - - def index - self.response_body = @list.join(", ") - end - - def sekrit_data - self.response_body = (@list + [@authenticated]).join(", ") - end - - private - def list - @list = ["Hello", "World"] - end - - def authenticate - @list = [] - @authenticated = "true" - end - end - - class TestCallbacksWithConditions < ActiveSupport::TestCase - def setup - @controller = CallbacksWithConditions.new - end - - test "when :only is specified, a before filter is triggered on that action" do - @controller.process(:index) - assert_equal "Hello, World", @controller.response_body - end - - test "when :only is specified, a before filter is not triggered on other actions" do - @controller.process(:sekrit_data) - assert_equal "true", @controller.response_body - end - - test "when :except is specified, an after filter is not triggered on that action" do - result = @controller.process(:index) - assert_nil @controller.instance_variable_get("@authenticated") - end - end - - class CallbacksWithArrayConditions < ControllerWithCallbacks - before_filter :list, :only => [:index, :listy] - before_filter :authenticate, :except => [:index, :listy] - - def index - self.response_body = @list.join(", ") - end - - def sekrit_data - self.response_body = (@list + [@authenticated]).join(", ") - end - - private - def list - @list = ["Hello", "World"] - end - - def authenticate - @list = [] - @authenticated = "true" - end - end - - class TestCallbacksWithArrayConditions < ActiveSupport::TestCase - def setup - @controller = CallbacksWithArrayConditions.new - end - - test "when :only is specified with an array, a before filter is triggered on that action" do - result = @controller.process(:index) - assert_equal "Hello, World", @controller.response_body - end - - test "when :only is specified with an array, a before filter is not triggered on other actions" do - result = @controller.process(:sekrit_data) - assert_equal "true", @controller.response_body - end - - test "when :except is specified with an array, an after filter is not triggered on that action" do - result = @controller.process(:index) - assert_nil @controller.instance_variable_get("@authenticated") - end - end - - class ChangedConditions < Callback2 - before_filter :first, :only => :index - - def not_index - self.response_body = @text.to_s - end - end - - class TestCallbacksWithChangedConditions < ActiveSupport::TestCase - def setup - @controller = ChangedConditions.new - end - - test "when a callback is modified in a child with :only, it works for the :only action" do - result = @controller.process(:index) - assert_equal "Hello world", @controller.response_body - end - - test "when a callback is modified in a child with :only, it does not work for other actions" do - result = @controller.process(:not_index) - assert_equal "", @controller.response_body - end - end - - class SetsResponseBody < ControllerWithCallbacks - before_filter :set_body - - def index - self.response_body = "Fail" - end - - def set_body - self.response_body = "Success" - end - end - - class TestHalting < ActiveSupport::TestCase - test "when a callback sets the response body, the action should not be invoked" do - controller = SetsResponseBody.new - controller.process(:index) - assert_equal "Success", controller.response_body - end - end - - end -end diff --git a/actionpack/test/abstract_controller/helper_test.rb b/actionpack/test/abstract_controller/helper_test.rb deleted file mode 100644 index 5a363c9aa5..0000000000 --- a/actionpack/test/abstract_controller/helper_test.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'abstract_unit' - -module AbstractController - module Testing - - class ControllerWithHelpers < AbstractController::Base - include AbstractController::RenderingController - include Helpers - - def render(string) - super(:_template_name => string) - end - - append_view_path File.expand_path(File.join(File.dirname(__FILE__), "views")) - end - - module HelperyTest - def included_method - "Included" - end - end - - class MyHelpers1 < ControllerWithHelpers - helper(HelperyTest) do - def helpery_test - "World" - end - end - - def index - render "helper_test.erb" - end - end - - class TestHelpers < ActiveSupport::TestCase - def test_helpers - controller = MyHelpers1.new - controller.process(:index) - assert_equal "Hello World : Included", controller.response_body - end - end - - end -end diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract_controller/layouts_test.rb deleted file mode 100644 index 453d31826e..0000000000 --- a/actionpack/test/abstract_controller/layouts_test.rb +++ /dev/null @@ -1,235 +0,0 @@ -require 'abstract_unit' -require 'active_support/core_ext/class/removal' - -module AbstractControllerTests - module Layouts - - # Base controller for these tests - class Base < AbstractController::Base - include AbstractController::RenderingController - include AbstractController::Layouts - - 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" => - "With Implied <%= yield %>", - "layouts/omg.erb" => "OMGHI2U <%= yield %>", - "layouts/with_false_layout.erb" => "False Layout <%= yield %>" - )] - - def self.controller_path - @controller_path ||= self.name.sub(/Controller$/, '').underscore - end - - def controller_path() self.class.controller_path end - - def render_to_body(options) - options[:_layout] = _default_layout({}) - super - end - end - - class Blank < Base - self.view_paths = [] - - def index - render :_template => ActionView::TextTemplate.new("Hello blank!") - end - end - - class WithString < Base - layout "hello" - - def index - render :_template => ActionView::TextTemplate.new("Hello string!") - end - end - - class WithStringChild < WithString - end - - class WithStringOverriddenChild < WithString - layout "hello_override" - end - - class WithNilChild < WithString - layout nil - end - - class WithStringImpliedChild < WithString - end - - class WithChildOfImplied < WithStringImpliedChild - end - - class WithSymbol < Base - layout :hello - - def index - render :_template => ActionView::TextTemplate.new("Hello symbol!") - end - private - def hello - "omg" - end - end - - class WithSymbolReturningString < Base - layout :no_hello - - def index - render :_template => ActionView::TextTemplate.new("Hello missing symbol!") - end - private - def no_hello - nil - end - end - - class WithSymbolReturningNil < Base - layout :nilz - - def index - render :_template => ActionView::TextTemplate.new("Hello nilz!") - end - - def nilz() end - end - - class WithSymbolReturningObj < Base - layout :objekt - - def index - render :_template => ActionView::TextTemplate.new("Hello nilz!") - end - - def objekt - Object.new - end - end - - class WithSymbolAndNoMethod < Base - layout :omg_no_method - - def index - render :_template => ActionView::TextTemplate.new("Hello boom!") - end - end - - class WithMissingLayout < Base - layout "missing" - - def index - render :_template => ActionView::TextTemplate.new("Hello missing!") - end - end - - class WithFalseLayout < Base - layout false - - def index - render :_template => ActionView::TextTemplate.new("Hello false!") - end - end - - class WithNilLayout < Base - layout nil - - def index - render :_template => ActionView::TextTemplate.new("Hello nil!") - 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 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 symbol, call the requested method and use the layout returned" do - controller = WithSymbol.new - controller.process(:index) - assert_equal "OMGHI2U 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(NoMethodError, /:nilz/) { 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 child controller specifies layout nil, do not use the parent layout" do - controller = WithNilChild.new - controller.process(:index) - assert_equal "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 "raises an exception when specifying layout true" do - assert_raises ArgumentError do - Object.class_eval do - class ::BadOmgFailLolLayout < AbstractControllerTests::Layouts::Base - layout true - end - end - end - end - end - end -end diff --git a/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/formatted.html.erb b/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/formatted.html.erb deleted file mode 100644 index 785bf69191..0000000000 --- a/actionpack/test/abstract_controller/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_controller/views/abstract_controller/testing/me3/index.erb b/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/index.erb deleted file mode 100644 index f079ad8204..0000000000 --- a/actionpack/test/abstract_controller/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_controller/views/abstract_controller/testing/me4/index.erb b/actionpack/test/abstract_controller/views/abstract_controller/testing/me4/index.erb deleted file mode 100644 index 89dce12bdc..0000000000 --- a/actionpack/test/abstract_controller/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_controller/views/abstract_controller/testing/me5/index.erb b/actionpack/test/abstract_controller/views/abstract_controller/testing/me5/index.erb deleted file mode 100644 index 84d0b7417e..0000000000 --- a/actionpack/test/abstract_controller/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_controller/views/action_with_ivars.erb b/actionpack/test/abstract_controller/views/action_with_ivars.erb deleted file mode 100644 index 8d8ae22fd7..0000000000 --- a/actionpack/test/abstract_controller/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_controller/views/helper_test.erb b/actionpack/test/abstract_controller/views/helper_test.erb deleted file mode 100644 index 8ae45cc195..0000000000 --- a/actionpack/test/abstract_controller/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_controller/views/index.erb b/actionpack/test/abstract_controller/views/index.erb deleted file mode 100644 index cc1a8b8c85..0000000000 --- a/actionpack/test/abstract_controller/views/index.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from index.erb \ No newline at end of file diff --git a/actionpack/test/abstract_controller/views/layouts/abstract_controller/testing/me4.erb b/actionpack/test/abstract_controller/views/layouts/abstract_controller/testing/me4.erb deleted file mode 100644 index 172dd56569..0000000000 --- a/actionpack/test/abstract_controller/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_controller/views/layouts/application.erb b/actionpack/test/abstract_controller/views/layouts/application.erb deleted file mode 100644 index 27317140ad..0000000000 --- a/actionpack/test/abstract_controller/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_controller/views/naked_render.erb b/actionpack/test/abstract_controller/views/naked_render.erb deleted file mode 100644 index 1b3d03878b..0000000000 --- a/actionpack/test/abstract_controller/views/naked_render.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from naked_render.erb \ No newline at end of file -- cgit v1.2.3 From f5ace625fe524938be35ad7d16bc9c29fd08fb96 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 13:22:09 -0500 Subject: Ensure changes to I18n locale get reset during tests --- actionpack/test/dispatch/show_exceptions_test.rb | 3 +-- actionpack/test/new_base/render_rjs_test.rb | 11 ++++++++--- actionpack/test/template/render_test.rb | 14 +++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index ce1973853e..d4800e4edb 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -70,8 +70,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest test "localize public rescue message" do # Change locale - old_locale = I18n.locale - I18n.locale = :da + old_locale, I18n.locale = I18n.locale, :da begin @integration_session = open_session(ProductionApp) diff --git a/actionpack/test/new_base/render_rjs_test.rb b/actionpack/test/new_base/render_rjs_test.rb index 9c6416bbe0..7b76c54ab9 100644 --- a/actionpack/test/new_base/render_rjs_test.rb +++ b/actionpack/test/new_base/render_rjs_test.rb @@ -1,9 +1,7 @@ require 'abstract_unit' 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'", @@ -26,6 +24,14 @@ module RenderRjs class TestBasic < SimpleRouteCase testing BasicController + def setup + @old_locale = I18n.locale + end + + def teardown + I18n.locale = @old_locale + end + test "rendering a partial in an RJS template should pick the JS template over the HTML one" do get :index, "format" => "js" assert_response("$(\"customer\").update(\"JS Partial\");") @@ -40,6 +46,5 @@ module RenderRjs get :index_locale, "format" => "js" assert_response("$(\"customer\").update(\"Danish HTML Partial\");") end - end end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index c86d5215cd..3c192906ae 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -33,18 +33,14 @@ module RenderTestCases end def test_render_file_with_localization - begin - old_locale = I18n.locale - I18n.locale = :da - assert_equal "Hey verden", @view.render(:file => "test/hello_world") - ensure - I18n.locale = old_locale - end + old_locale, I18n.locale = I18n.locale, :da + assert_equal "Hey verden", @view.render(:file => "test/hello_world") + ensure + I18n.locale = old_locale end def test_render_file_with_dashed_locale - old_locale = I18n.locale - I18n.locale = :"pt-BR" + old_locale, I18n.locale = I18n.locale, :"pt-BR" assert_equal "Ola mundo", @view.render(:file => "test/hello_world") ensure I18n.locale = old_locale -- cgit v1.2.3 From 7cc1c2e71da1ad277acc7a7664321d2224a56bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 19 Sep 2009 12:31:47 -0300 Subject: Add Orchestra instrumentation to fragment and page caching. --- actionpack/test/controller/caching_test.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 25e035cb49..bd17df73c7 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -625,15 +625,20 @@ class FragmentCachingTest < ActionController::TestCase def test_fragment_for_logging fragment_computed = false - @controller.class.expects(:benchmark).with('Cached fragment exists?: views/expensive') - @controller.class.expects(:benchmark).with('Cached fragment miss: views/expensive') - @controller.class.expects(:benchmark).with('Cached fragment hit: views/expensive').never + listener = [] + ActiveSupport::Orchestra.register listener buffer = 'generated till now -> ' @controller.fragment_for(buffer, 'expensive') { fragment_computed = true } + assert_equal 2, listener.size + assert_equal :fragment_exist?, listener[0].name + assert_equal :write_fragment, listener[1].name + assert fragment_computed assert_equal 'generated till now -> ', buffer + ensure + ActiveSupport::Orchestra.unregister listener end end -- cgit v1.2.3 From a0233dd3b21416e62be82f9b1b81258d985633bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 20 Sep 2009 10:09:08 -0300 Subject: Use NewCallbacks on ActionDispatch::Callbacks. --- actionpack/test/controller/dispatcher_test.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 9fae1fcf63..150fc83cde 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -3,13 +3,16 @@ require 'abstract_unit' class DispatcherTest < Test::Unit::TestCase Dispatcher = ActionController::Dispatcher + class Foo + cattr_accessor :a, :b + end + def setup ENV['REQUEST_METHOD'] = 'GET' # Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks - ActionDispatch::Callbacks.instance_variable_set("@prepare_callbacks", ActiveSupport::Callbacks::CallbackChain.new) - ActionDispatch::Callbacks.instance_variable_set("@before_callbacks", ActiveSupport::Callbacks::CallbackChain.new) - ActionDispatch::Callbacks.instance_variable_set("@after_callbacks", ActiveSupport::Callbacks::CallbackChain.new) + ActionDispatch::Callbacks.reset_callbacks(:prepare) + ActionDispatch::Callbacks.reset_callbacks(:call) @old_router, Dispatcher.router = Dispatcher.router, mock() Dispatcher.router.stubs(:call).returns([200, {}, 'response']) @@ -68,13 +71,12 @@ class DispatcherTest < Test::Unit::TestCase end def test_to_prepare_with_identifier_replaces - a = b = nil - Dispatcher.to_prepare(:unique_id) { |*args| a = b = 1 } - Dispatcher.to_prepare(:unique_id) { |*args| a = 2 } + Dispatcher.to_prepare(:unique_id) { |*args| Foo.a, Foo.b = 1, 1 } + Dispatcher.to_prepare(:unique_id) { |*args| Foo.a = 2 } dispatch - assert_equal 2, a - assert_equal nil, b + assert_equal 2, Foo.a + assert_equal nil, Foo.b end private -- cgit v1.2.3