From 8df7fe3f630e13da1585c151f6f2f986ea7dcdfd Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Mon, 3 Oct 2011 12:05:25 +0400 Subject: normalize arg for ActionView::TestCase tests method --- actionpack/test/template/test_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/test_test.rb b/actionpack/test/template/test_test.rb index bf789cd8b7..adcbf1447f 100644 --- a/actionpack/test/template/test_test.rb +++ b/actionpack/test/template/test_test.rb @@ -62,3 +62,19 @@ class CrazyHelperTest < ActionView::TestCase assert_equal PeopleHelper, self.class.helper_class end end + +class CrazySymbolHelperTest < ActionView::TestCase + tests :people + + def test_set_helper_class_using_symbol + assert_equal PeopleHelper, self.class.helper_class + end +end + +class CrazyStringHelperTest < ActionView::TestCase + tests 'people' + + def test_set_helper_class_using_string + assert_equal PeopleHelper, self.class.helper_class + end +end -- cgit v1.2.3 From fd8f0b297822ba36002084faa36bd0320d3be4a7 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 5 Oct 2011 15:41:28 -0200 Subject: stylesheet_link_tag('/stylesheets/application') and similar helpers doesn't throw Sprockets::FileOutsidePaths exception anymore --- actionpack/test/template/sprockets_helper_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index 08b66fec8b..db69f95130 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -219,6 +219,8 @@ class SprocketsHelperTest < ActionView::TestCase @config.assets.compile = true @config.assets.debug = true + assert_match %r{}, + javascript_include_tag('/javascripts/application') assert_match %r{\n}, javascript_include_tag(:application) end @@ -264,6 +266,9 @@ class SprocketsHelperTest < ActionView::TestCase @config.assets.compile = true @config.assets.debug = true + assert_match %r{}, + stylesheet_link_tag('/stylesheets/application') + assert_match %r{\n}, stylesheet_link_tag(:application) -- cgit v1.2.3 From 7f64e472772293a3a5bbf4a435d937dabd98ed92 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 7 Oct 2011 16:56:18 -0700 Subject: just check to see that the first item in the list is an array --- actionpack/test/template/form_options_helper_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 6aea991f7c..d3e0cc41a9 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -587,6 +587,15 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_empty + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", [], :prompt => true, :include_blank => true) + ) + end + def test_select_with_selected_value @post = Post.new @post.category = "" -- cgit v1.2.3 From d68f27e9b184a8e7e4ce71db11874a6b36ea1edc Mon Sep 17 00:00:00 2001 From: Ben Scheirman Date: Sat, 8 Oct 2011 18:38:02 -0500 Subject: accept optional :host parameter to force_ssl --- actionpack/test/controller/force_ssl_test.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/force_ssl_test.rb b/actionpack/test/controller/force_ssl_test.rb index 3e723e20d9..43b20fdead 100644 --- a/actionpack/test/controller/force_ssl_test.rb +++ b/actionpack/test/controller/force_ssl_test.rb @@ -14,6 +14,10 @@ class ForceSSLControllerLevel < ForceSSLController force_ssl end +class ForceSSLCustomDomain < ForceSSLController + force_ssl :host => "secure.test.host" +end + class ForceSSLOnlyAction < ForceSSLController force_ssl :only => :cheeseburger end @@ -38,6 +42,22 @@ class ForceSSLControllerLevelTest < ActionController::TestCase end end +class ForceSSLCustomDomainTest < ActionController::TestCase + tests ForceSSLCustomDomain + + def test_banana_redirects_to_https_with_custom_host + get :banana + assert_response 301 + assert_equal "https://secure.test.host/force_ssl_custom_domain/banana", redirect_to_url + end + + def test_cheeseburger_redirects_to_https_with_custom_host + get :cheeseburger + assert_response 301 + assert_equal "https://secure.test.host/force_ssl_custom_domain/cheeseburger", redirect_to_url + end +end + class ForceSSLOnlyActionTest < ActionController::TestCase tests ForceSSLOnlyAction @@ -80,4 +100,4 @@ class ForceSSLExcludeDevelopmentTest < ActionController::TestCase get :banana assert_response 200 end -end \ No newline at end of file +end -- cgit v1.2.3 From 114218e4da9a2adf7b6ef4a27d2fa47e15881cf1 Mon Sep 17 00:00:00 2001 From: Liborio Cannici Date: Thu, 15 Sep 2011 00:35:53 +0200 Subject: Fixes an issue when creating a date select with too many options. Inspired by dlt https://github.com/dlt/rails/commit/9e615634745dc81598e7b880d52411338d3a7a93 Closes #239. Conflicts: actionpack/CHANGELOG --- actionpack/test/template/date_helper_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 09c53a36f0..af30ec9892 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -664,6 +664,15 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005, :prefix => "date[first]") end + def test_select_date_with_too_big_range_between_start_year_and_end_year + assert_raise(ArgumentError) { select_date(Time.mktime(2003, 8, 16), :start_year => 2000, :end_year => 20000, :prefix => "date[first]", :order => [:month, :day, :year]) } + assert_raise(ArgumentError) { select_date(Time.mktime(2003, 8, 16), :start_year => Date.today.year - 100.years, :end_year => 2000, :prefix => "date[first]", :order => [:month, :day, :year]) } + end + + def test_select_date_can_have_more_then_1000_years_interval_if_forced_via_parameter + assert_nothing_raised { select_date(Time.mktime(2003, 8, 16), :start_year => 2000, :end_year => 3100, :max_years_allowed => 2000) } + end + def test_select_date_with_order expected = %(\n\n\n\n", + select("post", "category", [["Number", "number"], ["Text", "text"], ["Yes/No", "boolean"]], :prompt => true, :include_blank => true) + ) + end + def test_select_with_selected_value @post = Post.new @post.category = "" -- cgit v1.2.3 From 80768b739ed7e2053d85a01dd5fa60bde67aad9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 26 Oct 2011 09:31:56 +0200 Subject: Responders now return 204 No Content for API requests without a response body (as in the new scaffold) --- actionpack/test/controller/mime_responds_test.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index e91e11a8a7..76a8c89e60 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -796,21 +796,21 @@ class RespondWithControllerTest < ActionController::TestCase end end - def test_using_resource_for_put_with_xml_yields_ok_on_success + def test_using_resource_for_put_with_xml_yields_no_content_on_success @request.accept = "application/xml" put :using_resource assert_equal "application/xml", @response.content_type - assert_equal 200, @response.status + assert_equal 204, @response.status assert_equal " ", @response.body end - def test_using_resource_for_put_with_json_yields_ok_on_success + def test_using_resource_for_put_with_json_yields_no_content_on_success Customer.any_instance.stubs(:to_json).returns('{"name": "David"}') @request.accept = "application/json" put :using_resource assert_equal "application/json", @response.content_type - assert_equal 200, @response.status - assert_equal "{}", @response.body + assert_equal 204, @response.status + assert_equal " ", @response.body end def test_using_resource_for_put_with_xml_yields_unprocessable_entity_on_failure @@ -846,23 +846,23 @@ class RespondWithControllerTest < ActionController::TestCase end end - def test_using_resource_for_delete_with_xml_yields_ok_on_success + def test_using_resource_for_delete_with_xml_yields_no_content_on_success Customer.any_instance.stubs(:destroyed?).returns(true) @request.accept = "application/xml" delete :using_resource assert_equal "application/xml", @response.content_type - assert_equal 200, @response.status + assert_equal 204, @response.status assert_equal " ", @response.body end - def test_using_resource_for_delete_with_json_yields_ok_on_success + def test_using_resource_for_delete_with_json_yields_no_content_on_success Customer.any_instance.stubs(:to_json).returns('{"name": "David"}') Customer.any_instance.stubs(:destroyed?).returns(true) @request.accept = "application/json" delete :using_resource assert_equal "application/json", @response.content_type - assert_equal 200, @response.status - assert_equal "{}", @response.body + assert_equal 204, @response.status + assert_equal " ", @response.body end def test_using_resource_for_delete_with_html_redirects_on_failure -- cgit v1.2.3 From 6cbe4223a77d7ea364b4d2dc46cec6a0c58c9537 Mon Sep 17 00:00:00 2001 From: Christopher Meiklejohn Date: Sat, 30 Jul 2011 00:49:36 -0400 Subject: Ensure that the format isn't applied twice to the cache key, else it becomes impossible to target with expire_action. --- actionpack/test/controller/caching_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 618e7b77b2..2364bbf3a3 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -194,6 +194,7 @@ class ActionCachingTestController < CachingController caches_action :show, :cache_path => 'http://test.host/custom/show' caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" } caches_action :with_layout + caches_action :with_format_and_http_param, :cache_path => Proc.new { |c| { :key => 'value' } } caches_action :layout_false, :layout => false caches_action :record_not_found, :four_oh_four, :simple_runtime_error @@ -219,6 +220,11 @@ class ActionCachingTestController < CachingController render :text => @cache_this, :layout => true end + def with_format_and_http_param + @cache_this = MockTime.now.to_f.to_s + render :text => @cache_this + end + def record_not_found raise ActiveRecord::RecordNotFound, "oops!" end @@ -359,6 +365,13 @@ class ActionCacheTest < ActionController::TestCase assert !fragment_exist?('hostname.com/action_caching_test') end + def test_action_cache_with_format_and_http_param + get :with_format_and_http_param, :format => 'json' + assert_response :success + assert !fragment_exist?('hostname.com/action_caching_test/with_format_and_http_param.json?key=value.json') + assert fragment_exist?('hostname.com/action_caching_test/with_format_and_http_param.json?key=value') + end + def test_action_cache_with_store_options MockTime.expects(:now).returns(12345).once @controller.expects(:read_fragment).with('hostname.com/action_caching_test', :expires_in => 1.hour).once -- cgit v1.2.3 From b5f908a7ad515215f164e306f82c3e6c506182cb Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 3 Nov 2011 16:09:57 +0000 Subject: Stub find_template so that when handle_render_error is called in ActionView::Template, we get to see the actual underlying error rather than a NoMethodError. This shows an encoding bug on Ruby 1.9.3. --- actionpack/test/template/template_test.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index b0ca7de0b6..70ca876c67 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -8,6 +8,9 @@ class TestERBTemplate < ActiveSupport::TestCase def disable_cache yield end + + def find_template(*args) + end end class Context -- cgit v1.2.3 From 56207a3f0165650abb273594f1f54fbb92bbf177 Mon Sep 17 00:00:00 2001 From: Waseem Ahmad Date: Fri, 4 Nov 2011 15:03:02 +0530 Subject: Remove 'size' attribute from number_field form helper fixes #3454 f.number_field generates which is invalid HTML5. See: http://dev.w3.org/html5/spec/Overview.html#number-state --- actionpack/test/template/form_helper_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index e36d032f6c..bd7b322fc9 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -438,12 +438,12 @@ class FormHelperTest < ActionView::TestCase end def test_number_field - expected = %{} + expected = %{} assert_dom_equal(expected, number_field("order", "quantity", :in => 1...10)) end def test_range_input - expected = %{} + expected = %{} assert_dom_equal(expected, range_field("hifi", "volume", :in => 0..11, :step => 0.1)) end -- cgit v1.2.3 From cb06727b6cb7310808f5b9ce1bf254055806ba80 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 4 Nov 2011 16:44:59 +0530 Subject: add tests for the case where size is explicitly passed to number_field helper --- actionpack/test/template/form_helper_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index bd7b322fc9..6434d9645e 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -440,11 +440,15 @@ class FormHelperTest < ActionView::TestCase def test_number_field expected = %{} assert_dom_equal(expected, number_field("order", "quantity", :in => 1...10)) + expected = %{} + assert_dom_equal(expected, number_field("order", "quantity", :size => 30, :in => 1...10)) end def test_range_input expected = %{} assert_dom_equal(expected, range_field("hifi", "volume", :in => 0..11, :step => 0.1)) + expected = %{} + assert_dom_equal(expected, range_field("hifi", "volume", :size => 30, :in => 0..11, :step => 0.1)) end def test_explicit_name -- cgit v1.2.3 From 10773f94eae0dacf10e2ed0c28f6bb73805c2521 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sat, 5 Nov 2011 16:42:53 +0000 Subject: Skip test_default_external_works on the CI for Ruby 1.9.3. This test is affected by a bug in Ruby 1.9.3p0 and trunk: http://redmine.ruby-lang.org/issues/5564 Given we cannot fix it for ourselves, it is better to skip for now so that we will easily see if further failures are introduced. Jon Leighton is monitoring the bug report and will revert this when a suitable solution is found (either a new Ruby release or a generic workaround). If you are using 1.9.3 in your app and have templates that are not in UTF-8, you should add a workaround early on in the boot process. For example, if your templates are Shift_JIS encoded, then add the following in an initializer: Encoding::Converter.new('Shift_JIS', 'UTF-8') --- actionpack/test/template/template_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 70ca876c67..f3328b5dca 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -130,6 +130,17 @@ class TestERBTemplate < ActiveSupport::TestCase # is set to something other than UTF-8, we don't # get any errors and get back a UTF-8 String. def test_default_external_works + if ENV['TRAVIS'] && RUBY_VERSION >= '1.9.3' + skip( + "There is currently a bug in Ruby trunk and in 1.9.3 which makes this test fail. " \ + "Please see http://redmine.ruby-lang.org/issues/5564. " \ + "Given there is no known generic workaround that this requires a fix in Ruby itself, " \ + "this test is skipped on the CI for now so that we don't pollute the CI with failures. " \ + "Jon Leighton is monitoring the bug report and will renable this test when a solution " \ + "becomes available." + ) + end + with_external_encoding "ISO-8859-1" do @template = new_template("hello \xFCmlat") assert_equal Encoding::UTF_8, render.encoding -- cgit v1.2.3 From 7776055e2dcd29e0f8f27154663263c0bbd1c188 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sun, 6 Nov 2011 10:15:04 +0000 Subject: Revert "Skip test_default_external_works on the CI for Ruby 1.9.3." This reverts commit 10773f94eae0dacf10e2ed0c28f6bb73805c2521. --- actionpack/test/template/template_test.rb | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index f3328b5dca..70ca876c67 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -130,17 +130,6 @@ class TestERBTemplate < ActiveSupport::TestCase # is set to something other than UTF-8, we don't # get any errors and get back a UTF-8 String. def test_default_external_works - if ENV['TRAVIS'] && RUBY_VERSION >= '1.9.3' - skip( - "There is currently a bug in Ruby trunk and in 1.9.3 which makes this test fail. " \ - "Please see http://redmine.ruby-lang.org/issues/5564. " \ - "Given there is no known generic workaround that this requires a fix in Ruby itself, " \ - "this test is skipped on the CI for now so that we don't pollute the CI with failures. " \ - "Jon Leighton is monitoring the bug report and will renable this test when a solution " \ - "becomes available." - ) - end - with_external_encoding "ISO-8859-1" do @template = new_template("hello \xFCmlat") assert_equal Encoding::UTF_8, render.encoding -- cgit v1.2.3 From bd559b00680b6e4c272d4df36f239768750f1a6b Mon Sep 17 00:00:00 2001 From: Bradford Folkens Date: Tue, 8 Nov 2011 07:52:35 -0600 Subject: Fix trouble using :subdomain in development environment when using numeric addresses. See-also pull request #3561 from 3-1-stable Otherwise the following occurs: TypeError: can't convert nil into String /Users/bfolkens/dev/bfolkens-rails-core/actionpack/lib/action_dispatch/http/url.rb:75:in host_or_subdomain_and_domain' /Users/bfolkens/dev/bfolkens-rails-core/actionpack/lib/action_dispatch/http/url.rb:37:in url_for' /Users/bfolkens/dev/bfolkens-rails-core/actionpack/lib/action_dispatch/routing/url_for.rb:147:in test_subdomain_may_be_accepted_with_numeric_host' /Users/bfolkens/dev/bfolkens-rails-core/activesupport/lib/active_support/testing/setup_and_teardown.rb:67:in run' /Users/bfolkens/dev/bfolkens-rails-core/activesupport/lib/active_support/callbacks.rb:426:in send' /Users/bfolkens/dev/bfolkens-rails-core/activesupport/lib/active_support/callbacks.rb:81:in run' --- actionpack/test/controller/url_for_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb index 11ced2df2a..dc07e07cb9 100644 --- a/actionpack/test/controller/url_for_test.rb +++ b/actionpack/test/controller/url_for_test.rb @@ -16,6 +16,10 @@ module AbstractController W.default_url_options[:host] = 'www.basecamphq.com' end + def add_numeric_host! + W.default_url_options[:host] = '127.0.0.1' + end + def test_exception_is_thrown_without_host assert_raise ArgumentError do W.new.url_for :controller => 'c', :action => 'a', :id => 'i' @@ -81,6 +85,13 @@ module AbstractController ) end + def test_subdomain_may_be_accepted_with_numeric_host + add_numeric_host! + assert_equal('http://127.0.0.1/c/a/i', + W.new.url_for(:subdomain => 'api', :controller => 'c', :action => 'a', :id => 'i') + ) + end + def test_domain_may_be_changed add_host! assert_equal('http://www.37signals.com/c/a/i', -- cgit v1.2.3 From be7ab83b647c1ebb619b88854d310497075ea58f Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 10 Nov 2011 10:54:56 +0900 Subject: A test case to ensure that AC::Metal#response_body= always wraps the given value in an Array in both Ruby 1.8 and 1.9 (refs #3581) --- actionpack/test/controller/new_base/bare_metal_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/new_base/bare_metal_test.rb b/actionpack/test/controller/new_base/bare_metal_test.rb index 3ca29f1bcf..c424dcbd8d 100644 --- a/actionpack/test/controller/new_base/bare_metal_test.rb +++ b/actionpack/test/controller/new_base/bare_metal_test.rb @@ -23,6 +23,12 @@ module BareMetalTest assert_equal "Hello world", string end + + test "response_body value is wrapped in an array when the value is a String" do + controller = BareController.new + controller.index + assert_equal ["Hello world"], controller.response_body + end end class HeadController < ActionController::Metal -- cgit v1.2.3 From b5c3987294d3860a78b1b04ee49b2b55f3cdc614 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Thu, 10 Nov 2011 11:26:42 +0400 Subject: Fix and simplify highlight regexp --- actionpack/test/template/text_helper_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 02f9609483..a0afb77f05 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -194,6 +194,10 @@ class TextHelperTest < ActionView::TestCase "

This is a beautiful morning, but also a beautiful day

", highlight("

This is a beautiful morning, but also a beautiful day

", "beautiful") ) + assert_equal( + "
abc div
", + highlight("
abc div
", "div", :highlighter => '\1') + ) end def test_excerpt -- cgit v1.2.3 From 8f0085a483ebc6d416e902c3caff68f82934e091 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Sun, 13 Nov 2011 10:19:54 -1000 Subject: change tests to expect X-F-F over REMOTE_ADDR --- actionpack/test/dispatch/request_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index a611252b31..4658eeea17 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -36,7 +36,7 @@ class RequestTest < ActiveSupport::TestCase request = stub_request 'REMOTE_ADDR' => '1.2.3.4', 'HTTP_X_FORWARDED_FOR' => '3.4.5.6' - assert_equal '1.2.3.4', request.remote_ip + assert_equal '3.4.5.6', request.remote_ip request = stub_request 'REMOTE_ADDR' => '127.0.0.1', 'HTTP_X_FORWARDED_FOR' => '3.4.5.6' @@ -106,7 +106,7 @@ class RequestTest < ActiveSupport::TestCase request = stub_request 'REMOTE_ADDR' => '67.205.106.74,172.16.0.1', 'HTTP_X_FORWARDED_FOR' => '3.4.5.6' - assert_equal '67.205.106.74', request.remote_ip + assert_equal '3.4.5.6', request.remote_ip request = stub_request 'HTTP_X_FORWARDED_FOR' => 'unknown,67.205.106.73' assert_equal 'unknown', request.remote_ip -- cgit v1.2.3 From b8c85de62004868a34a27e58731f2a9e37aeebd0 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Mon, 14 Nov 2011 12:29:51 -1000 Subject: add test for bug fixed in 4f2bf64 --- actionpack/test/dispatch/request_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 4658eeea17..4d805464c2 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -89,6 +89,11 @@ class RequestTest < ActiveSupport::TestCase assert_equal '9.9.9.9', request.remote_ip end + test "remote ip when the remote ip middleware returns nil" do + request = stub_request 'REMOTE_ADDR' => '127.0.0.1' + assert_equal '127.0.0.1', request.remote_ip + end + test "remote ip with user specified trusted proxies" do @trusted_proxies = /^67\.205\.106\.73$/i -- cgit v1.2.3 From c2b6f63bbe2740fd63a36eeefe17d51813a17324 Mon Sep 17 00:00:00 2001 From: Alexander Uvarov Date: Thu, 17 Nov 2011 12:04:46 +0600 Subject: Fix impractical I18n lookup in nested fields_for --- actionpack/test/template/form_helper_test.rb | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 6434d9645e..34486bb151 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -27,7 +27,13 @@ class FormHelperTest < ActionView::TestCase :body => "Write entire text here", :color => { :red => "Rojo" + }, + :comments => { + :body => "Write body here" } + }, + :tag => { + :value => "Tag" } } } @@ -68,6 +74,12 @@ class FormHelperTest < ActionView::TestCase @post.secret = 1 @post.written_on = Date.new(2004, 6, 15) + @post.comments = [] + @post.comments << @comment + + @post.tags = [] + @post.tags << Tag.new + @blog_post = Blog::Post.new("And his name will be forty and four.", 44) end @@ -151,6 +163,40 @@ class FormHelperTest < ActionView::TestCase I18n.locale = old_locale end + def test_label_with_locales_and_nested_attributes + old_locale, I18n.locale = I18n.locale, :label + form_for(@post, :html => { :id => 'create-post' }) do |f| + f.fields_for(:comments) do |cf| + concat cf.label(:body) + end + end + + expected = whole_form("/posts/123", "create-post" , "edit_post", :method => "put") do + "" + end + + assert_dom_equal expected, output_buffer + ensure + I18n.locale = old_locale + end + + def test_label_with_locales_fallback_and_nested_attributes + old_locale, I18n.locale = I18n.locale, :label + form_for(@post, :html => { :id => 'create-post' }) do |f| + f.fields_for(:tags) do |cf| + concat cf.label(:value) + end + end + + expected = whole_form("/posts/123", "create-post" , "edit_post", :method => "put") do + "" + end + + assert_dom_equal expected, output_buffer + ensure + I18n.locale = old_locale + end + def test_label_with_for_attribute_as_symbol assert_dom_equal('', label(:post, :title, nil, :for => "my_for")) end -- cgit v1.2.3 From e8d57f361a9982382f75449ec0d65d6c798b9ce2 Mon Sep 17 00:00:00 2001 From: lest Date: Thu, 17 Nov 2011 18:29:55 +0300 Subject: _html translation should escape interpolated arguments --- actionpack/test/template/translation_helper_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb index cd9f54e04c..cabb29cfad 100644 --- a/actionpack/test/template/translation_helper_test.rb +++ b/actionpack/test/template/translation_helper_test.rb @@ -17,6 +17,7 @@ class TranslationHelperTest < ActiveSupport::TestCase :hello => 'Hello World', :html => 'Hello World', :hello_html => 'Hello World', + :interpolated_html => 'Hello %{word}', :array_html => %w(foo bar), :array => %w(foo bar) } @@ -83,6 +84,11 @@ class TranslationHelperTest < ActiveSupport::TestCase assert translate(:'translations.hello_html').html_safe? end + def test_translate_escapes_interpolations_in_translations_with_a_html_suffix + assert_equal 'Hello <World>', translate(:'translations.interpolated_html', :word => '') + assert_equal 'Hello <World>', translate(:'translations.interpolated_html', :word => stub(:to_s => "")) + end + def test_translation_returning_an_array_ignores_html_suffix assert_equal ["foo", "bar"], translate(:'translations.array_html') end -- cgit v1.2.3 From 4589b2419b6c2f6d8b1ea0873999a4d0fa21bdb3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 31 Oct 2011 16:26:11 -0400 Subject: require that all blocks have arity of 2 --- actionpack/test/dispatch/routing_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index cf22731823..66b2263790 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -79,7 +79,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest match 'sign_in' => "sessions#new" match 'account/modulo/:name', :to => redirect("/%{name}s") - match 'account/proc/:name', :to => redirect {|params| "/#{params[:name].pluralize}" } + match 'account/proc/:name', :to => redirect {|params, req| "/#{params[:name].pluralize}" } match 'account/proc_req' => redirect {|params, req| "/#{req.method}" } match 'account/google' => redirect('http://www.google.com/', :status => 302) -- cgit v1.2.3 From 0809c675ef5831852b7c1aa8497402b2beff5185 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 31 Oct 2011 17:49:20 -0400 Subject: remove the :path feature to redirects, since it cannot work --- actionpack/test/dispatch/routing_test.rb | 33 -------------------------------- 1 file changed, 33 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 66b2263790..c887fe7e6a 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -62,13 +62,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest match 'secure', :to => redirect("/secure/login") match 'mobile', :to => redirect(:subdomain => 'mobile') - match 'documentation', :to => redirect(:domain => 'example-documentation.com', :path => '') - match 'new_documentation', :to => redirect(:path => '/documentation/new') match 'super_new_documentation', :to => redirect(:host => 'super-docs.com') - match 'stores/:name', :to => redirect(:subdomain => 'stores', :path => '/%{name}') - match 'stores/:name(*rest)', :to => redirect(:subdomain => 'stores', :path => '/%{name}%{rest}') - match 'youtube_favorites/:youtube_id/:name', :to => redirect(YoutubeFavoritesRedirector) constraints(lambda { |req| true }) do @@ -711,20 +706,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - def test_redirect_hash_with_domain_and_path - with_test_routes do - get '/documentation' - verify_redirect 'http://www.example-documentation.com' - end - end - - def test_redirect_hash_with_path - with_test_routes do - get '/new_documentation' - verify_redirect 'http://www.example.com/documentation/new' - end - end - def test_redirect_hash_with_host with_test_routes do get '/super_new_documentation?section=top' @@ -732,20 +713,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - def test_redirect_hash_path_substitution - with_test_routes do - get '/stores/iernest' - verify_redirect 'http://stores.example.com/iernest' - end - end - - def test_redirect_hash_path_substitution_with_catch_all - with_test_routes do - get '/stores/iernest/products' - verify_redirect 'http://stores.example.com/iernest/products' - end - end - def test_redirect_class with_test_routes do get '/youtube_favorites/oHg5SJYRHA0/rick-rolld' -- cgit v1.2.3 From 99d94f126d05398ec0917d75253ab1548bc54ba3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 1 Nov 2011 15:53:02 -0200 Subject: Refactoring the redirect method for the router api. --- actionpack/test/dispatch/routing_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index c887fe7e6a..19eee379fd 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -2299,6 +2299,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal "/forced_collision", routes_forced_collision_path end + def test_redirect_argument_error + routes = Class.new { include ActionDispatch::Routing::Redirection }.new + assert_raises(ArgumentError) { routes.redirect Object.new } + end + def test_explicitly_avoiding_the_named_route assert !respond_to?(:routes_no_collision_path) end -- cgit v1.2.3 From 771635e858e486e1e9f2d181b710d81205e6bb4e Mon Sep 17 00:00:00 2001 From: Tobias Svensson Date: Sat, 19 Nov 2011 13:02:56 +0000 Subject: Meaningful errors for unexpected partial arguments. Fixes #3573 --- actionpack/test/template/render_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 77659918f7..c29519276d 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -142,6 +142,13 @@ module RenderTestCases "and is followed by any combinations of letters, numbers, or underscores.", e.message end + def test_render_partial_with_incompatible_object + @view.render(:partial => nil) + flunk "Render did not raise ArgumentError" + rescue ArgumentError => e + assert_equal "'#{nil.inspect}' is not an ActiveModel-compatible object that returns a valid partial path.", e.message + end + def test_render_partial_with_errors @view.render(:partial => "test/raise") flunk "Render did not raise Template::Error" -- cgit v1.2.3 From 603a679e87d0317957eb44ce3928d593a0c50bb5 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sat, 19 Nov 2011 13:19:20 +0000 Subject: Don't html-escape the :count option to translate if it's a Numeric. Fixes #3685. --- actionpack/test/template/translation_helper_test.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb index cabb29cfad..397de9c2ce 100644 --- a/actionpack/test/template/translation_helper_test.rb +++ b/actionpack/test/template/translation_helper_test.rb @@ -19,7 +19,11 @@ class TranslationHelperTest < ActiveSupport::TestCase :hello_html => 'Hello World', :interpolated_html => 'Hello %{word}', :array_html => %w(foo bar), - :array => %w(foo bar) + :array => %w(foo bar), + :count_html => { + :one => 'One %{count}', + :other => 'Other %{count}' + } } ) @view = ::ActionView::Base.new(ActionController::Base.view_paths, {}) @@ -89,6 +93,12 @@ class TranslationHelperTest < ActiveSupport::TestCase assert_equal 'Hello <World>', translate(:'translations.interpolated_html', :word => stub(:to_s => "")) end + def test_translate_with_html_count + assert_equal 'One 1', translate(:'translations.count_html', :count => 1) + assert_equal 'Other 2', translate(:'translations.count_html', :count => 2) + assert_equal 'Other <One>', translate(:'translations.count_html', :count => '') + end + def test_translation_returning_an_array_ignores_html_suffix assert_equal ["foo", "bar"], translate(:'translations.array_html') end -- cgit v1.2.3 From a9e8cf78fda696738f63e726796f6232c3751603 Mon Sep 17 00:00:00 2001 From: lest Date: Mon, 21 Nov 2011 20:13:54 +0300 Subject: add ActionController::Metal#show_detailed_exceptions? --- actionpack/test/dispatch/show_exceptions_test.rb | 45 ++++++++++++++---------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 42f6c7f79f..09eebb3ab5 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -2,28 +2,35 @@ require 'abstract_unit' class ShowExceptionsTest < ActionDispatch::IntegrationTest - Boomer = lambda do |env| - req = ActionDispatch::Request.new(env) - case req.path - when "/not_found" - raise ActionController::UnknownAction - when "/runtime_error" - raise RuntimeError - when "/method_not_allowed" - raise ActionController::MethodNotAllowed - when "/not_implemented" - raise ActionController::NotImplemented - when "/unprocessable_entity" - raise ActionController::InvalidAuthenticityToken - when "/not_found_original_exception" - raise ActionView::Template::Error.new('template', {}, AbstractController::ActionNotFound.new) - else - raise "puke!" + class Boomer + def initialize(show_exceptions = false) + @show_exceptions = show_exceptions + end + + def call(env) + env['action_dispatch.show_exceptions'] = @show_exceptions + req = ActionDispatch::Request.new(env) + case req.path + when "/not_found" + raise ActionController::UnknownAction + when "/runtime_error" + raise RuntimeError + when "/method_not_allowed" + raise ActionController::MethodNotAllowed + when "/not_implemented" + raise ActionController::NotImplemented + when "/unprocessable_entity" + raise ActionController::InvalidAuthenticityToken + when "/not_found_original_exception" + raise ActionView::Template::Error.new('template', {}, AbstractController::ActionNotFound.new) + else + raise "puke!" + end end end - ProductionApp = ActionDispatch::ShowExceptions.new(Boomer, false) - DevelopmentApp = ActionDispatch::ShowExceptions.new(Boomer, true) + ProductionApp = ActionDispatch::ShowExceptions.new(Boomer.new(false)) + DevelopmentApp = ActionDispatch::ShowExceptions.new(Boomer.new(true)) test "rescue in public from a remote ip" do @app = ProductionApp -- cgit v1.2.3 From c6d6b28bb4e105fd0ae7a0ef3c7df4bc416bd397 Mon Sep 17 00:00:00 2001 From: lest Date: Tue, 22 Nov 2011 11:24:05 +0300 Subject: refactor show exceptions tests --- actionpack/test/controller/show_exceptions_test.rb | 59 +++++++++++++++++++++ actionpack/test/dispatch/show_exceptions_test.rb | 61 +++++++--------------- 2 files changed, 78 insertions(+), 42 deletions(-) create mode 100644 actionpack/test/controller/show_exceptions_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb new file mode 100644 index 0000000000..c328a42e89 --- /dev/null +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -0,0 +1,59 @@ +require 'abstract_unit' + +module ShowExceptions + class ShowExceptionsController < ActionController::Metal + use ActionDispatch::ShowExceptions + + def boom + raise 'boom!' + end + end + + class ShowExceptionsTest < ActionDispatch::IntegrationTest + test 'show error page from a remote ip' do + @app = ShowExceptionsController.action(:boom) + self.remote_addr = '208.77.188.166' + get '/' + assert_equal "500 error fixture\n", body + end + + test 'show diagnostics from a local ip' do + @app = ShowExceptionsController.action(:boom) + ['127.0.0.1', '127.0.0.127', '::1', '0:0:0:0:0:0:0:1', '0:0:0:0:0:0:0:1%0'].each do |ip_address| + self.remote_addr = ip_address + get '/' + assert_match /boom/, body + end + end + + test 'show diagnostics from a remote ip when consider_all_requests_local is true' do + Rails.stubs(:application).returns stub(:config => stub(:consider_all_requests_local => true)) + @app = ShowExceptionsController.action(:boom) + self.remote_addr = '208.77.188.166' + get '/' + assert_match /boom/, body + end + end + + class ShowExceptionsOverridenController < ShowExceptionsController + private + + def show_detailed_exceptions? + params['detailed'] == '1' + end + end + + class ShowExceptionsOverridenTest < ActionDispatch::IntegrationTest + test 'show error page' do + @app = ShowExceptionsOverridenController.action(:boom) + get '/', {'detailed' => '0'} + assert_equal "500 error fixture\n", body + end + + test 'show diagnostics message' do + @app = ShowExceptionsOverridenController.action(:boom) + get '/', {'detailed' => '1'} + assert_match /boom/, body + end + end +end diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 09eebb3ab5..9f4d6c530f 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -3,12 +3,12 @@ require 'abstract_unit' class ShowExceptionsTest < ActionDispatch::IntegrationTest class Boomer - def initialize(show_exceptions = false) - @show_exceptions = show_exceptions + def initialize(detailed = false) + @detailed = detailed end def call(env) - env['action_dispatch.show_exceptions'] = @show_exceptions + env['action_dispatch.show_detailed_exceptions'] = @detailed req = ActionDispatch::Request.new(env) case req.path when "/not_found" @@ -32,9 +32,8 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest ProductionApp = ActionDispatch::ShowExceptions.new(Boomer.new(false)) DevelopmentApp = ActionDispatch::ShowExceptions.new(Boomer.new(true)) - test "rescue in public from a remote ip" do + test "rescue with error page when show_exceptions is false" do @app = ProductionApp - self.remote_addr = '208.77.188.166' get "/", {}, {'action_dispatch.show_exceptions' => true} assert_response 500 @@ -49,32 +48,28 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest assert_equal "", body end - test "rescue locally from a local request" do - @app = ProductionApp - ['127.0.0.1', '127.0.0.127', '::1', '0:0:0:0:0:0:0:1', '0:0:0:0:0:0:0:1%0'].each do |ip_address| - self.remote_addr = ip_address + test "rescue with diagnostics message when show_exceptions is true" do + @app = DevelopmentApp - get "/", {}, {'action_dispatch.show_exceptions' => true} - assert_response 500 - assert_match(/puke/, body) + get "/", {}, {'action_dispatch.show_exceptions' => true} + assert_response 500 + assert_match(/puke/, body) - get "/not_found", {}, {'action_dispatch.show_exceptions' => true} - assert_response 404 - assert_match(/#{ActionController::UnknownAction.name}/, body) + get "/not_found", {}, {'action_dispatch.show_exceptions' => true} + assert_response 404 + assert_match(/#{ActionController::UnknownAction.name}/, body) - get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true} - assert_response 405 - assert_match(/ActionController::MethodNotAllowed/, body) - end + get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true} + assert_response 405 + assert_match(/ActionController::MethodNotAllowed/, body) end - test "localize public rescue message" do + test "localize rescue error page" do # Change locale old_locale, I18n.locale = I18n.locale, :da begin @app = ProductionApp - self.remote_addr = '208.77.188.166' get "/", {}, {'action_dispatch.show_exceptions' => true} assert_response 500 @@ -88,23 +83,6 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest end end - test "always rescue locally in development mode" do - @app = DevelopmentApp - self.remote_addr = '208.77.188.166' - - get "/", {}, {'action_dispatch.show_exceptions' => true} - assert_response 500 - assert_match(/puke/, body) - - get "/not_found", {}, {'action_dispatch.show_exceptions' => true} - assert_response 404 - assert_match(/#{ActionController::UnknownAction.name}/, body) - - get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true} - assert_response 405 - assert_match(/ActionController::MethodNotAllowed/, body) - end - test "does not show filtered parameters" do @app = DevelopmentApp @@ -114,16 +92,15 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest assert_match(""foo"=>"[FILTERED]"", body) end - test "show registered original exception for wrapped exceptions when consider_all_requests_local is false" do + test "show registered original exception for wrapped exceptions when show_exceptions is false" do @app = ProductionApp - self.remote_addr = '208.77.188.166' get "/not_found_original_exception", {}, {'action_dispatch.show_exceptions' => true} assert_response 404 assert_match(/404 error/, body) end - test "show registered original exception for wrapped exceptions when consider_all_requests_local is true" do + test "show registered original exception for wrapped exceptions when show_exceptions is true" do @app = DevelopmentApp get "/not_found_original_exception", {}, {'action_dispatch.show_exceptions' => true} @@ -132,7 +109,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest end test "show the controller name in the diagnostics template when controller name is present" do - @app = ProductionApp + @app = DevelopmentApp get("/runtime_error", {}, { 'action_dispatch.show_exceptions' => true, 'action_dispatch.request.parameters' => { -- cgit v1.2.3 From 5bcd119b8d9bb6d88c949956de1ce13c2673b877 Mon Sep 17 00:00:00 2001 From: lest Date: Tue, 22 Nov 2011 13:34:13 +0300 Subject: move show_detailed_exceptions? to Rescue module --- actionpack/test/controller/show_exceptions_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb index c328a42e89..39245e9574 100644 --- a/actionpack/test/controller/show_exceptions_test.rb +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -1,7 +1,7 @@ require 'abstract_unit' module ShowExceptions - class ShowExceptionsController < ActionController::Metal + class ShowExceptionsController < ActionController::Base use ActionDispatch::ShowExceptions def boom @@ -27,7 +27,7 @@ module ShowExceptions end test 'show diagnostics from a remote ip when consider_all_requests_local is true' do - Rails.stubs(:application).returns stub(:config => stub(:consider_all_requests_local => true)) + ShowExceptionsController.any_instance.stubs(:consider_all_requests_local).returns(true) @app = ShowExceptionsController.action(:boom) self.remote_addr = '208.77.188.166' get '/' -- cgit v1.2.3 From aa491f6a9c90641a2d4115420b14e45514962834 Mon Sep 17 00:00:00 2001 From: lest Date: Tue, 22 Nov 2011 16:39:07 +0300 Subject: javascript_include_tag should add '.js' to sources that contain '.' --- actionpack/test/template/sprockets_helper_test.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index db69f95130..26a504beb8 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -217,6 +217,9 @@ class SprocketsHelperTest < ActionView::TestCase assert_match %r{\n}, javascript_include_tag(:application, :debug => true) + assert_match %r{}, + javascript_include_tag('jquery.plugin', :digest => false) + @config.assets.compile = true @config.assets.debug = true assert_match %r{}, -- cgit v1.2.3 From 453f5534b4a8517c6fd39702fc98f0c6f1d5fd9e Mon Sep 17 00:00:00 2001 From: kennyj Date: Thu, 24 Nov 2011 00:10:34 +0900 Subject: Warnings removed. (ambiguous first argument) --- actionpack/test/controller/show_exceptions_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb index 39245e9574..74067cb895 100644 --- a/actionpack/test/controller/show_exceptions_test.rb +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -22,7 +22,7 @@ module ShowExceptions ['127.0.0.1', '127.0.0.127', '::1', '0:0:0:0:0:0:0:1', '0:0:0:0:0:0:0:1%0'].each do |ip_address| self.remote_addr = ip_address get '/' - assert_match /boom/, body + assert_match(/boom/, body) end end @@ -31,7 +31,7 @@ module ShowExceptions @app = ShowExceptionsController.action(:boom) self.remote_addr = '208.77.188.166' get '/' - assert_match /boom/, body + assert_match(/boom/, body) end end @@ -53,7 +53,7 @@ module ShowExceptions test 'show diagnostics message' do @app = ShowExceptionsOverridenController.action(:boom) get '/', {'detailed' => '1'} - assert_match /boom/, body + assert_match(/boom/, body) end end end -- cgit v1.2.3 From ea70e027b63a1b8bfe4087a4de978ad4eef5575b Mon Sep 17 00:00:00 2001 From: kennyj Date: Wed, 23 Nov 2011 23:49:43 +0900 Subject: Remove unreachable code, and add additional testcases. --- actionpack/test/dispatch/request/json_params_parsing_test.rb | 12 ++++++++++++ actionpack/test/dispatch/request/xml_params_parsing_test.rb | 12 ++++++++++++ 2 files changed, 24 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb index d854d55173..d481a2df13 100644 --- a/actionpack/test/dispatch/request/json_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb @@ -45,6 +45,18 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest end end + test "occurring a parse error if parsing unsuccessful" do + with_test_routing do + begin + $stderr = StringIO.new # suppress the log + json = "[\"person]\": {\"name\": \"David\"}}" + assert_raise(MultiJson::DecodeError) { post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => false} } + ensure + $stderr = STDERR + end + end + end + private def assert_parses(expected, actual, headers = {}) with_test_routing do diff --git a/actionpack/test/dispatch/request/xml_params_parsing_test.rb b/actionpack/test/dispatch/request/xml_params_parsing_test.rb index 38453dfe48..65a25557b7 100644 --- a/actionpack/test/dispatch/request/xml_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/xml_params_parsing_test.rb @@ -67,6 +67,18 @@ class XmlParamsParsingTest < ActionDispatch::IntegrationTest end end + test "occurring a parse error if parsing unsuccessful" do + with_test_routing do + begin + $stderr = StringIO.new # suppress the log + xml = "David" + assert_raise(REXML::ParseException) { post "/parse", xml, default_headers.merge('action_dispatch.show_exceptions' => false) } + ensure + $stderr = STDERR + end + end + end + test "parses multiple files" do xml = <<-end_body -- cgit v1.2.3 From fd86a1b6b068df87164d5763bdcd4a323a1e76f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 23 Nov 2011 19:06:45 +0000 Subject: Rely on a public contract between railties instead of accessing railtie methods directly. --- actionpack/test/activerecord/polymorphic_routes_test.rb | 6 ++---- actionpack/test/lib/controller/fake_models.rb | 4 ++-- actionpack/test/template/form_helper_test.rb | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb index 20d11377f6..fc829aa6b4 100644 --- a/actionpack/test/activerecord/polymorphic_routes_test.rb +++ b/actionpack/test/activerecord/polymorphic_routes_test.rb @@ -34,10 +34,8 @@ module Blog set_table_name 'projects' end - def self._railtie - o = Object.new - def o.railtie_name; "blog" end - o + def self.use_relative_model_naming? + true end end diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb index 363403092b..f2362714d7 100644 --- a/actionpack/test/lib/controller/fake_models.rb +++ b/actionpack/test/lib/controller/fake_models.rb @@ -175,8 +175,8 @@ class HashBackedAuthor < Hash end module Blog - def self._railtie - self + def self.use_relative_model_naming? + true end class Post < Struct.new(:title, :id) diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 34486bb151..ccedcd7dac 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -740,7 +740,7 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end - def test_form_for_with_isolated_namespaced_model + def test_form_for_with_model_using_relative_model_naming form_for(@blog_post) do |f| concat f.text_field :title concat f.submit('Edit post') -- cgit v1.2.3 From 98a1717e7c094d011c89ea1ed88673a595af2de8 Mon Sep 17 00:00:00 2001 From: lest Date: Wed, 23 Nov 2011 23:36:56 +0300 Subject: configuration option to always write cookie --- actionpack/test/dispatch/cookies_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb index 49da448001..3765b7eb44 100644 --- a/actionpack/test/dispatch/cookies_test.rb +++ b/actionpack/test/dispatch/cookies_test.rb @@ -210,8 +210,8 @@ class CookiesTest < ActionController::TestCase assert_equal({"user_name" => "david"}, @response.cookies) end - def test_setting_cookie_with_secure_in_development - Rails.env.stubs(:development?).returns(true) + def test_setting_cookie_with_secure_when_always_write_cookie_is_true + ActionDispatch::Cookies::CookieJar.any_instance.stubs(:always_write_cookie).returns(true) get :authenticate_with_secure assert_cookie_header "user_name=david; path=/; secure" assert_equal({"user_name" => "david"}, @response.cookies) -- cgit v1.2.3 From 7fcc8c0a1f38c77b12cb6ffe81fb2887e6c60b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 23 Nov 2011 23:45:27 +0000 Subject: Rely solely on active_model_serializer and remove the fancy constant lookup. --- actionpack/test/controller/render_json_test.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb index f886af1a95..dc09812ba3 100644 --- a/actionpack/test/controller/render_json_test.rb +++ b/actionpack/test/controller/render_json_test.rb @@ -26,8 +26,12 @@ class RenderJsonTest < ActionController::TestCase end class JsonSerializable + def initialize(skip=false) + @skip = skip + end + def active_model_serializer - JsonSerializer + JsonSerializer unless @skip end def as_json(*) @@ -89,6 +93,11 @@ class RenderJsonTest < ActionController::TestCase @current_user = Struct.new(:as_json).new(:current_user => true) render :json => JsonSerializable.new end + + def render_json_with_serializer_api_but_without_serializer + @current_user = Struct.new(:as_json).new(:current_user => true) + render :json => JsonSerializable.new(true) + end end tests TestController @@ -166,4 +175,9 @@ class RenderJsonTest < ActionController::TestCase assert_match '"scope":{"current_user":true}', @response.body assert_match '"object":{"serializable_object":true}', @response.body end + + def test_render_json_with_serializer_api_but_without_serializer + get :render_json_with_serializer_api_but_without_serializer + assert_match '{"serializable_object":true}', @response.body + end end -- cgit v1.2.3 From cd9d28d6fdff6819dac3c6643fe882eb568b5a39 Mon Sep 17 00:00:00 2001 From: lest Date: Thu, 24 Nov 2011 22:37:48 +0300 Subject: middlewares should use logger from env --- actionpack/test/abstract_unit.rb | 4 ++-- .../test/dispatch/request/json_params_parsing_test.rb | 16 ++++++---------- .../test/dispatch/request/xml_params_parsing_test.rb | 16 ++++++---------- actionpack/test/dispatch/show_exceptions_test.rb | 7 +++++++ 4 files changed, 21 insertions(+), 22 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 24d071df39..cbb8968496 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -333,9 +333,9 @@ module ActionDispatch "#{FIXTURE_LOAD_PATH}/public" end - remove_method :logger + remove_method :stderr_logger # Silence logger - def logger + def stderr_logger nil end end diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb index d481a2df13..ad44b4b16a 100644 --- a/actionpack/test/dispatch/request/json_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb @@ -32,16 +32,12 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest test "logs error if parsing unsuccessful" do with_test_routing do - begin - $stderr = StringIO.new - json = "[\"person]\": {\"name\": \"David\"}}" - post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => true} - assert_response :error - $stderr.rewind && err = $stderr.read - assert err =~ /Error occurred while parsing request parameters/ - ensure - $stderr = STDERR - end + output = StringIO.new + json = "[\"person]\": {\"name\": \"David\"}}" + post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => true, 'action_dispatch.logger' => Logger.new(output)} + assert_response :error + output.rewind && err = output.read + assert err =~ /Error occurred while parsing request parameters/ end end diff --git a/actionpack/test/dispatch/request/xml_params_parsing_test.rb b/actionpack/test/dispatch/request/xml_params_parsing_test.rb index 65a25557b7..d8fa751548 100644 --- a/actionpack/test/dispatch/request/xml_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/xml_params_parsing_test.rb @@ -54,16 +54,12 @@ class XmlParamsParsingTest < ActionDispatch::IntegrationTest test "logs error if parsing unsuccessful" do with_test_routing do - begin - $stderr = StringIO.new - xml = "David#{ActiveSupport::Base64.encode64('ABC')}" - post "/parse", xml, default_headers.merge('action_dispatch.show_exceptions' => true) - assert_response :error - $stderr.rewind && err = $stderr.read - assert err =~ /Error occurred while parsing request parameters/ - ensure - $stderr = STDERR - end + output = StringIO.new + xml = "David#{ActiveSupport::Base64.encode64('ABC')}" + post "/parse", xml, default_headers.merge('action_dispatch.show_exceptions' => true, 'action_dispatch.logger' => Logger.new(output)) + assert_response :error + output.rewind && err = output.read + assert err =~ /Error occurred while parsing request parameters/ end end diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 9f4d6c530f..5875725b5d 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -128,4 +128,11 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest get "/", {}, {'action_dispatch.show_exceptions' => true} assert_equal "text/html; charset=utf-8", response.headers["Content-Type"] end + + test 'uses logger from env' do + @app = ProductionApp + output = StringIO.new + get "/", {}, {'action_dispatch.show_exceptions' => true, 'action_dispatch.logger' => Logger.new(output)} + assert_match(/puke/, output.rewind && output.read) + end end -- cgit v1.2.3 From 0a4035b12a6c59253cb60f9e3456513c6a6a9d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Nov 2011 19:29:39 +0000 Subject: Revert the serializers API as other alternatives are now also under discussion --- actionpack/test/controller/render_json_test.rb | 48 -------------------------- 1 file changed, 48 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb index dc09812ba3..fc604a2db3 100644 --- a/actionpack/test/controller/render_json_test.rb +++ b/actionpack/test/controller/render_json_test.rb @@ -15,36 +15,9 @@ class RenderJsonTest < ActionController::TestCase end end - class JsonSerializer - def initialize(object, scope) - @object, @scope = object, scope - end - - def as_json(*) - { :object => @object.as_json, :scope => @scope.as_json } - end - end - - class JsonSerializable - def initialize(skip=false) - @skip = skip - end - - def active_model_serializer - JsonSerializer unless @skip - end - - def as_json(*) - { :serializable_object => true } - end - end - class TestController < ActionController::Base protect_from_forgery - serialization_scope :current_user - attr_reader :current_user - def self.controller_path 'test' end @@ -88,16 +61,6 @@ class RenderJsonTest < ActionController::TestCase def render_json_without_options render :json => JsonRenderable.new end - - def render_json_with_serializer - @current_user = Struct.new(:as_json).new(:current_user => true) - render :json => JsonSerializable.new - end - - def render_json_with_serializer_api_but_without_serializer - @current_user = Struct.new(:as_json).new(:current_user => true) - render :json => JsonSerializable.new(true) - end end tests TestController @@ -169,15 +132,4 @@ class RenderJsonTest < ActionController::TestCase get :render_json_without_options assert_equal '{"a":"b"}', @response.body end - - def test_render_json_with_serializer - get :render_json_with_serializer - assert_match '"scope":{"current_user":true}', @response.body - assert_match '"object":{"serializable_object":true}', @response.body - end - - def test_render_json_with_serializer_api_but_without_serializer - get :render_json_with_serializer_api_but_without_serializer - assert_match '{"serializable_object":true}', @response.body - end end -- cgit v1.2.3 From bc81ba2451a6a6c5507ad497cf838935e9d1ece2 Mon Sep 17 00:00:00 2001 From: lest Date: Sun, 27 Nov 2011 16:59:44 +0300 Subject: fix label with block in erb --- actionpack/test/fixtures/test/_label_with_block.erb | 4 ++++ actionpack/test/template/form_helper_test.rb | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 actionpack/test/fixtures/test/_label_with_block.erb (limited to 'actionpack/test') diff --git a/actionpack/test/fixtures/test/_label_with_block.erb b/actionpack/test/fixtures/test/_label_with_block.erb new file mode 100644 index 0000000000..40117e594e --- /dev/null +++ b/actionpack/test/fixtures/test/_label_with_block.erb @@ -0,0 +1,4 @@ +<%= label 'post', 'message' do %> + Message + <%= text_field 'post', 'message' %> +<% end %> diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index ccedcd7dac..0758106a40 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -230,6 +230,13 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal('', label(:post, :title) { "The title, please:" }) end + def test_label_with_block_in_erb + path = ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH) + view_paths = ActionView::PathSet.new([path]) + view = ActionView::Base.new(view_paths) + assert_equal "", view.render("test/label_with_block") + end + def test_text_field assert_dom_equal( '', text_field("post", "title") -- cgit v1.2.3 From fb8b555c490553ffe32d099303deaa37397029df Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sun, 27 Nov 2011 23:41:23 +0300 Subject: add namespace options to form_for You can provide a namespace for your form to ensure uniqueness of id attributes on form elements. The namespace attribute will be prefixed with underscore on the generate HTML id --- actionpack/test/template/form_helper_test.rb | 76 ++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 0758106a40..ad876df65d 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -935,6 +935,82 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_form_for_with_namespace + form_for(@post, :namespace => 'namespace') do |f| + concat f.text_field(:title) + concat f.text_area(:body) + concat f.check_box(:secret) + end + + expected = whole_form('/posts/123', 'namespace_edit_post_123', 'edit_post', 'put') do + "" + + "" + + "" + + "" + end + + assert_dom_equal expected, output_buffer + end + + def test_form_for_with_namespace_with_label + form_for(@post, :namespace => 'namespace') do |f| + concat f.label(:title) + concat f.text_field(:title) + end + + expected = whole_form('/posts/123', 'namespace_edit_post_123', 'edit_post', 'put') do + "" + + "" + end + + assert_dom_equal expected, output_buffer + end + + def test_two_form_for_with_namespace + form_for(@post, :namespace => 'namespace_1') do |f| + concat f.label(:title) + concat f.text_field(:title) + end + + expected_1 = whole_form('/posts/123', 'namespace_1_edit_post_123', 'edit_post', 'put') do + "" + + "" + end + + assert_dom_equal expected_1, output_buffer + + form_for(@post, :namespace => 'namespace_2') do |f| + concat f.label(:title) + concat f.text_field(:title) + end + + expected_2 = whole_form('/posts/123', 'namespace_2_edit_post_123', 'edit_post', 'put') do + "" + + "" + end + + assert_dom_equal expected_2, output_buffer + end + + def test_fields_for_with_namespace + @comment.body = 'Hello World' + form_for(@post, :namespace => 'namespace') do |f| + concat f.text_field(:title) + concat f.text_area(:body) + concat f.fields_for(@comment) { |c| + concat c.text_field(:body) + } + end + + expected = whole_form('/posts/123', 'namespace_edit_post_123', 'edit_post', 'put') do + "" + + "" + + "" + end + + assert_dom_equal expected, output_buffer + end + def test_submit_with_object_as_new_record_and_locale_strings old_locale, I18n.locale = I18n.locale, :submit -- cgit v1.2.3 From fe7d4f09ef2296e45ab4a82c1556c63382856607 Mon Sep 17 00:00:00 2001 From: lest Date: Mon, 28 Nov 2011 19:25:37 +0300 Subject: put backtrace_cleaner to env --- actionpack/test/dispatch/show_exceptions_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 5875725b5d..90f13a3bb9 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -135,4 +135,11 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest get "/", {}, {'action_dispatch.show_exceptions' => true, 'action_dispatch.logger' => Logger.new(output)} assert_match(/puke/, output.rewind && output.read) end + + test 'uses backtrace cleaner from env' do + @app = DevelopmentApp + cleaner = stub(:clean => ['passed backtrace cleaner']) + get "/", {}, {'action_dispatch.show_exceptions' => true, 'action_dispatch.backtrace_cleaner' => cleaner} + assert_match(/passed backtrace cleaner/, body) + end end -- cgit v1.2.3 From d3bc12b27feb96e8799e2bcdc6e52b2704360aa3 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Tue, 29 Nov 2011 01:59:36 -0500 Subject: Handle correctly optional parameters for callable asset_host. --- actionpack/test/template/sprockets_helper_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index 26a504beb8..64fdd53e73 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -41,6 +41,10 @@ class SprocketsHelperTest < ActionView::TestCase @controller ? @controller.config : @config end + def compute_host(source, request, options = {}) + raise "Should never get here" + end + test "asset_path" do assert_match %r{/assets/logo-[0-9a-f]+.png}, asset_path("logo.png") @@ -125,6 +129,10 @@ class SprocketsHelperTest < ActionView::TestCase assert_raises ActionController::RoutingError do asset_path("logo.png") end + @config.asset_host = method :compute_host + assert_raises ActionController::RoutingError do + asset_path("logo.png") + end end test "image_tag" do -- cgit v1.2.3 From 0b72a04d0c93b666c23500aefbe4a6a76593cd36 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 29 Nov 2011 12:28:04 +0000 Subject: Deprecate set_table_name in favour of self.table_name= or defining your own method. --- actionpack/test/activerecord/polymorphic_routes_test.rb | 16 ++++++++-------- actionpack/test/fixtures/developer.rb | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb index fc829aa6b4..90e7f4ae59 100644 --- a/actionpack/test/activerecord/polymorphic_routes_test.rb +++ b/actionpack/test/activerecord/polymorphic_routes_test.rb @@ -2,36 +2,36 @@ require 'active_record_unit' require 'fixtures/project' class Task < ActiveRecord::Base - set_table_name 'projects' + self.table_name = 'projects' end class Step < ActiveRecord::Base - set_table_name 'projects' + self.table_name = 'projects' end class Bid < ActiveRecord::Base - set_table_name 'projects' + self.table_name = 'projects' end class Tax < ActiveRecord::Base - set_table_name 'projects' + self.table_name = 'projects' end class Fax < ActiveRecord::Base - set_table_name 'projects' + self.table_name = 'projects' end class Series < ActiveRecord::Base - set_table_name 'projects' + self.table_name = 'projects' end module Blog class Post < ActiveRecord::Base - set_table_name 'projects' + self.table_name = 'projects' end class Blog < ActiveRecord::Base - set_table_name 'projects' + self.table_name = 'projects' end def self.use_relative_model_naming? diff --git a/actionpack/test/fixtures/developer.rb b/actionpack/test/fixtures/developer.rb index c70eda34c6..dd14548fac 100644 --- a/actionpack/test/fixtures/developer.rb +++ b/actionpack/test/fixtures/developer.rb @@ -5,5 +5,5 @@ class Developer < ActiveRecord::Base end class DeVeLoPeR < ActiveRecord::Base - set_table_name "developers" + self.table_name = "developers" end -- cgit v1.2.3 From 7af719e81c46d06f50cd9b3caff38b945c5f2d84 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 29 Nov 2011 16:33:50 +0000 Subject: Deprecate set_sequence_name in favour of self.sequence_name= --- actionpack/test/fixtures/company.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/fixtures/company.rb b/actionpack/test/fixtures/company.rb index cd39ea7898..e29978801e 100644 --- a/actionpack/test/fixtures/company.rb +++ b/actionpack/test/fixtures/company.rb @@ -1,10 +1,10 @@ class Company < ActiveRecord::Base has_one :mascot attr_protected :rating - set_sequence_name :companies_nonstd_seq + self.sequence_name = :companies_nonstd_seq validates_presence_of :name def validate errors.add('rating', 'rating should not be 2') if rating == 2 end -end \ No newline at end of file +end -- cgit v1.2.3 From 38ab982cfff98570b5f12933cff489364845789c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 30 Nov 2011 09:52:52 +0100 Subject: Log 'Filter chain halted as CALLBACKNAME rendered or redirected' every time a before callback halts. --- actionpack/test/controller/log_subscriber_test.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb index ccdfcb0b2c..700fd788fa 100644 --- a/actionpack/test/controller/log_subscriber_test.rb +++ b/actionpack/test/controller/log_subscriber_test.rb @@ -13,6 +13,11 @@ module Another head :status => 406 end + before_filter :redirector, :only => :never_executed + + def never_executed + end + def show render :nothing => true end @@ -49,7 +54,6 @@ module Another def with_rescued_exception raise SpecialException end - end end @@ -86,6 +90,13 @@ class ACLogSubscriberTest < ActionController::TestCase assert_equal "Processing by Another::LogSubscribersController#show as HTML", logs.first end + def test_halted_callback + get :never_executed + wait + assert_equal 4, logs.size + assert_equal "Filter chain halted as :redirector rendered or redirected", logs.third + end + def test_process_action get :show wait -- cgit v1.2.3 From e975fe710a1a78d723cfd91c07014627f92e3250 Mon Sep 17 00:00:00 2001 From: lest Date: Wed, 30 Nov 2011 17:38:09 +0300 Subject: test helpers in erb using erb --- actionpack/test/abstract_unit.rb | 8 ++++++++ .../fixtures/test/_content_tag_nested_in_content_tag.erb | 3 +++ actionpack/test/template/form_helper_test.rb | 5 ++--- actionpack/test/template/form_tag_helper_test.rb | 16 +++++++++------- actionpack/test/template/record_tag_helper_test.rb | 6 ++++-- actionpack/test/template/tag_helper_test.rb | 10 +++++----- 6 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 actionpack/test/fixtures/test/_content_tag_nested_in_content_tag.erb (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index cbb8968496..644422a6a8 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -73,6 +73,14 @@ module RackTestUtils end module RenderERBUtils + def view + @view ||= begin + path = ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH) + view_paths = ActionView::PathSet.new([path]) + ActionView::Base.new(view_paths) + end + end + def render_erb(string) template = ActionView::Template.new( string.strip, diff --git a/actionpack/test/fixtures/test/_content_tag_nested_in_content_tag.erb b/actionpack/test/fixtures/test/_content_tag_nested_in_content_tag.erb new file mode 100644 index 0000000000..2f21a75dd9 --- /dev/null +++ b/actionpack/test/fixtures/test/_content_tag_nested_in_content_tag.erb @@ -0,0 +1,3 @@ +<%= content_tag 'p' do %> + <%= content_tag 'b', 'Hello' %> +<% end %> diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index ad876df65d..3fee366804 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -3,6 +3,8 @@ require 'controller/fake_models' require 'active_support/core_ext/object/inclusion' class FormHelperTest < ActionView::TestCase + include RenderERBUtils + tests ActionView::Helpers::FormHelper def form_for(*) @@ -231,9 +233,6 @@ class FormHelperTest < ActionView::TestCase end def test_label_with_block_in_erb - path = ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH) - view_paths = ActionView::PathSet.new([path]) - view = ActionView::Base.new(view_paths) assert_equal "", view.render("test/label_with_block") end diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 6eae9bf846..233907d07a 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -2,6 +2,8 @@ require 'abstract_unit' require 'active_support/core_ext/object/inclusion' class FormTagHelperTest < ActionView::TestCase + include RenderERBUtils + tests ActionView::Helpers::FormTagHelper def setup @@ -104,14 +106,14 @@ class FormTagHelperTest < ActionView::TestCase end def test_form_tag_with_block_in_erb - output_buffer = form_tag("http://www.example.com") { concat "Hello world!" } + output_buffer = render_erb("<%= form_tag('http://www.example.com') do %>Hello world!<% end %>") expected = whole_form { "Hello world!" } assert_dom_equal expected, output_buffer end def test_form_tag_with_block_and_method_in_erb - output_buffer = form_tag("http://www.example.com", :method => :put) { concat "Hello world!" } + output_buffer = render_erb("<%= form_tag('http://www.example.com', :method => :put) do %>Hello world!<% end %>") expected = whole_form("http://www.example.com", :method => "put") do "Hello world!" @@ -485,27 +487,27 @@ class FormTagHelperTest < ActionView::TestCase end def test_field_set_tag_in_erb - output_buffer = field_set_tag("Your details") { concat "Hello world!" } + output_buffer = render_erb("<%= field_set_tag('Your details') do %>Hello world!<% end %>") expected = %(
Your detailsHello world!
) assert_dom_equal expected, output_buffer - output_buffer = field_set_tag { concat "Hello world!" } + output_buffer = render_erb("<%= field_set_tag do %>Hello world!<% end %>") expected = %(
Hello world!
) assert_dom_equal expected, output_buffer - output_buffer = field_set_tag('') { concat "Hello world!" } + output_buffer = render_erb("<%= field_set_tag('') do %>Hello world!<% end %>") expected = %(
Hello world!
) assert_dom_equal expected, output_buffer - output_buffer = field_set_tag('', :class => 'format') { concat "Hello world!" } + output_buffer = render_erb("<%= field_set_tag('', :class => 'format') do %>Hello world!<% end %>") expected = %(
Hello world!
) assert_dom_equal expected, output_buffer end - + def test_text_area_tag_options_symbolize_keys_side_effects options = { :option => "random_option" } text_area_tag "body", "hello world", options diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb index 7f23629e05..ec777d15c4 100644 --- a/actionpack/test/template/record_tag_helper_test.rb +++ b/actionpack/test/template/record_tag_helper_test.rb @@ -22,6 +22,8 @@ class Post end class RecordTagHelperTest < ActionView::TestCase + include RenderERBUtils + tests ActionView::Helpers::RecordTagHelper def setup @@ -58,13 +60,13 @@ class RecordTagHelperTest < ActionView::TestCase def test_block_works_with_content_tag_for_in_erb expected = %(#{@post.body}) - actual = content_tag_for(:tr, @post) { concat @post.body } + actual = render_erb("<%= content_tag_for(:tr, @post) do %><%= @post.body %><% end %>") assert_dom_equal expected, actual end def test_div_for_in_erb expected = %(
#{@post.body}
) - actual = div_for(@post, :class => "bar") { concat @post.body } + actual = render_erb("<%= div_for(@post, :class => 'bar') do %><%= @post.body %><% end %>") assert_dom_equal expected, actual end diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb index 60b466a9ff..6c325d5abb 100644 --- a/actionpack/test/template/tag_helper_test.rb +++ b/actionpack/test/template/tag_helper_test.rb @@ -1,6 +1,8 @@ require 'abstract_unit' class TagHelperTest < ActionView::TestCase + include RenderERBUtils + tests ActionView::Helpers::TagHelper def test_tag @@ -44,12 +46,12 @@ class TagHelperTest < ActionView::TestCase end def test_content_tag_with_block_in_erb - buffer = content_tag(:div) { concat "Hello world!" } + buffer = render_erb("<%= content_tag(:div) do %>Hello world!<% end %>") assert_dom_equal "
Hello world!
", buffer end def test_content_tag_with_block_and_options_in_erb - buffer = content_tag(:div, :class => "green") { concat "Hello world!" } + buffer = render_erb("<%= content_tag(:div, :class => 'green') do %>Hello world!<% end %>") assert_dom_equal %(
Hello world!
), buffer end @@ -68,10 +70,8 @@ class TagHelperTest < ActionView::TestCase output_buffer end - # TAG TODO: Move this into a real template def test_content_tag_nested_in_content_tag_in_erb - buffer = content_tag("p") { concat content_tag("b", "Hello") } - assert_equal '

Hello

', buffer + assert_equal "

\n Hello\n

", view.render("test/content_tag_nested_in_content_tag") end def test_content_tag_with_escaped_array_class -- cgit v1.2.3 From a985309abc8993ddc33c7a604bc41868909f457c Mon Sep 17 00:00:00 2001 From: lest Date: Wed, 30 Nov 2011 18:05:23 +0300 Subject: fix warning in tests when using render_erb helper --- 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 644422a6a8..680d562379 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -82,6 +82,8 @@ module RenderERBUtils end def render_erb(string) + @virtual_path = nil + template = ActionView::Template.new( string.strip, "test template", -- cgit v1.2.3 From 565d92f57891c1114801a27cf45ba8ee4ec02cf9 Mon Sep 17 00:00:00 2001 From: lest Date: Wed, 30 Nov 2011 18:34:16 +0300 Subject: fix method redefined warnings in tests --- actionpack/test/abstract_unit.rb | 5 +++++ actionpack/test/controller/routing_test.rb | 6 ------ actionpack/test/controller/url_for_integration_test.rb | 6 ------ 3 files changed, 5 insertions(+), 12 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 680d562379..d191a203dd 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -351,3 +351,8 @@ module ActionDispatch end end +module RoutingTestHelpers + def url_for(set, options, recall = nil) + set.send(:url_for, options.merge(:only_path => true, :_path_segments => recall)) + end +end diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 5bf68decca..4a67380f59 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -11,12 +11,6 @@ end ROUTING = ActionDispatch::Routing -module RoutingTestHelpers - def url_for(set, options, recall = nil) - set.send(:url_for, options.merge(:only_path => true, :_path_segments => recall)) - end -end - # See RFC 3986, section 3.3 for allowed path characters. class UriReservedCharactersRoutingTest < Test::Unit::TestCase include RoutingTestHelpers diff --git a/actionpack/test/controller/url_for_integration_test.rb b/actionpack/test/controller/url_for_integration_test.rb index 7b734ff0fb..451ea6027d 100644 --- a/actionpack/test/controller/url_for_integration_test.rb +++ b/actionpack/test/controller/url_for_integration_test.rb @@ -3,12 +3,6 @@ require 'abstract_unit' require 'controller/fake_controllers' require 'active_support/core_ext/object/with_options' -module RoutingTestHelpers - def url_for(set, options, recall = nil) - set.send(:url_for, options.merge(:only_path => true, :_path_segments => recall)) - end -end - module ActionPack class URLForIntegrationTest < ActiveSupport::TestCase include RoutingTestHelpers -- cgit v1.2.3 From 218c2729384be487b7b743a58ac39753cb5a8856 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 1 Dec 2011 19:09:22 +0100 Subject: Allow fresh_when/stale? to take a record instead of an options hash [DHH] --- actionpack/test/controller/render_test.rb | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index aea603b014..243bad8749 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -50,12 +50,28 @@ class TestController < ActionController::Base end end + def conditional_hello_with_record + record = Struct.new(:updated_at, :cache_key).new(Time.now.utc.beginning_of_day, "foo/123") + + if stale?(record) + render :action => 'hello_world' + end + end + def conditional_hello_with_public_header if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123], :public => true) render :action => 'hello_world' end end + def conditional_hello_with_public_header_with_record + record = Struct.new(:updated_at, :cache_key).new(Time.now.utc.beginning_of_day, "foo/123") + + if stale?(record, :public => true) + render :action => 'hello_world' + end + end + def conditional_hello_with_public_header_and_expires_at expires_in 1.minute if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123], :public => true) @@ -1440,6 +1456,36 @@ class LastModifiedRenderTest < ActionController::TestCase assert_equal @last_modified, @response.headers['Last-Modified'] end + + def test_responds_with_last_modified_with_record + get :conditional_hello_with_record + assert_equal @last_modified, @response.headers['Last-Modified'] + end + + def test_request_not_modified_with_record + @request.if_modified_since = @last_modified + get :conditional_hello_with_record + assert_equal 304, @response.status.to_i + assert_blank @response.body + assert_equal @last_modified, @response.headers['Last-Modified'] + end + + def test_request_not_modified_but_etag_differs_with_record + @request.if_modified_since = @last_modified + @request.if_none_match = "234" + get :conditional_hello_with_record + assert_response :success + end + + def test_request_modified_with_record + @request.if_modified_since = 'Thu, 16 Jul 2008 00:00:00 GMT' + get :conditional_hello_with_record + assert_equal 200, @response.status.to_i + assert_present @response.body + assert_equal @last_modified, @response.headers['Last-Modified'] + end + + def test_request_with_bang_gets_last_modified get :conditional_hello_with_bangs assert_equal @last_modified, @response.headers['Last-Modified'] -- cgit v1.2.3 From 535853e83b9092078035a5abb2aa242fba815c05 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 1 Dec 2011 19:47:14 +0100 Subject: Added ActiveRecord::Base#last_modified to work with the new fresh_when/stale? conditional get methods from Action Pack --- actionpack/test/controller/render_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 243bad8749..e014d08ec9 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -51,7 +51,7 @@ class TestController < ActionController::Base end def conditional_hello_with_record - record = Struct.new(:updated_at, :cache_key).new(Time.now.utc.beginning_of_day, "foo/123") + record = Struct.new(:last_modified, :cache_key).new(Time.now.utc.beginning_of_day, "foo/123") if stale?(record) render :action => 'hello_world' @@ -65,7 +65,7 @@ class TestController < ActionController::Base end def conditional_hello_with_public_header_with_record - record = Struct.new(:updated_at, :cache_key).new(Time.now.utc.beginning_of_day, "foo/123") + record = Struct.new(:last_modified, :cache_key).new(Time.now.utc.beginning_of_day, "foo/123") if stale?(record, :public => true) render :action => 'hello_world' -- cgit v1.2.3 From 83d29a283ceb13ff431da535e8cc35db6828016c Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 1 Dec 2011 20:45:47 +0100 Subject: Revert "Added ActiveRecord::Base#last_modified to work with the new fresh_when/stale? conditional get methods from Action Pack" Needless indirection with no added value. This reverts commit 535853e83b9092078035a5abb2aa242fba815c05. --- actionpack/test/controller/render_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index e014d08ec9..243bad8749 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -51,7 +51,7 @@ class TestController < ActionController::Base end def conditional_hello_with_record - record = Struct.new(:last_modified, :cache_key).new(Time.now.utc.beginning_of_day, "foo/123") + record = Struct.new(:updated_at, :cache_key).new(Time.now.utc.beginning_of_day, "foo/123") if stale?(record) render :action => 'hello_world' @@ -65,7 +65,7 @@ class TestController < ActionController::Base end def conditional_hello_with_public_header_with_record - record = Struct.new(:last_modified, :cache_key).new(Time.now.utc.beginning_of_day, "foo/123") + record = Struct.new(:updated_at, :cache_key).new(Time.now.utc.beginning_of_day, "foo/123") if stale?(record, :public => true) render :action => 'hello_world' -- cgit v1.2.3 From 750bb5c865ac9234da91ec451eec7d9de55b8f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 1 Dec 2011 20:46:18 +0100 Subject: Split ShowExceptions responsibilities in two middlewares. --- actionpack/test/abstract_unit.rb | 22 +++++++++++++--------- actionpack/test/controller/show_exceptions_test.rb | 1 + actionpack/test/dispatch/show_exceptions_test.rb | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index d191a203dd..c95b8221a1 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -175,6 +175,7 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase def self.build_app(routes = nil) RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware| middleware.use "ActionDispatch::ShowExceptions" + middleware.use "ActionDispatch::DebugExceptions" middleware.use "ActionDispatch::Callbacks" middleware.use "ActionDispatch::ParamsParser" middleware.use "ActionDispatch::Cookies" @@ -338,16 +339,19 @@ end module ActionDispatch class ShowExceptions private - remove_method :public_path - def public_path - "#{FIXTURE_LOAD_PATH}/public" - end + remove_method :public_path + def public_path + "#{FIXTURE_LOAD_PATH}/public" + end + end - remove_method :stderr_logger - # Silence logger - def stderr_logger - nil - end + class DebugExceptions + private + remove_method :stderr_logger + # Silence logger + def stderr_logger + nil + end end end diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb index 74067cb895..5eff1eb09d 100644 --- a/actionpack/test/controller/show_exceptions_test.rb +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -3,6 +3,7 @@ require 'abstract_unit' module ShowExceptions class ShowExceptionsController < ActionController::Base use ActionDispatch::ShowExceptions + use ActionDispatch::DebugExceptions def boom raise 'boom!' diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 90f13a3bb9..4f1140b5d3 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -29,8 +29,8 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest end end - ProductionApp = ActionDispatch::ShowExceptions.new(Boomer.new(false)) - DevelopmentApp = ActionDispatch::ShowExceptions.new(Boomer.new(true)) + ProductionApp = ActionDispatch::ShowExceptions.new(ActionDispatch::DebugExceptions.new(Boomer.new(false))) + DevelopmentApp = ActionDispatch::ShowExceptions.new(ActionDispatch::DebugExceptions.new(Boomer.new(true))) test "rescue with error page when show_exceptions is false" do @app = ProductionApp -- cgit v1.2.3 From f9edc079e030a5d2b0f21b80d6382caf10751057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 1 Dec 2011 21:15:42 +0100 Subject: Split and improve show and debug exceptions middlewares. --- actionpack/test/dispatch/debug_exceptions_test.rb | 116 ++++++++++++++++++++++ actionpack/test/dispatch/show_exceptions_test.rb | 90 +++-------------- 2 files changed, 130 insertions(+), 76 deletions(-) create mode 100644 actionpack/test/dispatch/debug_exceptions_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb new file mode 100644 index 0000000000..e6c0a06878 --- /dev/null +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -0,0 +1,116 @@ +require 'abstract_unit' + +class DebugExceptionsTest < ActionDispatch::IntegrationTest + + class Boomer + def initialize(detailed = false) + @detailed = detailed + end + + def call(env) + env['action_dispatch.show_detailed_exceptions'] = @detailed + req = ActionDispatch::Request.new(env) + case req.path + when "/not_found" + raise ActionController::UnknownAction + when "/runtime_error" + raise RuntimeError + when "/method_not_allowed" + raise ActionController::MethodNotAllowed + when "/not_implemented" + raise ActionController::NotImplemented + when "/unprocessable_entity" + raise ActionController::InvalidAuthenticityToken + when "/not_found_original_exception" + raise ActionView::Template::Error.new('template', {}, AbstractController::ActionNotFound.new) + else + raise "puke!" + end + end + end + + ProductionApp = ActionDispatch::DebugExceptions.new((Boomer.new(false))) + DevelopmentApp = ActionDispatch::DebugExceptions.new((Boomer.new(true))) + + test 'skip diagnosis if not showing detailed exceptions' do + @app = ProductionApp + assert_raise RuntimeError do + get "/", {}, {'action_dispatch.show_exceptions' => true} + end + end + + test 'skip diagnosis if not showing exceptions' do + @app = DevelopmentApp + assert_raise RuntimeError do + get "/", {}, {'action_dispatch.show_exceptions' => false} + end + end + + test "rescue with diagnostics message" do + @app = DevelopmentApp + + get "/", {}, {'action_dispatch.show_exceptions' => true} + assert_response 500 + assert_match(/puke/, body) + + get "/not_found", {}, {'action_dispatch.show_exceptions' => true} + assert_response 404 + assert_match(/#{ActionController::UnknownAction.name}/, body) + + get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true} + assert_response 405 + assert_match(/ActionController::MethodNotAllowed/, body) + end + + test "does not show filtered parameters" do + @app = DevelopmentApp + + get "/", {"foo"=>"bar"}, {'action_dispatch.show_exceptions' => true, + 'action_dispatch.parameter_filter' => [:foo]} + assert_response 500 + assert_match(""foo"=>"[FILTERED]"", body) + end + + test "show registered original exception for wrapped exceptions" do + @app = DevelopmentApp + + get "/not_found_original_exception", {}, {'action_dispatch.show_exceptions' => true} + assert_response 404 + assert_match(/AbstractController::ActionNotFound/, body) + end + + test "show the controller name in the diagnostics template when controller name is present" do + @app = DevelopmentApp + get("/runtime_error", {}, { + 'action_dispatch.show_exceptions' => true, + 'action_dispatch.request.parameters' => { + 'action' => 'show', + 'id' => 'unknown', + 'controller' => 'featured_tile' + } + }) + assert_response 500 + assert_match(/RuntimeError\n in FeaturedTileController/, body) + end + + test "sets the HTTP charset parameter" do + @app = DevelopmentApp + + get "/", {}, {'action_dispatch.show_exceptions' => true} + assert_equal "text/html; charset=utf-8", response.headers["Content-Type"] + end + + test 'uses logger from env' do + @app = DevelopmentApp + output = StringIO.new + get "/", {}, {'action_dispatch.show_exceptions' => true, 'action_dispatch.logger' => Logger.new(output)} + assert_match(/puke/, output.rewind && output.read) + end + + test 'uses backtrace cleaner from env' do + @app = DevelopmentApp + cleaner = stub(:clean => ['passed backtrace cleaner']) + get "/", {}, {'action_dispatch.show_exceptions' => true, 'action_dispatch.backtrace_cleaner' => cleaner} + assert_match(/passed backtrace cleaner/, body) + end +end diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 4f1140b5d3..a34f6f1888 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -13,14 +13,8 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest case req.path when "/not_found" raise ActionController::UnknownAction - when "/runtime_error" - raise RuntimeError when "/method_not_allowed" raise ActionController::MethodNotAllowed - when "/not_implemented" - raise ActionController::NotImplemented - when "/unprocessable_entity" - raise ActionController::InvalidAuthenticityToken when "/not_found_original_exception" raise ActionView::Template::Error.new('template', {}, AbstractController::ActionNotFound.new) else @@ -29,10 +23,16 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest end end - ProductionApp = ActionDispatch::ShowExceptions.new(ActionDispatch::DebugExceptions.new(Boomer.new(false))) - DevelopmentApp = ActionDispatch::ShowExceptions.new(ActionDispatch::DebugExceptions.new(Boomer.new(true))) + ProductionApp = ActionDispatch::ShowExceptions.new((Boomer.new(false))) - test "rescue with error page when show_exceptions is false" do + test 'skip diagnosis if not showing exceptions' do + @app = ProductionApp + assert_raise RuntimeError do + get "/", {}, {'action_dispatch.show_exceptions' => false} + end + end + + test "rescue with error page" do @app = ProductionApp get "/", {}, {'action_dispatch.show_exceptions' => true} @@ -48,24 +48,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest assert_equal "", body end - test "rescue with diagnostics message when show_exceptions is true" do - @app = DevelopmentApp - - get "/", {}, {'action_dispatch.show_exceptions' => true} - assert_response 500 - assert_match(/puke/, body) - - get "/not_found", {}, {'action_dispatch.show_exceptions' => true} - assert_response 404 - assert_match(/#{ActionController::UnknownAction.name}/, body) - - get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true} - assert_response 405 - assert_match(/ActionController::MethodNotAllowed/, body) - end - test "localize rescue error page" do - # Change locale old_locale, I18n.locale = I18n.locale, :da begin @@ -83,63 +66,18 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest end end - test "does not show filtered parameters" do - @app = DevelopmentApp - - get "/", {"foo"=>"bar"}, {'action_dispatch.show_exceptions' => true, - 'action_dispatch.parameter_filter' => [:foo]} - assert_response 500 - assert_match(""foo"=>"[FILTERED]"", body) - end - - test "show registered original exception for wrapped exceptions when show_exceptions is false" do - @app = ProductionApp - - get "/not_found_original_exception", {}, {'action_dispatch.show_exceptions' => true} - assert_response 404 - assert_match(/404 error/, body) - end - - test "show registered original exception for wrapped exceptions when show_exceptions is true" do - @app = DevelopmentApp - - get "/not_found_original_exception", {}, {'action_dispatch.show_exceptions' => true} - assert_response 404 - assert_match(/AbstractController::ActionNotFound/, body) - end - - test "show the controller name in the diagnostics template when controller name is present" do - @app = DevelopmentApp - get("/runtime_error", {}, { - 'action_dispatch.show_exceptions' => true, - 'action_dispatch.request.parameters' => { - 'action' => 'show', - 'id' => 'unknown', - 'controller' => 'featured_tile' - } - }) - assert_response 500 - assert_match(/RuntimeError\n in FeaturedTileController/, body) - end - test "sets the HTTP charset parameter" do - @app = DevelopmentApp + @app = ProductionApp get "/", {}, {'action_dispatch.show_exceptions' => true} assert_equal "text/html; charset=utf-8", response.headers["Content-Type"] end - test 'uses logger from env' do + test "show registered original exception for wrapped exceptions" do @app = ProductionApp - output = StringIO.new - get "/", {}, {'action_dispatch.show_exceptions' => true, 'action_dispatch.logger' => Logger.new(output)} - assert_match(/puke/, output.rewind && output.read) - end - test 'uses backtrace cleaner from env' do - @app = DevelopmentApp - cleaner = stub(:clean => ['passed backtrace cleaner']) - get "/", {}, {'action_dispatch.show_exceptions' => true, 'action_dispatch.backtrace_cleaner' => cleaner} - assert_match(/passed backtrace cleaner/, body) + get "/not_found_original_exception", {}, {'action_dispatch.show_exceptions' => true} + assert_response 404 + assert_match(/404 error/, body) end end -- cgit v1.2.3 From 6a4606d3a64e60189ea4ba5243830dcd97e6de14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 1 Dec 2011 21:17:11 +0100 Subject: Remove unnecessary test setup. --- actionpack/test/dispatch/show_exceptions_test.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index a34f6f1888..020cc80f3f 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -3,12 +3,7 @@ require 'abstract_unit' class ShowExceptionsTest < ActionDispatch::IntegrationTest class Boomer - def initialize(detailed = false) - @detailed = detailed - end - def call(env) - env['action_dispatch.show_detailed_exceptions'] = @detailed req = ActionDispatch::Request.new(env) case req.path when "/not_found" @@ -23,7 +18,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest end end - ProductionApp = ActionDispatch::ShowExceptions.new((Boomer.new(false))) + ProductionApp = ActionDispatch::ShowExceptions.new(Boomer.new) test 'skip diagnosis if not showing exceptions' do @app = ProductionApp -- cgit v1.2.3 From 2ab2077235308aaa82dc430f1da8d6519fb7dac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 3 Dec 2011 11:38:25 +0100 Subject: Fix failing cascade exception. --- actionpack/test/dispatch/debug_exceptions_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index e6c0a06878..f7411c7729 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -11,6 +11,8 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest env['action_dispatch.show_detailed_exceptions'] = @detailed req = ActionDispatch::Request.new(env) case req.path + when "/pass" + [404, { "X-Cascade" => "pass" }, []] when "/not_found" raise ActionController::UnknownAction when "/runtime_error" @@ -46,6 +48,13 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end end + test 'raise an exception on cascade pass' do + @app = ProductionApp + assert_raise ActionController::RoutingError do + get "/pass", {}, {'action_dispatch.show_exceptions' => true} + end + end + test "rescue with diagnostics message" do @app = DevelopmentApp -- cgit v1.2.3 From e29773f885fd500189ffd964550ae20061d745ba Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sun, 4 Dec 2011 22:12:24 +0300 Subject: form_for with +:as+ option uses "action_as" as css class and id --- actionpack/test/template/form_helper_test.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 3fee366804..41e925b000 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -769,7 +769,7 @@ class FormHelperTest < ActionView::TestCase concat f.submit('Create post') end - expected = whole_form("/posts/123", "create-post", "other_name_edit", :method => "put") do + expected = whole_form("/posts/123", "create-post", "edit_other_name", :method => "put") do "" + "" + "" + @@ -906,7 +906,7 @@ class FormHelperTest < ActionView::TestCase concat f.check_box(:secret) end - expected = whole_form('/posts/123', 'post[]_edit', 'post[]_edit', 'put') do + expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'put') do "" + "" + "" + @@ -924,7 +924,7 @@ class FormHelperTest < ActionView::TestCase concat f.check_box(:secret) end - expected = whole_form('/posts/123', 'post[]_edit', 'post[]_edit', 'put') do + expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'put') do "" + "" + "" + @@ -1066,7 +1066,7 @@ class FormHelperTest < ActionView::TestCase concat f.submit end - expected = whole_form('/posts/123', 'another_post_edit', 'another_post_edit', :method => 'put') do + expected = whole_form('/posts/123', 'edit_another_post', 'edit_another_post', :method => 'put') do "" end @@ -1098,7 +1098,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'post[]_edit', 'post[]_edit', 'put') do + expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'put') do "" + "" end @@ -1157,7 +1157,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'post[]_edit', 'post[]_edit', 'put') do + expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'put') do "" end @@ -1185,7 +1185,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'post[]_edit', 'post[]_edit', 'put') do + expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'put') do "" end @@ -1205,9 +1205,9 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'post[]_edit', 'post[]_edit', 'put') do + expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'put') do "" - end + whole_form('/posts/123', 'post_edit', 'post_edit', 'put') do + end + whole_form('/posts/123', 'edit_post', 'edit_post', 'put') do "" end @@ -1860,7 +1860,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'create-post', 'post_edit', :method => 'put') do + expected = whole_form('/posts/123', 'create-post', 'edit_post', :method => 'put') do "" + "" + "" + @@ -1880,7 +1880,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'create-post', 'post_edit', :method => 'put') do + expected = whole_form('/posts/123', 'create-post', 'edit_post', :method => 'put') do "" + "" + "" -- cgit v1.2.3 From e31c4ace97638d186aae389dd2cbe3b5786beb57 Mon Sep 17 00:00:00 2001 From: Overbryd Date: Mon, 5 Dec 2011 11:14:21 +0100 Subject: Fix for redirect_to to respect urls with a network path reference like "//asset.host.com/resources/1235" see issue #3856 --- actionpack/test/controller/redirect_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 79041055bd..5b739e49ac 100644 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -70,6 +70,10 @@ class RedirectController < ActionController::Base redirect_to "x-test+scheme.complex:redirect" end + def redirect_to_url_with_network_path_reference + redirect_to "//www.rubyonrails.org/" + end + def redirect_to_back redirect_to :back end @@ -216,6 +220,12 @@ class RedirectTest < ActionController::TestCase assert_equal "x-test+scheme.complex:redirect", redirect_to_url end + def test_redirect_to_url_with_network_path_reference + get :redirect_to_url_with_network_path_reference + assert_response :redirect + assert_equal "//www.rubyonrails.org/", redirect_to_url + end + def test_redirect_to_back @request.env["HTTP_REFERER"] = "http://www.example.com/coming/from" get :redirect_to_back -- cgit v1.2.3 From 71d769e3b58cb56b4b1d5143936c65be8b27c490 Mon Sep 17 00:00:00 2001 From: Andy Jeffries Date: Mon, 5 Dec 2011 15:41:38 +0000 Subject: Named Routes shouldn't override existing ones (currently route recognition goes with the earliest match, named routes use the latest match) --- actionpack/test/controller/routing_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 4a67380f59..062fc1f94e 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -713,12 +713,12 @@ class RouteSetTest < ActiveSupport::TestCase assert_equal set.routes.first, set.named_routes[:hello] end - def test_later_named_routes_take_precedence + def test_earlier_named_routes_take_precedence set.draw do match '/hello/world' => 'a#b', :as => 'hello' match '/hello' => 'a#b', :as => 'hello' end - assert_equal set.routes.last, set.named_routes[:hello] + assert_equal set.routes.first, set.named_routes[:hello] end def setup_named_route_test -- cgit v1.2.3 From 1f0e21ce3037b03a125229810d584db77c0c6ed4 Mon Sep 17 00:00:00 2001 From: lest Date: Mon, 5 Dec 2011 19:05:03 +0300 Subject: use classify in ParamsWrapper to derive model name from controller name --- actionpack/test/controller/params_wrapper_test.rb | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb index 7bef1e8d5d..0102f66dfe 100644 --- a/actionpack/test/controller/params_wrapper_test.rb +++ b/actionpack/test/controller/params_wrapper_test.rb @@ -285,3 +285,38 @@ class AnonymousControllerParamsWrapperTest < ActionController::TestCase end end end + +class IrregularInflectionParamsWrapperTest < ActionController::TestCase + include ParamsWrapperTestHelp + + class ParamswrappernewsItem + def self.attribute_names + ['test_attr'] + end + end + + class ParamswrappernewsController < ActionController::Base + class << self + attr_accessor :last_parameters + end + + def parse + self.class.last_parameters = request.params.except(:controller, :action) + head :ok + end + end + + tests ParamswrappernewsController + + def test_uses_model_attribute_names_with_irregular_inflection + ActiveSupport::Inflector.inflections do |inflect| + inflect.irregular 'paramswrappernews_item', 'paramswrappernews' + end + + with_default_wrapper_options do + @request.env['CONTENT_TYPE'] = 'application/json' + post :parse, { 'username' => 'sikachu', 'test_attr' => 'test_value' } + assert_parameters({ 'username' => 'sikachu', 'test_attr' => 'test_value', 'paramswrappernews_item' => { 'test_attr' => 'test_value' }}) + end + end +end -- cgit v1.2.3 From 25007ad3fb3eac28a5f7ad3f6cd26eb33e14b4e0 Mon Sep 17 00:00:00 2001 From: Adrian Pike Date: Mon, 24 Oct 2011 15:57:14 -0700 Subject: Let's do the same trick for asset_path that we do for [image,javascript,stylesheet]_path to avoid namespace conflicts on named routes. Closes #3427 --- .../template/sprockets_helper_with_routes_test.rb | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 actionpack/test/template/sprockets_helper_with_routes_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/template/sprockets_helper_with_routes_test.rb b/actionpack/test/template/sprockets_helper_with_routes_test.rb new file mode 100644 index 0000000000..bcbd81a7dd --- /dev/null +++ b/actionpack/test/template/sprockets_helper_with_routes_test.rb @@ -0,0 +1,57 @@ +require 'abstract_unit' +require 'sprockets' +require 'sprockets/helpers/rails_helper' +require 'mocha' + +class SprocketsHelperWithRoutesTest < ActionView::TestCase + include Sprockets::Helpers::RailsHelper + + # Let's bring in some named routes to test namespace conflicts with potential *_paths. + # We have to do this after we bring in the Sprockets RailsHelper so if there are conflicts, + # they'll fail in the way we expect in a real live Rails app. + routes = ActionDispatch::Routing::RouteSet.new + routes.draw do + resources :assets + end + include routes.url_helpers + + def setup + super + @controller = BasicController.new + + @assets = Sprockets::Environment.new + @assets.append_path(FIXTURES.join("sprockets/app/javascripts")) + @assets.append_path(FIXTURES.join("sprockets/app/stylesheets")) + @assets.append_path(FIXTURES.join("sprockets/app/images")) + + application = Struct.new(:config, :assets).new(config, @assets) + Rails.stubs(:application).returns(application) + @config = config + @config.perform_caching = true + @config.assets.digest = true + @config.assets.compile = true + end + + test "namespace conflicts on a named route called asset_path" do + # Testing this for sanity - asset_path is now a named route! + assert_match asset_path('test_asset'), '/assets/test_asset' + + assert_match %r{/assets/logo-[0-9a-f]+.png}, + path_to_asset("logo.png") + assert_match %r{/assets/logo-[0-9a-f]+.png}, + path_to_asset("logo.png", :digest => true) + assert_match %r{/assets/logo.png}, + path_to_asset("logo.png", :digest => false) + end + + test "javascript_include_tag with a named_route named asset_path" do + assert_match %r{}, + javascript_include_tag(:application) + end + + test "stylesheet_link_tag with a named_route named asset_path" do + assert_match %r{}, + stylesheet_link_tag(:application) + end + +end \ No newline at end of file -- cgit v1.2.3 From 0da31a1839d03e597f8ce0ae853b3a75519f325a Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 6 Dec 2011 13:05:15 +0100 Subject: Allowing string as url argument for expire_action --- actionpack/test/controller/caching_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 2364bbf3a3..015e6b9955 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -251,6 +251,11 @@ class ActionCachingTestController < CachingController expire_action :controller => 'action_caching_test', :action => 'index', :format => 'xml' render :nothing => true end + + def expire_with_url_string + expire_action url_for(:controller => 'action_caching_test', :action => 'index') + render :nothing => true + end end class MockTime < Time @@ -445,6 +450,21 @@ class ActionCacheTest < ActionController::TestCase assert_not_equal cached_time, @response.body end + def test_cache_expiration_with_url_string + get :index + cached_time = content_to_cache + reset! + + @request.request_uri = "/action_caching_test/expire_with_url_string" + get :expire_with_url_string + assert_response :success + reset! + + get :index + assert_response :success + assert_not_equal cached_time, @response.body + end + def test_cache_is_scoped_by_subdomain @request.host = 'jamis.hostname.com' get :index -- cgit v1.2.3 From 0460b3a46920ccf7d70d6699a3da06ca9663c1f6 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Fri, 2 Dec 2011 13:13:36 -0500 Subject: Fix bug in assert_template when using only `:layout` option Currently if you're do this: assert_template :layout => "foo" Regardless of what layout you were using, the test will always pass. This was broken since the introduction of :layout option in [d9375f3f]. We have a lot of test cases in actionpack/test/controller/layout_test.rb that use this feature. This will make sure that those test cases are not true negative. --- .../test/controller/action_pack_assertions_test.rb | 16 ++++++++++++++++ actionpack/test/controller/layout_test.rb | 2 +- 2 files changed, 17 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 a714e8bbcc..b414327d08 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -71,6 +71,10 @@ class ActionPackAssertionsController < ActionController::Base render :text => "Hello!", :content_type => Mime::RSS end + def render_with_layout + render "test/hello_world", :layout => "layouts/standard" + end + def session_stuffing session['xmas'] = 'turkey' render :text => "ho ho ho" @@ -471,6 +475,18 @@ class AssertTemplateTest < ActionController::TestCase end end + def test_fails_with_wrong_layout + get :render_with_layout + assert_raise(ActiveSupport::TestCase::Assertion) do + assert_template :layout => "application" + end + end + + def test_passes_with_correct_layout + get :render_with_layout + assert_template :layout => "layouts/standard" + end + def test_assert_template_reset_between_requests get :hello_world assert_template 'test/hello_world' diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index 25299eb8b8..bc171e201b 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -167,7 +167,7 @@ class LayoutSetInResponseTest < ActionController::TestCase def test_layout_is_picked_from_the_controller_instances_view_path @controller = PrependsViewPathController.new get :hello - assert_template :layout => /layouts\/alt\.\w+/ + assert_template :layout => /layouts\/alt/ end def test_absolute_pathed_layout -- cgit v1.2.3 From 18ceed201b37d91ad6598d0f8b3c010e6cc48b15 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Tue, 6 Dec 2011 21:05:56 -0500 Subject: Allow layout fallback when using `layout` method Rails will now use your default layout (such as "layouts/application") when you specify a layout with `:only` and `:except` condition, and those conditions fail. For example, consider this snippet: class CarsController layout 'single_car', :only => :show end Rails will use 'layouts/single_car' when a request comes in `:show` action, and use 'layouts/application' (or 'layouts/cars', if exists) when a request comes in for any other actions. --- actionpack/test/abstract/layouts_test.rb | 50 +++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb index 86208899f8..a5382a730d 100644 --- a/actionpack/test/abstract/layouts_test.rb +++ b/actionpack/test/abstract/layouts_test.rb @@ -141,6 +141,30 @@ module AbstractControllerTests end end + class WithOnlyConditional < WithStringImpliedChild + layout "overwrite", :only => :show + + def index + render :template => ActionView::Template::Text.new("Hello index!") + end + + def show + render :template => ActionView::Template::Text.new("Hello show!") + end + end + + class WithExceptConditional < WithStringImpliedChild + layout "overwrite", :except => :show + + def index + render :template => ActionView::Template::Text.new("Hello index!") + end + + def show + render :template => ActionView::Template::Text.new("Hello show!") + end + end + class TestBase < ActiveSupport::TestCase test "when no layout is specified, and no default is available, render without a layout" do controller = Blank.new @@ -260,6 +284,30 @@ module AbstractControllerTests end end end + + test "when specify an :only option which match current action name" do + controller = WithOnlyConditional.new + controller.process(:show) + assert_equal "Overwrite Hello show!", controller.response_body + end + + test "when specify an :only option which does not match current action name" do + controller = WithOnlyConditional.new + controller.process(:index) + assert_equal "With Implied Hello index!", controller.response_body + end + + test "when specify an :except option which match current action name" do + controller = WithExceptConditional.new + controller.process(:show) + assert_equal "With Implied Hello show!", controller.response_body + end + + test "when specify an :except option which does not match current action name" do + controller = WithExceptConditional.new + controller.process(:index) + assert_equal "Overwrite Hello index!", controller.response_body + end end end -end \ No newline at end of file +end -- cgit v1.2.3 From a1986e7d55bed6895cab3d8b490f769d7abe727b Mon Sep 17 00:00:00 2001 From: kennyj Date: Wed, 7 Dec 2011 01:46:41 +0900 Subject: Use default charset when we read content type without charset. --- actionpack/test/dispatch/response_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 5abbaf74fe..337ece6b88 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -130,6 +130,17 @@ class ResponseTest < ActiveSupport::TestCase assert_equal('application/xml; charset=utf-16', resp.headers['Content-Type']) end + + test "read content type without charset" do + original = ActionDispatch::Response.default_charset + begin + ActionDispatch::Response.default_charset = 'utf-16' + resp = ActionDispatch::Response.new(200, { "Content-Type" => "text/xml" }) + assert_equal('utf-16', resp.charset) + ensure + ActionDispatch::Response.default_charset = original + end + end end class ResponseIntegrationTest < ActionDispatch::IntegrationTest -- cgit v1.2.3 From d5526218e43072a3b9b4a55568f4b29b3a2c0445 Mon Sep 17 00:00:00 2001 From: Jean-Francois Turcot Date: Wed, 7 Dec 2011 22:50:01 -0500 Subject: ParamsWrapper only wrap the accessible attributes when they were set --- actionpack/test/controller/params_wrapper_test.rb | 29 ++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb index 0102f66dfe..a4c6c08abb 100644 --- a/actionpack/test/controller/params_wrapper_test.rb +++ b/actionpack/test/controller/params_wrapper_test.rb @@ -26,7 +26,7 @@ class ParamsWrapperTest < ActionController::TestCase self.class.last_parameters = request.params.except(:controller, :action) head :ok end - end +end class User; end class Person; end @@ -147,6 +147,7 @@ class ParamsWrapperTest < ActionController::TestCase end def test_derived_wrapped_keys_from_matching_model + User.expects(:respond_to?).with(:accessible_attributes).returns(false) User.expects(:respond_to?).with(:attribute_names).returns(true) User.expects(:attribute_names).twice.returns(["username"]) @@ -159,6 +160,7 @@ class ParamsWrapperTest < ActionController::TestCase def test_derived_wrapped_keys_from_specified_model with_default_wrapper_options do + Person.expects(:respond_to?).with(:accessible_attributes).returns(false) Person.expects(:respond_to?).with(:attribute_names).returns(true) Person.expects(:attribute_names).twice.returns(["username"]) @@ -169,8 +171,33 @@ class ParamsWrapperTest < ActionController::TestCase assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'person' => { 'username' => 'sikachu' }}) end end + + def test_accessible_wrapped_keys_from_matching_model + User.expects(:respond_to?).with(:accessible_attributes).returns(true) + User.expects(:accessible_attributes).twice.returns(["username"]) + + with_default_wrapper_options do + @request.env['CONTENT_TYPE'] = 'application/json' + post :parse, { 'username' => 'sikachu', 'title' => 'Developer' } + assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'user' => { 'username' => 'sikachu' }}) + end + end + + def test_accessible_wrapped_keys_from_specified_model + with_default_wrapper_options do + Person.expects(:respond_to?).with(:accessible_attributes).returns(true) + Person.expects(:accessible_attributes).twice.returns(["username"]) + + UsersController.wrap_parameters Person + + @request.env['CONTENT_TYPE'] = 'application/json' + post :parse, { 'username' => 'sikachu', 'title' => 'Developer' } + assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'person' => { 'username' => 'sikachu' }}) + end + end def test_not_wrapping_abstract_model + User.expects(:respond_to?).with(:accessible_attributes).returns(false) User.expects(:respond_to?).with(:attribute_names).returns(true) User.expects(:attribute_names).returns([]) -- cgit v1.2.3 From 3ade2f8e8950d9e7edf451627ca52ab96d630077 Mon Sep 17 00:00:00 2001 From: kennyj Date: Thu, 8 Dec 2011 23:09:09 +0900 Subject: Fix warning for params_wrapper_test. --- actionpack/test/controller/params_wrapper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb index a4c6c08abb..c4d2614200 100644 --- a/actionpack/test/controller/params_wrapper_test.rb +++ b/actionpack/test/controller/params_wrapper_test.rb @@ -26,7 +26,7 @@ class ParamsWrapperTest < ActionController::TestCase self.class.last_parameters = request.params.except(:controller, :action) head :ok end -end + end class User; end class Person; end -- cgit v1.2.3 From ebd71fd0e39abf495bdf64e3e6d278340c17e5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 8 Dec 2011 20:59:43 +0100 Subject: Fix a regression and also fix broken test. --- actionpack/test/controller/new_base/render_layout_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/new_base/render_layout_test.rb b/actionpack/test/controller/new_base/render_layout_test.rb index d3dcb5cad6..73c2d8244a 100644 --- a/actionpack/test/controller/new_base/render_layout_test.rb +++ b/actionpack/test/controller/new_base/render_layout_test.rb @@ -71,7 +71,8 @@ module ControllerLayouts self.view_paths = [ActionView::FixtureResolver.new( "layouts/application.html.erb" => "<%= yield %>", "controller_layouts/mismatch_format/index.xml.builder" => "xml.instruct!", - "controller_layouts/mismatch_format/implicit.builder" => "xml.instruct!" + "controller_layouts/mismatch_format/implicit.builder" => "xml.instruct!", + "controller_layouts/mismatch_format/explicit.js.erb" => "alert('foo');" )] def explicit @@ -94,10 +95,9 @@ module ControllerLayouts assert_response XML_INSTRUCT end - test "if an HTML template is explicitly provides for a JS template, an error is raised" do - assert_raises ActionView::MissingTemplate do - get :explicit, {}, "action_dispatch.show_exceptions" => false - end + test "a layout for JS is ignored even if explicitly provided for HTML" do + get :explicit, { :format => "js" } + assert_response "alert('foo');" end end end -- cgit v1.2.3 From d4d99bbc87021fad1df516cb24912973d186279d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 8 Dec 2011 22:56:50 +0100 Subject: Fix another regression related to the layout optimization. --- .../test/controller/new_base/render_layout_test.rb | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/new_base/render_layout_test.rb b/actionpack/test/controller/new_base/render_layout_test.rb index 73c2d8244a..4ac40ca405 100644 --- a/actionpack/test/controller/new_base/render_layout_test.rb +++ b/actionpack/test/controller/new_base/render_layout_test.rb @@ -82,7 +82,7 @@ module ControllerLayouts class MismatchFormatTest < Rack::TestCase testing ControllerLayouts::MismatchFormatController - + XML_INSTRUCT = %Q(\n) test "if XML is selected, an HTML template is not also selected" do @@ -100,4 +100,28 @@ module ControllerLayouts assert_response "alert('foo');" end end + + class FalseLayoutMethodController < ::ApplicationController + self.view_paths = [ActionView::FixtureResolver.new( + "controller_layouts/false_layout_method/index.js.erb" => "alert('foo');" + )] + + layout :which_layout? + + def which_layout? + false + end + + def index + end + end + + class FalseLayoutMethodTest < Rack::TestCase + testing ControllerLayouts::FalseLayoutMethodController + + test "access false layout returned by a method/proc" do + get :index, :format => "js" + assert_response "alert('foo');" + end + end end -- cgit v1.2.3 From 2c471b3ac805b00ac1423f7ae2be1554aca0db9f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 8 Dec 2011 15:11:23 -0800 Subject: load the encoding converter to work around [ruby-core:41556] when switching encodings --- actionpack/test/template/template_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 70ca876c67..fe82504d3b 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -170,6 +170,7 @@ class TestERBTemplate < ActiveSupport::TestCase def with_external_encoding(encoding) old = Encoding.default_external + Encoding::Converter.new old, encoding silence_warnings { Encoding.default_external = encoding } yield ensure -- cgit v1.2.3 From 5ad52152117ecda1166359c499bcd03ae6be3365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 9 Dec 2011 07:20:55 +0100 Subject: Deprecate implicit layout lookup in favor of inheriting the _layout config. --- actionpack/test/abstract/layouts_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb index a5382a730d..de6f42d826 100644 --- a/actionpack/test/abstract/layouts_test.rb +++ b/actionpack/test/abstract/layouts_test.rb @@ -258,7 +258,7 @@ module AbstractControllerTests 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_deprecated { controller.process(:index) } assert_equal "With Implied Hello string!", controller.response_body end @@ -271,7 +271,7 @@ module AbstractControllerTests 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_deprecated { controller.process(:index) } assert_equal "With Implied Hello string!", controller.response_body end -- cgit v1.2.3 From c212a34e1d1e2a4bfb546a664958aba168892c49 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 9 Dec 2011 09:33:36 -0800 Subject: only load converter if the encodings are different --- actionpack/test/template/template_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index fe82504d3b..13d30a93ce 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -170,7 +170,7 @@ class TestERBTemplate < ActiveSupport::TestCase def with_external_encoding(encoding) old = Encoding.default_external - Encoding::Converter.new old, encoding + Encoding::Converter.new old, encoding if old != encoding silence_warnings { Encoding.default_external = encoding } yield ensure -- cgit v1.2.3 From 3f65e7f7be92adfb2d89ec23ef28a96d2bfae294 Mon Sep 17 00:00:00 2001 From: Will Farrington Date: Sat, 10 Dec 2011 23:53:39 -0500 Subject: Add button_tag support to ActionView::Helpers::FormBuilder. This support is near-identical to the existing submit_tag support. Example: <%= form_for @post do |f| %> <%= f.button %> <% end %> --- actionpack/test/template/form_helper_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 41e925b000..73b936b16e 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -689,6 +689,7 @@ class FormHelperTest < ActionView::TestCase concat f.text_area(:body) concat f.check_box(:secret) concat f.submit('Create post') + concat f.button('Create post') end expected = whole_form("/posts/123", "create-post" , "edit_post", :method => "put") do @@ -697,7 +698,8 @@ class FormHelperTest < ActionView::TestCase "" + "" + "" + - "" + "" + + "" end assert_dom_equal expected, output_buffer -- cgit v1.2.3 From dc43e402a10d10f72f3051c1f33bdc335a54d995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lennart=20Fride=CC=81n?= Date: Sun, 11 Dec 2011 22:19:11 +0100 Subject: =?UTF-8?q?Added=20:use=5Ftwo=5Fdigit=5Fnumbers=20option=20[Lennar?= =?UTF-8?q?t=20Frid=C3=A9n=20&=20Kim=20Persson]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added use_two_digit_numbers select_tag option for displaying months and days with leading zeros without affecting the values (useful for e.g. ISO-style dates, 2011-08-01). Signed-off-by: José Valim Conflicts: actionpack/CHANGELOG.md --- actionpack/test/template/date_helper_test.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index af30ec9892..57a5895cec 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -164,6 +164,15 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, select_day(nil, :include_blank => true) end + def test_select_day_with_two_digit_numbers + expected = %(\n" + + assert_dom_equal expected, select_day(Time.mktime(2011, 8, 2), :use_two_digit_numbers => true) + assert_dom_equal expected, select_day(2, :use_two_digit_numbers => true) + end + def test_select_day_with_html_options expected = %(\n) + expected << %(\n\n\n\n\n\n\n\n\n\n\n\n) + expected << "\n" + + assert_dom_equal expected, select_month(Time.mktime(2011, 8, 16), :use_two_digit_numbers => true) + assert_dom_equal expected, select_month(8, :use_two_digit_numbers => true) + end + def test_select_month_with_disabled expected = %(\n) expected << %(\n\n\n) -- cgit v1.2.3 From ede647a505fbba459d4e8529646b1f5cb59c1d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 19:23:13 +0100 Subject: Allow reloader to be configured. --- actionpack/test/dispatch/reloader_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/reloader_test.rb b/actionpack/test/dispatch/reloader_test.rb index eaabc1feb3..bd24256427 100644 --- a/actionpack/test/dispatch/reloader_test.rb +++ b/actionpack/test/dispatch/reloader_test.rb @@ -43,6 +43,19 @@ class ReloaderTest < Test::Unit::TestCase assert_respond_to body, :close end + def test_condition_specifies_when_to_reload + i, j = 0, 0, 0, 0 + Reloader.to_prepare { |*args| i += 1 } + Reloader.to_cleanup { |*args| j += 1 } + app = Reloader.new(lambda { |env| [200, {}, []] }, lambda { i < 3 }) + 5.times do + resp = app.call({}) + resp[2].close + end + assert_equal 3, i + assert_equal 3, j + end + def test_returned_body_object_behaves_like_underlying_object body = call_and_return_body do b = MyBody.new -- cgit v1.2.3 From fa1d9a884c0d5b70c97442e3360ac98ca5fa4340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 22:51:33 +0100 Subject: Speed up development by only reloading classes if dependencies files changed. This can be turned off by setting `config.reload_classes_only_on_change` to false. Extensions like Active Record should add their respective files like db/schema.rb and db/structure.sql to `config.watchable_files` if they want their changes to affect classes reloading. Thanks to https://github.com/paneq/active_reload and Pastorino for the inspiration. <3 --- actionpack/test/dispatch/reloader_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/reloader_test.rb b/actionpack/test/dispatch/reloader_test.rb index bd24256427..3411bd14ea 100644 --- a/actionpack/test/dispatch/reloader_test.rb +++ b/actionpack/test/dispatch/reloader_test.rb @@ -129,6 +129,15 @@ class ReloaderTest < Test::Unit::TestCase assert cleaned end + def test_prepend_prepare_callback + i = 10 + Reloader.to_prepare { i += 1 } + Reloader.to_prepare(:prepend => true) { i = 0 } + + Reloader.prepare! + assert_equal 1, i + end + def test_cleanup_callbacks_are_called_on_exceptions cleaned = false Reloader.to_cleanup { cleaned = true } -- cgit v1.2.3 From 810837dda890a5bc5d0b4d65b973ca0ccc9465bd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 12 Dec 2011 19:45:16 -0800 Subject: use Array#join so that file encoding doesn't impact returned string. Fixes #3957 --- actionpack/test/dispatch/response_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 337ece6b88..9bdd5ecbc6 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -5,6 +5,15 @@ class ResponseTest < ActiveSupport::TestCase @response = ActionDispatch::Response.new end + def test_response_body_encoding + # FIXME: remove this conditional on Rails 4.0 + return unless "<3".encoding_aware? + + body = ["hello".encode('utf-8')] + response = ActionDispatch::Response.new 200, {}, body + assert_equal Encoding::UTF_8, response.body.encoding + end + test "simple output" do @response.body = "Hello, World!" -- cgit v1.2.3 From 0f4da5b39394fe1096e93a7f2600f4d90330d1c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 15:39:58 +0100 Subject: Fix failing AP tests. --- actionpack/test/dispatch/routing_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 19eee379fd..bc4e2e31c8 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -2296,7 +2296,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_named_routes_collision_is_avoided_unless_explicitly_given_as assert_equal "/c/1", routes_collision_path(1) - assert_equal "/forced_collision", routes_forced_collision_path + assert_equal "/fc", routes_forced_collision_path end def test_redirect_argument_error -- cgit v1.2.3 From 081431fdf180ec7395c769793b2270d244566ca2 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Tue, 13 Dec 2011 22:32:39 +0300 Subject: log exception backtrace when all backtrace lines silenced --- actionpack/test/dispatch/debug_exceptions_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index f7411c7729..6133bfe338 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -122,4 +122,17 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest get "/", {}, {'action_dispatch.show_exceptions' => true, 'action_dispatch.backtrace_cleaner' => cleaner} assert_match(/passed backtrace cleaner/, body) end + + test 'logs exception backtrace when all lines silenced' do + output = StringIO.new + backtrace_cleaner = ActiveSupport::BacktraceCleaner.new + backtrace_cleaner.add_silencer { true } + + env = {'action_dispatch.show_exceptions' => true, + 'action_dispatch.logger' => Logger.new(output), + 'action_dispatch.backtrace_cleaner' => backtrace_cleaner} + + get "/", {}, env + assert_operator (output.rewind && output.read).lines.count, :>, 10 + end end -- cgit v1.2.3 From f3531a8fc9f661f96759f0a851540745876e5d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 14 Dec 2011 09:23:34 +0100 Subject: Clean up details keys before some tests to expire the cache. --- actionpack/test/template/compiled_templates_test.rb | 4 ++++ actionpack/test/template/lookup_context_test.rb | 8 +------- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index 8fc78283d8..30d798d693 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -3,6 +3,10 @@ require 'controller/fake_models' class CompiledTemplatesTest < Test::Unit::TestCase def setup + # Clean up any details key cached to expose failures + # that otherwise would appear just on isolated tests + ActionView::LookupContext::DetailsKey.clear + @compiled_templates = ActionView::CompiledTemplates @compiled_templates.instance_methods.each do |m| @compiled_templates.send(:remove_method, m) if m =~ /^_render_template_/ diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb index bac2530e3d..c65f707da0 100644 --- a/actionpack/test/template/lookup_context_test.rb +++ b/actionpack/test/template/lookup_context_test.rb @@ -1,20 +1,14 @@ require "abstract_unit" require "abstract_controller/rendering" -ActionView::LookupContext::DetailsKey.class_eval do - def self.details_keys - @details_keys - end -end - class LookupContextTest < ActiveSupport::TestCase def setup @lookup_context = ActionView::LookupContext.new(FIXTURE_LOAD_PATH, {}) + ActionView::LookupContext::DetailsKey.clear end def teardown I18n.locale = :en - ActionView::LookupContext::DetailsKey.details_keys.clear end test "process view paths on initialization" do -- cgit v1.2.3 From 5f67cfeda116f2b932ef72781420aa37e62437ca Mon Sep 17 00:00:00 2001 From: choonkeat Date: Wed, 14 Dec 2011 22:43:42 +0800 Subject: Fix url_for options[:subdomain] to allow objects as values * e.g. blog_url(subdomain: current_user) instead of blog_url(subdomain: current_user.to_param) --- actionpack/test/controller/url_for_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb index dc07e07cb9..288efbf7c3 100644 --- a/actionpack/test/controller/url_for_test.rb +++ b/actionpack/test/controller/url_for_test.rb @@ -71,6 +71,14 @@ module AbstractController ) end + def test_subdomain_may_be_object + model = mock(:to_param => 'api') + add_host! + assert_equal('http://api.basecamphq.com/c/a/i', + W.new.url_for(:subdomain => model, :controller => 'c', :action => 'a', :id => 'i') + ) + end + def test_subdomain_may_be_removed add_host! assert_equal('http://basecamphq.com/c/a/i', -- cgit v1.2.3 From e3a4eb4b4067ee7d906babd029e60565001f7808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 14 Dec 2011 17:03:35 +0100 Subject: Close the response body on cascade pass, closes #3975. --- actionpack/test/dispatch/debug_exceptions_test.rb | 25 ++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index 6133bfe338..29fc248acc 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -3,8 +3,18 @@ require 'abstract_unit' class DebugExceptionsTest < ActionDispatch::IntegrationTest class Boomer + attr_accessor :closed + def initialize(detailed = false) @detailed = detailed + @closed = false + end + + def each + end + + def close + @closed = true end def call(env) @@ -12,7 +22,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest req = ActionDispatch::Request.new(env) case req.path when "/pass" - [404, { "X-Cascade" => "pass" }, []] + [404, { "X-Cascade" => "pass" }, self] when "/not_found" raise ActionController::UnknownAction when "/runtime_error" @@ -31,8 +41,8 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end end - ProductionApp = ActionDispatch::DebugExceptions.new((Boomer.new(false))) - DevelopmentApp = ActionDispatch::DebugExceptions.new((Boomer.new(true))) + ProductionApp = ActionDispatch::DebugExceptions.new(Boomer.new(false)) + DevelopmentApp = ActionDispatch::DebugExceptions.new(Boomer.new(true)) test 'skip diagnosis if not showing detailed exceptions' do @app = ProductionApp @@ -55,6 +65,15 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end end + test 'closes the response body on cascade pass' do + boomer = Boomer.new(false) + @app = ActionDispatch::DebugExceptions.new(boomer) + assert_raise ActionController::RoutingError do + get "/pass", {}, {'action_dispatch.show_exceptions' => true} + end + assert boomer.closed, "Expected to close the response body" + end + test "rescue with diagnostics message" do @app = DevelopmentApp -- cgit v1.2.3 From caa1c1978733b6271309db5af488c39aacff6c5a Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Wed, 14 Dec 2011 23:20:23 +0300 Subject: fix separator insertion in date_select helper --- actionpack/test/template/date_helper_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 57a5895cec..fadfb59572 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1396,6 +1396,25 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, date_select("post", "written_on", :order => [ :month, :year ]) end + def test_date_select_without_day_with_separator + @post = Post.new + @post.written_on = Date.new(2004, 6, 15) + + expected = "\n" + + expected << %{\n" + + expected << "/" + + expected << %{\n" + + assert_dom_equal expected, date_select("post", "written_on", :date_separator => '/', :order => [ :month, :year ]) + end + def test_date_select_without_day_and_with_disabled_html_option @post = Post.new @post.written_on = Date.new(2004, 6, 15) -- cgit v1.2.3 From 26e7400cc5415dbce5e2c5d13da96ad8c25749e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 15 Dec 2011 19:43:49 +0100 Subject: Fix diagnostics page for routing errors. --- actionpack/test/controller/show_exceptions_test.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb index 5eff1eb09d..2f5c268330 100644 --- a/actionpack/test/controller/show_exceptions_test.rb +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -5,9 +5,17 @@ module ShowExceptions use ActionDispatch::ShowExceptions use ActionDispatch::DebugExceptions + before_filter :only => :another_boom do + request.env["action_dispatch.show_detailed_exceptions"] = true + end + def boom raise 'boom!' end + + def another_boom + raise 'boom!' + end end class ShowExceptionsTest < ActionDispatch::IntegrationTest @@ -27,9 +35,8 @@ module ShowExceptions end end - test 'show diagnostics from a remote ip when consider_all_requests_local is true' do - ShowExceptionsController.any_instance.stubs(:consider_all_requests_local).returns(true) - @app = ShowExceptionsController.action(:boom) + test 'show diagnostics from a remote ip when env is already set' do + @app = ShowExceptionsController.action(:another_boom) self.remote_addr = '208.77.188.166' get '/' assert_match(/boom/, body) -- cgit v1.2.3 From 5e0dec5e1042e67fb50adc8c073216195ed23ceb Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 15 Dec 2011 12:56:00 -0800 Subject: it's -> its --- actionpack/test/controller/default_url_options_with_filter_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/default_url_options_with_filter_test.rb b/actionpack/test/controller/default_url_options_with_filter_test.rb index 3bbb981040..ef028e8cdb 100644 --- a/actionpack/test/controller/default_url_options_with_filter_test.rb +++ b/actionpack/test/controller/default_url_options_with_filter_test.rb @@ -21,7 +21,7 @@ end class ControllerWithBeforeFilterAndDefaultUrlOptionsTest < ActionController::TestCase - # This test has it´s roots in issue #1872 + # This test has its roots in issue #1872 test "should redirect with correct locale :de" do get :redirect, :locale => "de" assert_redirected_to "/controller_with_before_filter_and_default_url_options/target?locale=de" -- cgit v1.2.3 From aa39149b2f20963d883130f24679292c3ed39bd0 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 16 Dec 2011 10:30:20 +0530 Subject: Warning removed "warning: (...) interpreted as grouped expression" --- actionpack/test/dispatch/debug_exceptions_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index 29fc248acc..f3dc160d7d 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -152,6 +152,6 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest 'action_dispatch.backtrace_cleaner' => backtrace_cleaner} get "/", {}, env - assert_operator (output.rewind && output.read).lines.count, :>, 10 + assert_operator((output.rewind && output.read).lines.count, :>, 10) end end -- cgit v1.2.3 From d1425725673b0172d6561adebaed017b51db9333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 09:06:30 +0100 Subject: Get rid of the close checks since we cannot reliably close the session anyway. --- actionpack/test/controller/flash_test.rb | 40 ------------- actionpack/test/dispatch/cookies_test.rb | 98 +------------------------------- 2 files changed, 1 insertion(+), 137 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index e19612eace..d497913dc4 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -254,16 +254,6 @@ class FlashIntegrationTest < ActionDispatch::IntegrationTest end end - def test_setting_flash_raises_after_stream_back_to_client - with_test_route_set do - env = { 'action_dispatch.request.flash_hash' => ActionDispatch::Flash::FlashHash.new } - get '/set_flash', nil, env - assert_raise(ActionDispatch::ClosedError) { - @request.flash['alert'] = 'alert' - } - end - end - def test_setting_flash_does_not_raise_in_following_requests with_test_route_set do env = { 'action_dispatch.request.flash_hash' => ActionDispatch::Flash::FlashHash.new } @@ -280,36 +270,6 @@ class FlashIntegrationTest < ActionDispatch::IntegrationTest end end - def test_setting_flash_raises_after_stream_back_to_client_even_with_an_empty_flash - with_test_route_set do - env = { 'action_dispatch.request.flash_hash' => ActionDispatch::Flash::FlashHash.new } - get '/dont_set_flash', nil, env - assert_raise(ActionDispatch::ClosedError) { - @request.flash['alert'] = 'alert' - } - end - end - - def test_setting_flash_now_raises_after_stream_back_to_client - with_test_route_set do - env = { 'action_dispatch.request.flash_hash' => ActionDispatch::Flash::FlashHash.new } - get '/set_flash_now', nil, env - assert_raise(ActionDispatch::ClosedError) { - @request.flash.now['alert'] = 'alert' - } - end - end - - def test_setting_flash_now_raises_after_stream_back_to_client_even_with_an_empty_flash - with_test_route_set do - env = { 'action_dispatch.request.flash_hash' => ActionDispatch::Flash::FlashHash.new } - get '/dont_set_flash', nil, env - assert_raise(ActionDispatch::ClosedError) { - @request.flash.now['alert'] = 'alert' - } - end - end - private # Overwrite get to send SessionSecret in env hash diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb index 3765b7eb44..6ebd02e85c 100644 --- a/actionpack/test/dispatch/cookies_test.rb +++ b/actionpack/test/dispatch/cookies_test.rb @@ -564,100 +564,4 @@ class CookiesTest < ActionController::TestCase assert_not_equal expected.split("\n"), header end end -end - -class CookiesIntegrationTest < ActionDispatch::IntegrationTest - SessionKey = '_myapp_session' - SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33' - - class TestController < ActionController::Base - def dont_set_cookies - head :ok - end - - def set_cookies - cookies["that"] = "hello" - head :ok - end - end - - def test_setting_cookies_raises_after_stream_back_to_client - with_test_route_set do - get '/set_cookies' - assert_raise(ActionDispatch::ClosedError) { - request.cookie_jar['alert'] = 'alert' - cookies['alert'] = 'alert' - } - end - end - - def test_setting_cookies_raises_after_stream_back_to_client_even_without_cookies - with_test_route_set do - get '/dont_set_cookies' - assert_raise(ActionDispatch::ClosedError) { - request.cookie_jar['alert'] = 'alert' - } - end - end - - def test_setting_permanent_cookies_raises_after_stream_back_to_client - with_test_route_set do - get '/set_cookies' - assert_raise(ActionDispatch::ClosedError) { - request.cookie_jar.permanent['alert'] = 'alert' - cookies['alert'] = 'alert' - } - end - end - - def test_setting_permanent_cookies_raises_after_stream_back_to_client_even_without_cookies - with_test_route_set do - get '/dont_set_cookies' - assert_raise(ActionDispatch::ClosedError) { - request.cookie_jar.permanent['alert'] = 'alert' - } - end - end - - def test_setting_signed_cookies_raises_after_stream_back_to_client - with_test_route_set do - get '/set_cookies' - assert_raise(ActionDispatch::ClosedError) { - request.cookie_jar.signed['alert'] = 'alert' - cookies['alert'] = 'alert' - } - end - end - - def test_setting_signed_cookies_raises_after_stream_back_to_client_even_without_cookies - with_test_route_set do - get '/dont_set_cookies' - assert_raise(ActionDispatch::ClosedError) { - request.cookie_jar.signed['alert'] = 'alert' - } - end - end - - private - - # Overwrite get to send SessionSecret in env hash - def get(path, parameters = nil, env = {}) - env["action_dispatch.secret_token"] ||= SessionSecret - super - end - - def with_test_route_set - with_routing do |set| - set.draw do - match ':action', :to => CookiesIntegrationTest::TestController - end - - @app = self.class.build_app(set) do |middleware| - middleware.use ActionDispatch::Cookies - middleware.delete "ActionDispatch::ShowExceptions" - end - - yield - end - end -end +end \ No newline at end of file -- cgit v1.2.3 From deef8dd68241cdb9826a2293bced5e2257ccea90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 09:29:37 +0100 Subject: Extract the rendering of public exceptions pages into a Rack app. --- actionpack/test/abstract_unit.rb | 10 +--------- actionpack/test/controller/show_exceptions_test.rb | 2 +- actionpack/test/dispatch/show_exceptions_test.rb | 2 +- 3 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 c95b8221a1..40ca23a39d 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -174,7 +174,7 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase def self.build_app(routes = nil) RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware| - middleware.use "ActionDispatch::ShowExceptions" + middleware.use "ActionDispatch::ShowExceptions", ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public") middleware.use "ActionDispatch::DebugExceptions" middleware.use "ActionDispatch::Callbacks" middleware.use "ActionDispatch::ParamsParser" @@ -337,14 +337,6 @@ class Workshop end module ActionDispatch - class ShowExceptions - private - remove_method :public_path - def public_path - "#{FIXTURE_LOAD_PATH}/public" - end - end - class DebugExceptions private remove_method :stderr_logger diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb index 2f5c268330..ba78559f31 100644 --- a/actionpack/test/controller/show_exceptions_test.rb +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -2,7 +2,7 @@ require 'abstract_unit' module ShowExceptions class ShowExceptionsController < ActionController::Base - use ActionDispatch::ShowExceptions + use ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public") use ActionDispatch::DebugExceptions before_filter :only => :another_boom do diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 020cc80f3f..d3c99e4f31 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -18,7 +18,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest end end - ProductionApp = ActionDispatch::ShowExceptions.new(Boomer.new) + ProductionApp = ActionDispatch::ShowExceptions.new(Boomer.new, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")) test 'skip diagnosis if not showing exceptions' do @app = ProductionApp -- cgit v1.2.3 From 7dd1c751f90858cbdfaebeafed5fdf1ef400ae8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 09:45:14 +0100 Subject: Improve the specs on exceptions app. --- actionpack/test/dispatch/show_exceptions_test.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index d3c99e4f31..0ebe281ada 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -20,7 +20,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest ProductionApp = ActionDispatch::ShowExceptions.new(Boomer.new, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")) - test 'skip diagnosis if not showing exceptions' do + test "skip exceptions app if not showing exceptions" do @app = ProductionApp assert_raise RuntimeError do get "/", {}, {'action_dispatch.show_exceptions' => false} @@ -75,4 +75,17 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest assert_response 404 assert_match(/404 error/, body) end + + test "calls custom exceptions app" do + exceptions_app = lambda do |env| + assert_kind_of AbstractController::ActionNotFound, env["action_dispatch.exception"] + assert_equal "/404", env["PATH_INFO"] + [404, { "Content-Type" => "text/plain" }, ["YOU FAILED BRO"]] + end + + @app = ActionDispatch::ShowExceptions.new(Boomer.new, exceptions_app) + get "/not_found_original_exception", {}, {'action_dispatch.show_exceptions' => true} + assert_response 404 + assert_equal "YOU FAILED BRO", body + end end -- cgit v1.2.3 From 5359262695b491422b18c565567e16ad50f6155e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 09:59:36 +0100 Subject: ShowExceptions should understand X-Cascade responses from exceptions app. --- actionpack/test/dispatch/show_exceptions_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 0ebe281ada..e9504f3524 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -88,4 +88,15 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest assert_response 404 assert_equal "YOU FAILED BRO", body end + + test "returns an empty response if custom exceptions app returns X-Cascade pass" do + exceptions_app = lambda do |env| + [404, { "X-Cascade" => "pass" }, []] + end + + @app = ActionDispatch::ShowExceptions.new(Boomer.new, exceptions_app) + get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true} + assert_response 405 + assert_equal "", body + end end -- cgit v1.2.3 From 192e55c38ed9b48672b9e216c9805b782b835d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 10:29:45 +0100 Subject: Do not raise an exception if an invalid route was generated automatically. --- actionpack/test/dispatch/routing_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index bc4e2e31c8..5325f81364 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -91,6 +91,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest match "/local/:action", :controller => "local" match "/projects/status(.:format)" + match "/404", :to => lambda { |env| [404, {"Content-Type" => "text/plain"}, ["NOT FOUND"]] } constraints(:ip => /192\.168\.1\.\d\d\d/) do get 'admin' => "queenbee#index" -- cgit v1.2.3 From 654df86b7b022085785a64c431c45d8450d5e987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 10:38:17 +0100 Subject: Show detailed exceptions no longer returns true if the request is local in production. --- actionpack/test/controller/new_base/render_template_test.rb | 6 ++++++ actionpack/test/controller/show_exceptions_test.rb | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/new_base/render_template_test.rb b/actionpack/test/controller/new_base/render_template_test.rb index ba804421da..ade204c387 100644 --- a/actionpack/test/controller/new_base/render_template_test.rb +++ b/actionpack/test/controller/new_base/render_template_test.rb @@ -59,6 +59,12 @@ module RenderTemplate def with_error render :template => "test/with_error" end + + private + + def show_detailed_exceptions? + request.local? + end end class TestWithoutLayout < Rack::TestCase diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb index ba78559f31..13ab19ed8f 100644 --- a/actionpack/test/controller/show_exceptions_test.rb +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -16,6 +16,10 @@ module ShowExceptions def another_boom raise 'boom!' end + + def show_detailed_exceptions? + request.local? + end end class ShowExceptionsTest < ActionDispatch::IntegrationTest @@ -26,7 +30,7 @@ module ShowExceptions assert_equal "500 error fixture\n", body end - test 'show diagnostics from a local ip' do + test 'show diagnostics from a local ip if show_detailed_exceptions? is set to request.local?' do @app = ShowExceptionsController.action(:boom) ['127.0.0.1', '127.0.0.127', '::1', '0:0:0:0:0:0:0:1', '0:0:0:0:0:0:0:1%0'].each do |ip_address| self.remote_addr = ip_address -- cgit v1.2.3 From 23334be5b88a2607a35cfc970f3250ec7ae5ca9e Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sat, 17 Dec 2011 12:00:28 +0530 Subject: warning removed "warning: instance variable @variable_for_layout not initialized" --- actionpack/test/controller/action_pack_assertions_test.rb | 1 + 1 file changed, 1 insertion(+) (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 b414327d08..5252e43c25 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -72,6 +72,7 @@ class ActionPackAssertionsController < ActionController::Base end def render_with_layout + @variable_for_layout = nil render "test/hello_world", :layout => "layouts/standard" end -- cgit v1.2.3 From 4d5266e2706195888c9f72fdc9ebde22f89a08df Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Sat, 17 Dec 2011 07:39:52 -0500 Subject: Allow symbols to be passed for extension aliases --- actionpack/test/dispatch/mime_type_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index 08fe2127b9..7a94b188ce 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -95,6 +95,17 @@ class MimeTypeTest < ActiveSupport::TestCase end end + test "custom type with extension aliases" do + begin + Mime::Type.register "text/foobar", :foobar, [], [:foo, "bar"] + %w[foobar foo bar].each do |extension| + assert_equal Mime::FOOBAR, Mime::EXTENSION_LOOKUP[extension] + end + ensure + Mime::Type.unregister(:FOOBAR) + end + end + test "type should be equal to symbol" do assert_equal Mime::HTML, 'application/xhtml+xml' assert_equal Mime::HTML, :html -- cgit v1.2.3 From a87690b02c0d1b4387974114625696e7e113080f Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Sat, 17 Dec 2011 07:40:54 -0500 Subject: Add test for type aliases --- actionpack/test/dispatch/mime_type_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index 7a94b188ce..5415097e44 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -95,6 +95,17 @@ class MimeTypeTest < ActiveSupport::TestCase end end + test "custom type with type aliases" do + begin + Mime::Type.register "text/foobar", :foobar, ["text/foo", "text/bar"] + %w[text/foobar text/foo text/bar].each do |type| + assert_equal Mime::FOOBAR, type + end + ensure + Mime::Type.unregister(:FOOBAR) + end + end + test "custom type with extension aliases" do begin Mime::Type.register "text/foobar", :foobar, [], [:foo, "bar"] -- cgit v1.2.3 From 27f3619cd5d3700b2ff16f7c153c3549316b9410 Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Sat, 17 Dec 2011 07:52:42 -0500 Subject: Add test for register_alias --- actionpack/test/dispatch/mime_type_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index 5415097e44..db21080c42 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -117,6 +117,15 @@ class MimeTypeTest < ActiveSupport::TestCase end end + test "register alias" do + begin + Mime::Type.register_alias "application/xhtml+xml", :foobar + assert_equal Mime::HTML, Mime::EXTENSION_LOOKUP['foobar'] + ensure + Mime::Type.unregister(:FOOBAR) + end + end + test "type should be equal to symbol" do assert_equal Mime::HTML, 'application/xhtml+xml' assert_equal Mime::HTML, :html -- cgit v1.2.3 From 024d3b9fcc684367b1a329c8b89c227b6470520e Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Mon, 19 Dec 2011 21:55:37 +0300 Subject: add failing tests for issue #3487 --- .../test/template/active_model_helper_test.rb | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/active_model_helper_test.rb b/actionpack/test/template/active_model_helper_test.rb index 8530a72a82..52be0f1762 100644 --- a/actionpack/test/template/active_model_helper_test.rb +++ b/actionpack/test/template/active_model_helper_test.rb @@ -4,7 +4,7 @@ class ActiveModelHelperTest < ActionView::TestCase tests ActionView::Helpers::ActiveModelHelper silence_warnings do - class Post < Struct.new(:author_name, :body) + class Post < Struct.new(:author_name, :body, :updated_at) include ActiveModel::Conversion include ActiveModel::Validations @@ -20,9 +20,11 @@ class ActiveModelHelperTest < ActionView::TestCase @post = Post.new @post.errors[:author_name] << "can't be empty" @post.errors[:body] << "foo" + @post.errors[:updated_at] << "bar" @post.author_name = "" @post.body = "Back to the hill and over it again!" + @post.updated_at = Date.new(2004, 6, 15) end def test_text_area_with_errors @@ -39,6 +41,27 @@ class ActiveModelHelperTest < ActionView::TestCase ) end + def test_date_select_with_errors + assert_dom_equal( + %(
\n\n\n
), + date_select("post", "updated_at", :discard_month => true, :discard_day => true, :start_year => 2004, :end_year => 2005) + ) + end + + def test_datetime_select_with_errors + assert_dom_equal( + %(
\n\n\n\n : \n
), + datetime_select("post", "updated_at", :discard_year => true, :discard_month => true, :discard_day => true, :minute_step => 60) + ) + end + + def test_time_select_with_errors + assert_dom_equal( + %(
\n\n\n\n : \n
), + time_select("post", "updated_at", :minute_step => 60) + ) + end + def test_hidden_field_does_not_render_errors assert_dom_equal( %(), -- cgit v1.2.3 From 9d0789c415111a3b3e85bdb5ed16d10f1f749d89 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 19 Dec 2011 13:34:54 -0800 Subject: adding tests for #4029 --- actionpack/test/controller/routing_test.rb | 51 ++++++++++++++++++++++++++++++ actionpack/test/dispatch/mount_test.rb | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 062fc1f94e..f40d663ae8 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -85,6 +85,57 @@ class LegacyRouteSetTests < Test::Unit::TestCase @rs.clear! end + def test_class_and_lambda_constraints + subdomain = Class.new { + def matches? request + request.subdomain.present? and request.subdomain != 'clients' + end + } + + @rs.draw do + match '/', :constraints => subdomain.new, + :to => lambda { |env| [200, {}, 'default'] } + match '/', :constraints => { :subdomain => 'clients' }, + :to => lambda { |env| [200, {}, 'clients'] } + end + + body = @rs.call({'PATH_INFO' => '/', + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => 'www.example.org'})[2] + + assert_equal 'default', body + + body = @rs.call({'PATH_INFO' => '/', + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => 'clients.example.org'})[2] + + assert_equal 'clients', body + end + + def test_lambda_constraints + @rs.draw do + match '/', :constraints => lambda { |req| + req.subdomain.present? and req.subdomain != "clients" }, + :to => lambda { |env| [200, {}, 'default'] } + + match '/', :constraints => lambda { |req| + req.subdomain.present? && req.subdomain == "clients" }, + :to => lambda { |env| [200, {}, 'clients'] } + end + + body = @rs.call({'PATH_INFO' => '/', + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => 'www.example.org'})[2] + + assert_equal 'default', body + + body = @rs.call({'PATH_INFO' => '/', + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => 'clients.example.org'})[2] + + assert_equal 'clients', body + end + def test_draw_with_block_arity_one_raises assert_raise(RuntimeError) do @rs.draw { |map| map.match '/:controller(/:action(/:id))' } diff --git a/actionpack/test/dispatch/mount_test.rb b/actionpack/test/dispatch/mount_test.rb index 1a032539b9..f7a746120e 100644 --- a/actionpack/test/dispatch/mount_test.rb +++ b/actionpack/test/dispatch/mount_test.rb @@ -51,4 +51,4 @@ class TestRoutingMount < ActionDispatch::IntegrationTest get "/fakeengine" assert_equal "OK", response.body end -end \ No newline at end of file +end -- cgit v1.2.3 From c3c1ff40fcc4cbc31a5396a8b7737755ad4bc95b Mon Sep 17 00:00:00 2001 From: lest Date: Tue, 20 Dec 2011 15:37:20 +0300 Subject: remove warnings about @variable_for_layout --- actionpack/test/controller/render_test.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 243bad8749..f42a04d670 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -25,6 +25,8 @@ end class TestController < ActionController::Base protect_from_forgery + before_filter :set_variable_for_layout + class LabellingFormBuilder < ActionView::Helpers::FormBuilder end @@ -364,17 +366,14 @@ class TestController < ActionController::Base end def layout_test_with_different_layout - @variable_for_layout = nil render :action => "hello_world", :layout => "standard" end def layout_test_with_different_layout_and_string_action - @variable_for_layout = nil render "hello_world", :layout => "standard" end def layout_test_with_different_layout_and_symbol_action - @variable_for_layout = nil render :hello_world, :layout => "standard" end @@ -383,7 +382,6 @@ class TestController < ActionController::Base end def layout_overriding_layout - @variable_for_layout = nil render :action => "hello_world", :layout => "standard" end @@ -666,8 +664,11 @@ class TestController < ActionController::Base private + def set_variable_for_layout + @variable_for_layout = nil + end + def determine_layout - @variable_for_layout ||= nil case action_name when "hello_world", "layout_test", "rendering_without_layout", "rendering_nothing_on_layout", "render_text_hello_world", -- cgit v1.2.3 From cae1768c6a0e3d1cd4a2c2d836ef213438689db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Dec 2011 14:44:48 +0100 Subject: Remove deprecated layout lookup. --- actionpack/test/abstract/layouts_test.rb | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb index de6f42d826..fc25718d9e 100644 --- a/actionpack/test/abstract/layouts_test.rb +++ b/actionpack/test/abstract/layouts_test.rb @@ -57,11 +57,8 @@ module AbstractControllerTests layout "hello_override" end - class WithNilChild < WithString - layout nil - end - class WithStringImpliedChild < WithString + layout nil end class WithChildOfImplied < WithStringImpliedChild @@ -258,20 +255,14 @@ module AbstractControllerTests test "when a child controller has an implied layout, use that layout and not the parent controller layout" do controller = WithStringImpliedChild.new - assert_deprecated { 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 + assert_equal "With Implied Hello string!", controller.response_body end test "when a grandchild has no layout specified, the child has an implied layout, and the " \ "parent has specified a layout, use the child controller layout" do controller = WithChildOfImplied.new - assert_deprecated { controller.process(:index) } + controller.process(:index) assert_equal "With Implied Hello string!", controller.response_body end -- cgit v1.2.3 From 6c57177f2c7f4f934716d588545902d5fc00fa99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Dec 2011 15:12:38 +0100 Subject: Remove deprecation warnings from Action Pack. --- actionpack/test/controller/render_test.rb | 6 ++---- actionpack/test/template/render_test.rb | 32 +------------------------------ 2 files changed, 3 insertions(+), 35 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index f42a04d670..768cfb34ac 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -43,7 +43,7 @@ class TestController < ActionController::Base end def hello_world_file - render :file => File.expand_path("../../fixtures/hello.html", __FILE__) + render :file => File.expand_path("../../fixtures/hello", __FILE__), :formats => [:html] end def conditional_hello @@ -810,9 +810,7 @@ class RenderTest < ActionController::TestCase end def test_render_file - assert_deprecated do - get :hello_world_file - end + get :hello_world_file assert_equal "Hello world!", @response.body end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index c29519276d..2ba86306f4 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -146,7 +146,7 @@ module RenderTestCases @view.render(:partial => nil) flunk "Render did not raise ArgumentError" rescue ArgumentError => e - assert_equal "'#{nil.inspect}' is not an ActiveModel-compatible object that returns a valid partial path.", e.message + assert_equal "'#{nil.inspect}' is not an ActiveModel-compatible object. It must implement :to_partial_path.", e.message end def test_render_partial_with_errors @@ -243,36 +243,6 @@ module RenderTestCases @controller_view.render(customers, :greeting => "Hello") end - class CustomerWithDeprecatedPartialPath - attr_reader :name - - def self.model_name - Struct.new(:partial_path).new("customers/customer") - end - - def initialize(name) - @name = name - end - end - - def test_render_partial_using_object_with_deprecated_partial_path - assert_deprecated(/#model_name.*#partial_path.*#to_partial_path/) do - assert_equal "Hello: nertzy", - @controller_view.render(CustomerWithDeprecatedPartialPath.new("nertzy"), :greeting => "Hello") - end - end - - def test_render_partial_using_collection_with_deprecated_partial_path - assert_deprecated(/#model_name.*#partial_path.*#to_partial_path/) do - customers = [ - CustomerWithDeprecatedPartialPath.new("nertzy"), - CustomerWithDeprecatedPartialPath.new("peeja") - ] - assert_equal "Hello: nertzyHello: peeja", - @controller_view.render(customers, :greeting => "Hello") - end - end - # TODO: The reason for this test is unclear, improve documentation def test_render_partial_and_fallback_to_layout assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" }) -- cgit v1.2.3 From 53c1ae99f587d6d7f85a3910f97948906ebba877 Mon Sep 17 00:00:00 2001 From: Jarrod Carlson Date: Wed, 5 Oct 2011 00:18:37 -0400 Subject: Added failing test to demonstrate digest authentication failure --- actionpack/test/controller/http_digest_authentication_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/http_digest_authentication_test.rb b/actionpack/test/controller/http_digest_authentication_test.rb index b011536717..25fda58232 100644 --- a/actionpack/test/controller/http_digest_authentication_test.rb +++ b/actionpack/test/controller/http_digest_authentication_test.rb @@ -208,6 +208,16 @@ class HttpDigestAuthenticationTest < ActionController::TestCase assert !ActionController::HttpAuthentication::Digest.validate_digest_response(@request, "SuperSecret"){nil} end + test "authentication request with request-uri ending in '?'" do + @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please', + :uri => '/http_digest_authentication_test/dummy_digest?') + @request.env['PATH_INFO'] = "/http_digest_authentication_test/dummy_digest?" + get :display + + assert_response :success + assert_equal 'Definitely Maybe', @response.body + end + private def encode_credentials(options) -- cgit v1.2.3 From 55334f52d49630bf73ce06e4f4ec4682a7fe566a Mon Sep 17 00:00:00 2001 From: Brian Rose Date: Tue, 20 Dec 2011 13:19:55 -0700 Subject: Ensure option for select helper responds to `#first` before comparison. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/test/template/form_options_helper_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 469718e1bd..4a889beadd 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -596,6 +596,24 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_select_with_nil + @post = Post.new + @post.category = "othervalue" + assert_dom_equal( + "", + select("post", "category", [nil, "othervalue"]) + ) + end + + def test_select_with_fixnum + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", [1], :prompt => true, :include_blank => true) + ) + end + def test_list_of_lists @post = Post.new @post.category = "" -- cgit v1.2.3 From 80ab9e2a7434a445eaacb097832fbad24ed01960 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 20 Dec 2011 20:34:04 +0100 Subject: Add original_fullpath and original_url methods to Request --- actionpack/test/dispatch/request_test.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 4d805464c2..5b3d38c48c 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -618,6 +618,30 @@ class RequestTest < ActiveSupport::TestCase assert_equal "/authenticate?secret", path end + test "original_fullpath returns ORIGINAL_FULLPATH" do + request = stub_request('ORIGINAL_FULLPATH' => "/foo?bar") + + path = request.original_fullpath + assert_equal "/foo?bar", path + end + + test "original_url returns url built using ORIGINAL_FULLPATH" do + request = stub_request('ORIGINAL_FULLPATH' => "/foo?bar", + 'HTTP_HOST' => "example.org", + 'rack.url_scheme' => "http") + + url = request.original_url + assert_equal "http://example.org/foo?bar", url + end + + test "original_fullpath returns fullpath if ORIGINAL_FULLPATH is not present" do + request = stub_request('PATH_INFO' => "/foo", + 'QUERY_STRING' => "bar") + + path = request.original_fullpath + assert_equal "/foo?bar", path + end + protected def stub_request(env = {}) -- cgit v1.2.3 From 3131a9379766a735a80220fd2e94cb07791bed9c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 20 Dec 2011 21:01:47 +0100 Subject: Fix http digest authentication with trailing '/' or '?' (fixes #4038 and #3228) --- .../controller/http_digest_authentication_test.rb | 41 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/http_digest_authentication_test.rb b/actionpack/test/controller/http_digest_authentication_test.rb index 25fda58232..a91e3cafa5 100644 --- a/actionpack/test/controller/http_digest_authentication_test.rb +++ b/actionpack/test/controller/http_digest_authentication_test.rb @@ -139,7 +139,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase test "authentication request with request-uri that doesn't match credentials digest-uri" do @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please') - @request.env['PATH_INFO'] = "/http_digest_authentication_test/dummy_digest/altered/uri" + @request.env['ORIGINAL_FULLPATH'] = "/http_digest_authentication_test/dummy_digest/altered/uri" get :display assert_response :unauthorized @@ -208,16 +208,44 @@ class HttpDigestAuthenticationTest < ActionController::TestCase assert !ActionController::HttpAuthentication::Digest.validate_digest_response(@request, "SuperSecret"){nil} end + test "authentication request with request-uri ending in '/'" do + @request.env['PATH_INFO'] = "/http_digest_authentication_test/dummy_digest/" + @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please') + + # simulate normalizing PATH_INFO + @request.env['PATH_INFO'] = "/http_digest_authentication_test/dummy_digest" + get :display + + assert_response :success + assert_equal 'Definitely Maybe', @response.body + end + test "authentication request with request-uri ending in '?'" do - @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please', - :uri => '/http_digest_authentication_test/dummy_digest?') - @request.env['PATH_INFO'] = "/http_digest_authentication_test/dummy_digest?" + @request.env['PATH_INFO'] = "/http_digest_authentication_test/dummy_digest/?" + @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please') + + # simulate normalizing PATH_INFO + @request.env['PATH_INFO'] = "/http_digest_authentication_test/dummy_digest" get :display assert_response :success assert_equal 'Definitely Maybe', @response.body end + test "authentication request with absolute uri in credentials (as in IE) ending with /" do + @request.env['PATH_INFO'] = "/http_digest_authentication_test/dummy_digest/" + @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:uri => "http://test.host/http_digest_authentication_test/dummy_digest/", + :username => 'pretty', :password => 'please') + + # simulate normalizing PATH_INFO + @request.env['PATH_INFO'] = "/http_digest_authentication_test/dummy_digest" + get :display + + assert_response :success + assert assigns(:logged_in) + assert_equal 'Definitely Maybe', @response.body + end + private def encode_credentials(options) @@ -238,7 +266,10 @@ class HttpDigestAuthenticationTest < ActionController::TestCase credentials = decode_credentials(@response.headers['WWW-Authenticate']) credentials.merge!(options) - credentials.merge!(:uri => @request.env['PATH_INFO'].to_s) + path_info = @request.env['PATH_INFO'].to_s + uri = options[:uri] || path_info + credentials.merge!(:uri => uri) + @request.env["ORIGINAL_FULLPATH"] = path_info ActionController::HttpAuthentication::Digest.encode_credentials(method, credentials, password, options[:password_is_ha1]) end -- cgit v1.2.3 From b74f5b73989edaca124b4b6f8594e63bda6344c9 Mon Sep 17 00:00:00 2001 From: "Rahul P. Chaudhari" Date: Wed, 21 Dec 2011 13:34:54 +0530 Subject: Remove unused conditions for 1.9 --- actionpack/test/controller/test_test.rb | 9 ++--- actionpack/test/template/capture_helper_test.rb | 30 +++++++---------- actionpack/test/template/text_helper_test.rb | 45 ++++++------------------- 3 files changed, 26 insertions(+), 58 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index b64e275363..0e75a23cfd 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -665,13 +665,8 @@ XML FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart' - if RUBY_VERSION < '1.9' - READ_BINARY = 'rb' - READ_PLAIN = 'r' - else - READ_BINARY = 'rb:binary' - READ_PLAIN = 'r:binary' - end + READ_BINARY = 'rb:binary' + READ_PLAIN = 'r:binary' def test_test_uploaded_file filename = 'mona_lisa.jpg' diff --git a/actionpack/test/template/capture_helper_test.rb b/actionpack/test/template/capture_helper_test.rb index 13e2d5b595..a37e3a8d6a 100644 --- a/actionpack/test/template/capture_helper_test.rb +++ b/actionpack/test/template/capture_helper_test.rb @@ -131,17 +131,15 @@ class CaptureHelperTest < ActionView::TestCase assert buffer.equal?(@av.output_buffer) end - unless RUBY_VERSION < '1.9' - def test_with_output_buffer_sets_proper_encoding - @av.output_buffer = ActionView::OutputBuffer.new + def test_with_output_buffer_sets_proper_encoding + @av.output_buffer = ActionView::OutputBuffer.new - # Ensure we set the output buffer to an encoding different than the default one. - alt_encoding = alt_encoding(@av.output_buffer) - @av.output_buffer.force_encoding(alt_encoding) + # Ensure we set the output buffer to an encoding different than the default one. + alt_encoding = alt_encoding(@av.output_buffer) + @av.output_buffer.force_encoding(alt_encoding) - @av.with_output_buffer do - assert_equal alt_encoding, @av.output_buffer.encoding - end + @av.with_output_buffer do + assert_equal alt_encoding, @av.output_buffer.encoding end end @@ -165,14 +163,12 @@ class CaptureHelperTest < ActionView::TestCase assert_equal '', view.output_buffer end - unless RUBY_VERSION < '1.9' - def test_flush_output_buffer_preserves_the_encoding_of_the_output_buffer - view = view_with_controller - alt_encoding = alt_encoding(view.output_buffer) - view.output_buffer.force_encoding(alt_encoding) - flush_output_buffer - assert_equal alt_encoding, view.output_buffer.encoding - end + def test_flush_output_buffer_preserves_the_encoding_of_the_output_buffer + view = view_with_controller + alt_encoding = alt_encoding(view.output_buffer) + view.output_buffer.force_encoding(alt_encoding) + flush_output_buffer + assert_equal alt_encoding, view.output_buffer.encoding end def alt_encoding(output_buffer) diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index a0afb77f05..96af824b51 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -82,25 +82,13 @@ class TextHelperTest < ActionView::TestCase assert_equal "Hello Big[...]", truncate("Hello Big World!", :omission => "[...]", :length => 15, :separator => ' ') end - if RUBY_VERSION < '1.9.0' - def test_truncate_multibyte - with_kcode 'none' do - assert_equal "\354\225\210\353\205\225\355...", truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", :length => 10) - end - with_kcode 'u' do - assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...", - truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244", :length => 10) - end - end - else - def test_truncate_multibyte - # .mb_chars always returns a UTF-8 String. - # assert_equal "\354\225\210\353\205\225\355...", - # truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", :length => 10) - - assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'), - truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8'), :length => 10) - end + def test_truncate_multibyte + # .mb_chars always returns a UTF-8 String. + # assert_equal "\354\225\210\353\205\225\355...", + # truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", :length => 10) + + assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'), + truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8'), :length => 10) end def test_highlight_should_be_html_safe @@ -243,21 +231,10 @@ class TextHelperTest < ActionView::TestCase ) end - if RUBY_VERSION < '1.9' - def test_excerpt_with_utf8 - with_kcode('u') do - assert_equal("...\357\254\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8)) - end - with_kcode('none') do - assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8)) - end - end - else - def test_excerpt_with_utf8 - assert_equal("...\357\254\203ciency could not be...".force_encoding('UTF-8'), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding('UTF-8'), 'could', 8)) - # .mb_chars always returns UTF-8, even in 1.9. This is not great, but it's how it works. Let's work this out. - # assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped".force_encoding("BINARY"), 'could', 8)) - end + def test_excerpt_with_utf8 + assert_equal("...\357\254\203ciency could not be...".force_encoding('UTF-8'), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding('UTF-8'), 'could', 8)) + # .mb_chars always returns UTF-8, even in 1.9. This is not great, but it's how it works. Let's work this out. + # assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped".force_encoding("BINARY"), 'could', 8)) end def test_word_wrap -- cgit v1.2.3 From 7276fc63be79a5769acb28b54d248c87591c1825 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 21 Dec 2011 15:39:50 +0530 Subject: 'with_kcode' removed. Testing Sandbox removed. --- actionpack/test/lib/testing_sandbox.rb | 15 --------------- actionpack/test/template/output_safety_helper_test.rb | 2 -- actionpack/test/template/sanitize_helper_test.rb | 2 -- actionpack/test/template/text_helper_test.rb | 2 -- 4 files changed, 21 deletions(-) delete mode 100644 actionpack/test/lib/testing_sandbox.rb (limited to 'actionpack/test') diff --git a/actionpack/test/lib/testing_sandbox.rb b/actionpack/test/lib/testing_sandbox.rb deleted file mode 100644 index c36585104f..0000000000 --- a/actionpack/test/lib/testing_sandbox.rb +++ /dev/null @@ -1,15 +0,0 @@ -module TestingSandbox - # Temporarily replaces KCODE for the block - def with_kcode(kcode) - if RUBY_VERSION < '1.9' - old_kcode, $KCODE = $KCODE, kcode - begin - yield - ensure - $KCODE = old_kcode - end - else - yield - end - end -end diff --git a/actionpack/test/template/output_safety_helper_test.rb b/actionpack/test/template/output_safety_helper_test.rb index fc127c24e9..76c71c9e6d 100644 --- a/actionpack/test/template/output_safety_helper_test.rb +++ b/actionpack/test/template/output_safety_helper_test.rb @@ -1,9 +1,7 @@ require 'abstract_unit' -require 'testing_sandbox' class OutputSafetyHelperTest < ActionView::TestCase tests ActionView::Helpers::OutputSafetyHelper - include TestingSandbox def setup @string = "hello" diff --git a/actionpack/test/template/sanitize_helper_test.rb b/actionpack/test/template/sanitize_helper_test.rb index 222d4dbf4c..4182af590e 100644 --- a/actionpack/test/template/sanitize_helper_test.rb +++ b/actionpack/test/template/sanitize_helper_test.rb @@ -1,11 +1,9 @@ require 'abstract_unit' -require 'testing_sandbox' # The exhaustive tests are in test/controller/html/sanitizer_test.rb. # This tests the that the helpers hook up correctly to the sanitizer classes. class SanitizeHelperTest < ActionView::TestCase tests ActionView::Helpers::SanitizeHelper - include TestingSandbox def test_strip_links assert_equal "Dont touch me", strip_links("Dont touch me") diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 96af824b51..839bf900dc 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -1,10 +1,8 @@ # encoding: utf-8 require 'abstract_unit' -require 'testing_sandbox' class TextHelperTest < ActionView::TestCase tests ActionView::Helpers::TextHelper - include TestingSandbox def setup super -- cgit v1.2.3 From 0f510e970f00ac819d331f0415db3ac5ada7b861 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 21 Dec 2011 17:55:57 +0530 Subject: Using uuid which is supported in 1.9 Orignal commit #ada78066fdbccffb1da092a2470211fa252b3c99 --- actionpack/test/dispatch/request_id_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request_id_test.rb b/actionpack/test/dispatch/request_id_test.rb index b6e8b6c3ad..e2a38af233 100644 --- a/actionpack/test/dispatch/request_id_test.rb +++ b/actionpack/test/dispatch/request_id_test.rb @@ -14,7 +14,7 @@ class RequestIdTest < ActiveSupport::TestCase end test "generating a request id when none is supplied" do - assert_match(/\w+/, stub_request.uuid) + assert_match /\w+-\w+-\w+-\w+-\w+/, stub_request.uuid end private -- cgit v1.2.3 From a3c1dc223bb9df3387e1171e17650cef85bf5bb9 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 21 Dec 2011 21:21:39 +0530 Subject: removed warning "warning: ambiguous first argument; put parentheses or even spaces" --- actionpack/test/dispatch/request_id_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request_id_test.rb b/actionpack/test/dispatch/request_id_test.rb index e2a38af233..4b98cd32f2 100644 --- a/actionpack/test/dispatch/request_id_test.rb +++ b/actionpack/test/dispatch/request_id_test.rb @@ -14,7 +14,7 @@ class RequestIdTest < ActiveSupport::TestCase end test "generating a request id when none is supplied" do - assert_match /\w+-\w+-\w+-\w+-\w+/, stub_request.uuid + assert_match(/\w+-\w+-\w+-\w+-\w+/, stub_request.uuid) end private -- cgit v1.2.3 From 52c214f7a388d1bf5c43be96c0495259d54f0f0c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 21 Dec 2011 10:43:54 -0700 Subject: caches should not be global, so no need to clear in the teardown --- actionpack/test/controller/routing_test.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index f40d663ae8..a60da65ae5 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -81,10 +81,6 @@ class LegacyRouteSetTests < Test::Unit::TestCase @rs = ::ActionDispatch::Routing::RouteSet.new end - def teardown - @rs.clear! - end - def test_class_and_lambda_constraints subdomain = Class.new { def matches? request -- cgit v1.2.3 From 9fbaf9f0777485b32ae12d0cc261695b9bb26eea Mon Sep 17 00:00:00 2001 From: Lucas Mazza Date: Wed, 21 Dec 2011 17:31:53 -0200 Subject: raises an ArgumentError if no valid options are given to TemplateRenderer#determine_template --- actionpack/test/template/render_test.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 2ba86306f4..761bcf61f2 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -20,6 +20,13 @@ module RenderTestCases assert_equal ORIGINAL_LOCALES, I18n.available_locales.map {|l| l.to_s }.sort end + def test_render_without_options + @view.render() + flunk "Render did not raise ArgumentError" + rescue ArgumentError => e + assert_match "You invoked render but did not give any of :partial, :template, :inline, :file or :text option.", e.message + end + def test_render_file assert_equal "Hello world!", @view.render(:file => "test/hello_world") end @@ -43,21 +50,21 @@ module RenderTestCases assert_match "

No Comment

", @view.render(:template => "comments/empty", :formats => [:html]) assert_match "No Comment", @view.render(:template => "comments/empty", :formats => [:xml]) end - + def test_render_file_with_locale assert_equal "

Kein Kommentar

", @view.render(:file => "comments/empty", :locale => [:de]) assert_equal "

Kein Kommentar

", @view.render(:file => "comments/empty", :locale => :de) end - + def test_render_template_with_locale assert_equal "

Kein Kommentar

", @view.render(:template => "comments/empty", :locale => [:de]) end - + def test_render_file_with_handlers assert_equal "

No Comment

\n", @view.render(:file => "comments/empty", :handlers => [:builder]) assert_equal "

No Comment

\n", @view.render(:file => "comments/empty", :handlers => :builder) end - + def test_render_template_with_handlers assert_equal "

No Comment

\n", @view.render(:template => "comments/empty", :handlers => [:builder]) end -- cgit v1.2.3 From 44ff03bb2eb1eb2b088265389a2adc89936d7099 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 21 Dec 2011 11:45:41 -0700 Subject: adding integration test for journey #7 --- actionpack/test/controller/routing_test.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index a60da65ae5..a931222bbc 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -81,6 +81,28 @@ class LegacyRouteSetTests < Test::Unit::TestCase @rs = ::ActionDispatch::Routing::RouteSet.new end + def test_regexp_precidence + @rs.draw do + match '/whois/:domain', :constraints => { + :domain => /\w+\.[\w\.]+/ }, + :to => lambda { |env| [200, {}, 'regexp'] } + + match '/whois/:id', :to => lambda { |env| [200, {}, 'id'] } + end + + body = @rs.call({'PATH_INFO' => '/whois/example.org', + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => 'www.example.org'})[2] + + assert_equal 'regexp', body + + body = @rs.call({'PATH_INFO' => '/whois/123', + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => 'clients.example.org'})[2] + + assert_equal 'id', body + end + def test_class_and_lambda_constraints subdomain = Class.new { def matches? request -- cgit v1.2.3 From e68b72dbc4d121e05f70cc56c7b4dfb7e314b8b9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 21 Dec 2011 14:22:38 -0700 Subject: just use def setup --- actionpack/test/dispatch/routing_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 5325f81364..d5c1586600 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -2414,7 +2414,8 @@ class TestAppendingRoutes < ActionDispatch::IntegrationTest lambda { |e| [ 200, { 'Content-Type' => 'text/plain' }, [resp] ] } end - setup do + def setup + super s = self @app = ActionDispatch::Routing::RouteSet.new @app.append do -- cgit v1.2.3 From de6e92fe53ca8760ca3bb16ece64e152eb15c8ef Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 22 Dec 2011 12:53:14 -0700 Subject: refactoring routing tests --- actionpack/test/controller/routing_test.rb | 53 +++++++++++------------------- 1 file changed, 19 insertions(+), 34 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index a931222bbc..d6ae9909b8 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -78,7 +78,19 @@ class LegacyRouteSetTests < Test::Unit::TestCase attr_reader :rs def setup - @rs = ::ActionDispatch::Routing::RouteSet.new + @rs = ::ActionDispatch::Routing::RouteSet.new + @response = nil + end + + def get(uri_or_host, path = nil, port = nil) + host = uri_or_host.host unless path + path ||= uri_or_host.path + + params = {'PATH_INFO' => path, + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => host} + + @rs.call(params)[2] end def test_regexp_precidence @@ -90,17 +102,8 @@ class LegacyRouteSetTests < Test::Unit::TestCase match '/whois/:id', :to => lambda { |env| [200, {}, 'id'] } end - body = @rs.call({'PATH_INFO' => '/whois/example.org', - 'REQUEST_METHOD' => 'GET', - 'HTTP_HOST' => 'www.example.org'})[2] - - assert_equal 'regexp', body - - body = @rs.call({'PATH_INFO' => '/whois/123', - 'REQUEST_METHOD' => 'GET', - 'HTTP_HOST' => 'clients.example.org'})[2] - - assert_equal 'id', body + assert_equal 'regexp', get(URI('http://example.org/whois/example.org')) + assert_equal 'id', get(URI('http://example.org/whois/123')) end def test_class_and_lambda_constraints @@ -117,17 +120,8 @@ class LegacyRouteSetTests < Test::Unit::TestCase :to => lambda { |env| [200, {}, 'clients'] } end - body = @rs.call({'PATH_INFO' => '/', - 'REQUEST_METHOD' => 'GET', - 'HTTP_HOST' => 'www.example.org'})[2] - - assert_equal 'default', body - - body = @rs.call({'PATH_INFO' => '/', - 'REQUEST_METHOD' => 'GET', - 'HTTP_HOST' => 'clients.example.org'})[2] - - assert_equal 'clients', body + assert_equal 'default', get(URI('http://www.example.org/')) + assert_equal 'clients', get(URI('http://clients.example.org/')) end def test_lambda_constraints @@ -141,17 +135,8 @@ class LegacyRouteSetTests < Test::Unit::TestCase :to => lambda { |env| [200, {}, 'clients'] } end - body = @rs.call({'PATH_INFO' => '/', - 'REQUEST_METHOD' => 'GET', - 'HTTP_HOST' => 'www.example.org'})[2] - - assert_equal 'default', body - - body = @rs.call({'PATH_INFO' => '/', - 'REQUEST_METHOD' => 'GET', - 'HTTP_HOST' => 'clients.example.org'})[2] - - assert_equal 'clients', body + assert_equal 'default', get(URI('http://www.example.org/')) + assert_equal 'clients', get(URI('http://clients.example.org/')) end def test_draw_with_block_arity_one_raises -- cgit v1.2.3 From 3f92e5e40720bd3c00935b2df42d9c781248b9e7 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 22 Dec 2011 13:09:43 -0700 Subject: rack bodies should be a list --- actionpack/test/controller/routing_test.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index d6ae9909b8..715cc229e1 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -90,16 +90,16 @@ class LegacyRouteSetTests < Test::Unit::TestCase 'REQUEST_METHOD' => 'GET', 'HTTP_HOST' => host} - @rs.call(params)[2] + @rs.call(params)[2].join end def test_regexp_precidence @rs.draw do match '/whois/:domain', :constraints => { :domain => /\w+\.[\w\.]+/ }, - :to => lambda { |env| [200, {}, 'regexp'] } + :to => lambda { |env| [200, {}, %w{regexp}] } - match '/whois/:id', :to => lambda { |env| [200, {}, 'id'] } + match '/whois/:id', :to => lambda { |env| [200, {}, %w{id}] } end assert_equal 'regexp', get(URI('http://example.org/whois/example.org')) @@ -115,9 +115,9 @@ class LegacyRouteSetTests < Test::Unit::TestCase @rs.draw do match '/', :constraints => subdomain.new, - :to => lambda { |env| [200, {}, 'default'] } + :to => lambda { |env| [200, {}, %w{default}] } match '/', :constraints => { :subdomain => 'clients' }, - :to => lambda { |env| [200, {}, 'clients'] } + :to => lambda { |env| [200, {}, %w{clients}] } end assert_equal 'default', get(URI('http://www.example.org/')) @@ -128,11 +128,11 @@ class LegacyRouteSetTests < Test::Unit::TestCase @rs.draw do match '/', :constraints => lambda { |req| req.subdomain.present? and req.subdomain != "clients" }, - :to => lambda { |env| [200, {}, 'default'] } + :to => lambda { |env| [200, {}, %w{default}] } match '/', :constraints => lambda { |req| req.subdomain.present? && req.subdomain == "clients" }, - :to => lambda { |env| [200, {}, 'clients'] } + :to => lambda { |env| [200, {}, %w{clients}] } end assert_equal 'default', get(URI('http://www.example.org/')) -- cgit v1.2.3 From 4ee537a8a21ecab2a4d0c8e6a6730a72a7937428 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 22 Dec 2011 18:04:22 -0700 Subject: Adding an integration test. Fixes #4136 --- actionpack/test/controller/routing_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 715cc229e1..715010d7f7 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -139,6 +139,15 @@ class LegacyRouteSetTests < Test::Unit::TestCase assert_equal 'clients', get(URI('http://clients.example.org/')) end + def test_empty_string_match + rs.draw do + get '/:username', :constraints => { :username => /[^\/]+/ }, + :to => lambda { |e| [200, {}, ['foo']] } + end + assert_equal 'Not Found', get(URI('http://example.org/')) + assert_equal 'foo', get(URI('http://example.org/hello')) + end + def test_draw_with_block_arity_one_raises assert_raise(RuntimeError) do @rs.draw { |map| map.match '/:controller(/:action(/:id))' } -- cgit v1.2.3 From ead2593a54223498647555171e930f9cbe08759c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 22 Dec 2011 18:52:42 -0700 Subject: adding an integration test for splat regexp substitutions. fixes #4138 --- actionpack/test/controller/routing_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 715010d7f7..53a50898c5 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -148,6 +148,19 @@ class LegacyRouteSetTests < Test::Unit::TestCase assert_equal 'foo', get(URI('http://example.org/hello')) end + def test_non_greedy_glob_regexp + params = nil + rs.draw do + get '/posts/:id(/*filters)', :constraints => { :filters => /.+?/ }, + :to => lambda { |e| + params = e["action_dispatch.request.path_parameters"] + [200, {}, ['foo']] + } + end + assert_equal 'foo', get(URI('http://example.org/posts/1/foo.js')) + assert_equal({:id=>"1", :filters=>"foo", :format=>"js"}, params) + end + def test_draw_with_block_arity_one_raises assert_raise(RuntimeError) do @rs.draw { |map| map.match '/:controller(/:action(/:id))' } -- cgit v1.2.3 From 131c9ba9d00f49e3b52bf606ca60317c28b4ce6a Mon Sep 17 00:00:00 2001 From: "Karunakar (Ruby)" Date: Sat, 24 Dec 2011 00:17:21 +0530 Subject: Moving to logger methods to ActiveSupport Logger --- actionpack/test/controller/addresses_render_test.rb | 4 ++-- actionpack/test/controller/base_test.rb | 4 ++-- actionpack/test/controller/capture_test.rb | 4 ++-- actionpack/test/controller/render_json_test.rb | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/addresses_render_test.rb b/actionpack/test/controller/addresses_render_test.rb index c1cd22113d..0b5f2d7679 100644 --- a/actionpack/test/controller/addresses_render_test.rb +++ b/actionpack/test/controller/addresses_render_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'logger' +require 'active_support/logger' require 'controller/fake_controllers' class Address @@ -23,7 +23,7 @@ class AddressesTest < ActionController::TestCase super # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get # a more accurate simulation of what happens in "real life". - @controller.logger = Logger.new(nil) + @controller.logger = ActiveSupport::Logger.new(nil) @request.host = "www.nextangle.com" end diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 9c22a4e7e0..a4f858d06d 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'logger' +require 'active_support/logger' require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late # Provide some controller to run the tests on. @@ -142,7 +142,7 @@ class PerformActionTest < ActionController::TestCase # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get # a more accurate simulation of what happens in "real life". - @controller.logger = Logger.new(nil) + @controller.logger = ActiveSupport::Logger.new(nil) @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new diff --git a/actionpack/test/controller/capture_test.rb b/actionpack/test/controller/capture_test.rb index d78acb8ce8..a217510434 100644 --- a/actionpack/test/controller/capture_test.rb +++ b/actionpack/test/controller/capture_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'logger' +require 'active_support/logger' class CaptureController < ActionController::Base def self.controller_name; "test"; end @@ -39,7 +39,7 @@ class CaptureTest < ActionController::TestCase super # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get # a more accurate simulation of what happens in "real life". - @controller.logger = Logger.new(nil) + @controller.logger = ActiveSupport::Logger.new(nil) @request.host = "www.nextangle.com" end diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb index fc604a2db3..75fed8e933 100644 --- a/actionpack/test/controller/render_json_test.rb +++ b/actionpack/test/controller/render_json_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'controller/fake_models' +require 'active_support/logger' require 'pathname' class RenderJsonTest < ActionController::TestCase @@ -69,7 +70,7 @@ class RenderJsonTest < ActionController::TestCase # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get # a more accurate simulation of what happens in "real life". super - @controller.logger = Logger.new(nil) + @controller.logger = ActiveSupport::Logger.new(nil) @request.host = "www.nextangle.com" end -- cgit v1.2.3 From f7669cd8344a83485d01f94e7b5896616cd57f51 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sat, 24 Dec 2011 00:44:23 +0300 Subject: add ability to set a prompt string in include_blank option for date helpers, closes #4143 --- actionpack/test/template/date_helper_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index fadfb59572..21c9083386 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1581,6 +1581,26 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, date_select("post", "written_on", :include_blank => true) end + def test_date_select_with_stringified_blank + @post = Post.new + + start_year = Time.now.year-5 + end_year = Time.now.year+5 + + expected = '' + "\n" + expected << %{\n" + + expected << %{\n" + + assert_dom_equal expected, date_select("post", "written_on", :order=>[:year, :month], :include_blank=> 'blank') + end + def test_date_select_with_nil_and_blank_and_order @post = Post.new -- cgit v1.2.3 From 7b1ac55f50bd580a8a9c6e9bfa8b178f1ab6f443 Mon Sep 17 00:00:00 2001 From: "Andrey A.I. Sitnik" Date: Fri, 23 Dec 2011 21:29:49 +0700 Subject: Gzip files on page caching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/test/controller/caching_test.rb | 41 +++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 015e6b9955..dfebb29da3 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -17,6 +17,9 @@ class PageCachingTestController < CachingController caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? } caches_page :found, :not_found caches_page :about_me + caches_page :default_gzip + caches_page :no_gzip, :gzip => false + caches_page :gzip_level, :gzip => :best_speed def ok @@ -40,6 +43,18 @@ class PageCachingTestController < CachingController cache_page("Super soaker", "/index.html") end + def default_gzip + render :text => "Text" + end + + def no_gzip + render :text => "PNG" + end + + def gzip_level + render :text => "Big text" + end + def expire_custom_path expire_page("/index.html") head :ok @@ -115,6 +130,30 @@ class PageCachingTest < ActionController::TestCase assert !File.exist?("#{FILE_STORE_PATH}/index.html") end + def test_should_gzip_cache + get :custom_path + assert File.exist?("#{FILE_STORE_PATH}/index.html.gz") + + get :expire_custom_path + assert !File.exist?("#{FILE_STORE_PATH}/index.html.gz") + end + + def test_should_allow_to_disable_gzip + get :no_gzip + assert File.exist?("#{FILE_STORE_PATH}/page_caching_test/no_gzip.html") + assert !File.exist?("#{FILE_STORE_PATH}/page_caching_test/no_gzip.html.gz") + end + + def test_should_use_best_gzip_by_default + @controller.expects(:cache_page).with(nil, nil, Zlib::BEST_COMPRESSION) + get :default_gzip + end + + def test_should_set_gzip_level + @controller.expects(:cache_page).with(nil, nil, Zlib::BEST_SPEED) + get :gzip_level + end + def test_should_cache_without_trailing_slash_on_url @controller.class.cache_page 'cached content', '/page_caching_test/trailing_slash' assert File.exist?("#{FILE_STORE_PATH}/page_caching_test/trailing_slash.html") @@ -224,7 +263,7 @@ class ActionCachingTestController < CachingController @cache_this = MockTime.now.to_f.to_s render :text => @cache_this end - + def record_not_found raise ActiveRecord::RecordNotFound, "oops!" end -- cgit v1.2.3 From 39081f166023092041605144c87d7a6cd3b65102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 24 Dec 2011 09:54:29 +0100 Subject: Provide a class optin for page_cache_compression. --- actionpack/test/controller/caching_test.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index dfebb29da3..34a38a5567 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -14,6 +14,8 @@ class CachingController < ActionController::Base end class PageCachingTestController < CachingController + self.page_cache_compression = :best_compression + caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? } caches_page :found, :not_found caches_page :about_me @@ -21,7 +23,6 @@ class PageCachingTestController < CachingController caches_page :no_gzip, :gzip => false caches_page :gzip_level, :gzip => :best_speed - def ok head :ok end @@ -144,7 +145,7 @@ class PageCachingTest < ActionController::TestCase assert !File.exist?("#{FILE_STORE_PATH}/page_caching_test/no_gzip.html.gz") end - def test_should_use_best_gzip_by_default + def test_should_use_config_gzip_by_default @controller.expects(:cache_page).with(nil, nil, Zlib::BEST_COMPRESSION) get :default_gzip end @@ -233,7 +234,7 @@ class ActionCachingTestController < CachingController caches_action :show, :cache_path => 'http://test.host/custom/show' caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" } caches_action :with_layout - caches_action :with_format_and_http_param, :cache_path => Proc.new { |c| { :key => 'value' } } + caches_action :with_format_and_http_param, :cache_path => Proc.new { |c| { :key => 'value' } } caches_action :layout_false, :layout => false caches_action :record_not_found, :four_oh_four, :simple_runtime_error -- cgit v1.2.3 From 58f69ba085542bf99ae6cdd34ddf62cb847aceed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 24 Dec 2011 11:28:05 +0100 Subject: Remove Rescue middleware that was never used by Rails. --- actionpack/test/controller/rescue_test.rb | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index c445285538..86d6737cbb 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -338,23 +338,8 @@ class RescueTest < ActionDispatch::IntegrationTest end end - test 'rescue routing exceptions' do - raiser = proc { |env| raise ActionController::RoutingError, "Did not handle the request" } - @app = ActionDispatch::Rescue.new(raiser) do - rescue_from ActionController::RoutingError, lambda { |env| [200, {"Content-Type" => "text/html"}, ["Gotcha!"]] } - end - - get '/b00m' - assert_equal "Gotcha!", response.body - end - - test 'unrescued exception' do - raiser = proc { |env| raise ActionController::RoutingError, "Did not handle the request" } - @app = ActionDispatch::Rescue.new(raiser) - assert_raise(ActionController::RoutingError) { get '/b00m' } - end - private + def with_test_routing with_routing do |set| set.draw do -- cgit v1.2.3 From 5ca86ac8f924b333a5a01a47cc07cbcf39c16e80 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Sat, 24 Dec 2011 15:57:54 +0300 Subject: deprecate String#encoding_aware? and remove its usage --- actionpack/test/abstract_unit.rb | 13 ++- .../request/url_encoded_params_parsing_test.rb | 2 - actionpack/test/dispatch/response_test.rb | 3 - actionpack/test/dispatch/uploaded_file_test.rb | 8 +- actionpack/test/template/javascript_helper_test.rb | 6 +- actionpack/test/template/template_test.rb | 98 +++++++++++----------- 6 files changed, 57 insertions(+), 73 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 40ca23a39d..63109d592a 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -14,14 +14,11 @@ ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') require 'active_support/core_ext/kernel/reporting' -require 'active_support/core_ext/string/encoding' -if "ruby".encoding_aware? - # These are the normal settings that will be set up by Railties - # TODO: Have these tests support other combinations of these values - silence_warnings do - Encoding.default_internal = "UTF-8" - Encoding.default_external = "UTF-8" - end +# These are the normal settings that will be set up by Railties +# TODO: Have these tests support other combinations of these values +silence_warnings do + Encoding.default_internal = "UTF-8" + Encoding.default_external = "UTF-8" end require 'test/unit' diff --git a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb index 04a0fb6f34..05569561d2 100644 --- a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb @@ -146,8 +146,6 @@ class UrlEncodedParamsParsingTest < ActionDispatch::IntegrationTest end def assert_utf8(object) - return unless "ruby".encoding_aware? - correct_encoding = Encoding.default_internal unless object.is_a?(Hash) diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 9bdd5ecbc6..82d1200f8e 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -6,9 +6,6 @@ class ResponseTest < ActiveSupport::TestCase end def test_response_body_encoding - # FIXME: remove this conditional on Rails 4.0 - return unless "<3".encoding_aware? - body = ["hello".encode('utf-8')] response = ActionDispatch::Response.new 200, {}, body assert_equal Encoding::UTF_8, response.body.encoding diff --git a/actionpack/test/dispatch/uploaded_file_test.rb b/actionpack/test/dispatch/uploaded_file_test.rb index 7e4a1519fb..0b95291e18 100644 --- a/actionpack/test/dispatch/uploaded_file_test.rb +++ b/actionpack/test/dispatch/uploaded_file_test.rb @@ -13,11 +13,9 @@ module ActionDispatch assert_equal 'foo', uf.original_filename end - if "ruby".encoding_aware? - def test_filename_should_be_in_utf_8 - uf = Http::UploadedFile.new(:filename => 'foo', :tempfile => Object.new) - assert_equal "UTF-8", uf.original_filename.encoding.to_s - end + def test_filename_should_be_in_utf_8 + uf = Http::UploadedFile.new(:filename => 'foo', :tempfile => Object.new) + assert_equal "UTF-8", uf.original_filename.encoding.to_s end def test_content_type diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index 4b9c3c97b1..d98ffe8fa7 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -28,11 +28,7 @@ class JavaScriptHelperTest < ActionView::TestCase assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos')) assert_equal %(backslash\\\\test), escape_javascript( %(backslash\\test) ) assert_equal %(dont <\\/close> tags), escape_javascript(%(dont tags)) - if "ruby".encoding_aware? - assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\250 newline).force_encoding('UTF-8').encode!) - else - assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\250 newline)) - end + assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\250 newline).force_encoding('UTF-8').encode!) assert_equal %(dont <\\/close> tags), j(%(dont tags)) end diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 13d30a93ce..f9c228f0c3 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -114,67 +114,65 @@ class TestERBTemplate < ActiveSupport::TestCase end end - if "ruby".encoding_aware? - def test_resulting_string_is_utf8 - @template = new_template - assert_equal Encoding::UTF_8, render.encoding - end + def test_resulting_string_is_utf8 + @template = new_template + assert_equal Encoding::UTF_8, render.encoding + end + + def test_no_magic_comment_word_with_utf_8 + @template = new_template("hello \u{fc}mlat") + assert_equal Encoding::UTF_8, render.encoding + assert_equal "hello \u{fc}mlat", render + end - def test_no_magic_comment_word_with_utf_8 - @template = new_template("hello \u{fc}mlat") + # This test ensures that if the default_external + # is set to something other than UTF-8, we don't + # get any errors and get back a UTF-8 String. + def test_default_external_works + with_external_encoding "ISO-8859-1" do + @template = new_template("hello \xFCmlat") assert_equal Encoding::UTF_8, render.encoding assert_equal "hello \u{fc}mlat", render end + end - # This test ensures that if the default_external - # is set to something other than UTF-8, we don't - # get any errors and get back a UTF-8 String. - def test_default_external_works - with_external_encoding "ISO-8859-1" do - @template = new_template("hello \xFCmlat") - assert_equal Encoding::UTF_8, render.encoding - assert_equal "hello \u{fc}mlat", render - end - end - - def test_encoding_can_be_specified_with_magic_comment - @template = new_template("# encoding: ISO-8859-1\nhello \xFCmlat") - assert_equal Encoding::UTF_8, render.encoding - assert_equal "\nhello \u{fc}mlat", render - end + def test_encoding_can_be_specified_with_magic_comment + @template = new_template("# encoding: ISO-8859-1\nhello \xFCmlat") + assert_equal Encoding::UTF_8, render.encoding + assert_equal "\nhello \u{fc}mlat", render + end - # TODO: This is currently handled inside ERB. The case of explicitly - # lying about encodings via the normal Rails API should be handled - # inside Rails. - def test_lying_with_magic_comment - assert_raises(ActionView::Template::Error) do - @template = new_template("# encoding: UTF-8\nhello \xFCmlat", :virtual_path => nil) - render - end + # TODO: This is currently handled inside ERB. The case of explicitly + # lying about encodings via the normal Rails API should be handled + # inside Rails. + def test_lying_with_magic_comment + assert_raises(ActionView::Template::Error) do + @template = new_template("# encoding: UTF-8\nhello \xFCmlat", :virtual_path => nil) + render end + end - def test_encoding_can_be_specified_with_magic_comment_in_erb - with_external_encoding Encoding::UTF_8 do - @template = new_template("<%# encoding: ISO-8859-1 %>hello \xFCmlat", :virtual_path => nil) - assert_equal Encoding::UTF_8, render.encoding - assert_equal "hello \u{fc}mlat", render - end + def test_encoding_can_be_specified_with_magic_comment_in_erb + with_external_encoding Encoding::UTF_8 do + @template = new_template("<%# encoding: ISO-8859-1 %>hello \xFCmlat", :virtual_path => nil) + assert_equal Encoding::UTF_8, render.encoding + assert_equal "hello \u{fc}mlat", render end + end - def test_error_when_template_isnt_valid_utf8 - assert_raises(ActionView::Template::Error, /\xFC/) do - @template = new_template("hello \xFCmlat", :virtual_path => nil) - render - end + def test_error_when_template_isnt_valid_utf8 + assert_raises(ActionView::Template::Error, /\xFC/) do + @template = new_template("hello \xFCmlat", :virtual_path => nil) + render end + end - def with_external_encoding(encoding) - old = Encoding.default_external - Encoding::Converter.new old, encoding if old != encoding - silence_warnings { Encoding.default_external = encoding } - yield - ensure - silence_warnings { Encoding.default_external = old } - end + def with_external_encoding(encoding) + old = Encoding.default_external + Encoding::Converter.new old, encoding if old != encoding + silence_warnings { Encoding.default_external = encoding } + yield + ensure + silence_warnings { Encoding.default_external = old } end end -- cgit v1.2.3 From 1e9e88fcd335c7d5a99159d592c3e1b605510a16 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Sun, 25 Dec 2011 14:34:58 +0300 Subject: remove checks for encodings availability --- actionpack/test/controller/routing_test.rb | 2 +- actionpack/test/controller/send_file_test.rb | 2 +- actionpack/test/controller/test_test.rb | 2 +- .../request/multipart_params_parsing_test.rb | 2 +- actionpack/test/template/output_buffer_test.rb | 16 +++-- actionpack/test/template/render_test.rb | 70 +++++++++++----------- 6 files changed, 45 insertions(+), 49 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 53a50898c5..c9785d9b8a 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -483,7 +483,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase assert_equal({ :controller => "content", :action => 'show_page', :id => 'foo' }, rs.recognize_path("/page/foo")) token = "\321\202\320\265\320\272\321\201\321\202" # 'text' in Russian - token.force_encoding(Encoding::BINARY) if token.respond_to?(:force_encoding) + token.force_encoding(Encoding::BINARY) escaped_token = CGI::escape(token) assert_equal '/page/' + escaped_token, url_for(rs, { :controller => 'content', :action => 'show_page', :id => token }) diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 8f885ff28e..36884846be 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -61,7 +61,7 @@ class SendFileTest < ActionController::TestCase require 'stringio' output = StringIO.new output.binmode - output.string.force_encoding(file_data.encoding) if output.string.respond_to?(:force_encoding) + output.string.force_encoding(file_data.encoding) assert_nothing_raised { response.body_parts.each { |part| output << part.to_s } } assert_equal file_data, output.string end diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index 0e75a23cfd..b3b7ece518 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -673,7 +673,7 @@ XML path = "#{FILES_DIR}/#{filename}" content_type = 'image/png' expected = File.read(path) - expected.force_encoding(Encoding::BINARY) if expected.respond_to?(:force_encoding) + expected.force_encoding(Encoding::BINARY) file = Rack::Test::UploadedFile.new(path, content_type) assert_equal filename, file.original_filename diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index 560ea00923..d144f013f5 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -89,7 +89,7 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest # Rack doesn't handle multipart/mixed for us. files = params['files'] - files.force_encoding('ASCII-8BIT') if files.respond_to?(:force_encoding) + files.force_encoding('ASCII-8BIT') assert_equal 19756, files.size end diff --git a/actionpack/test/template/output_buffer_test.rb b/actionpack/test/template/output_buffer_test.rb index bd49a11af1..eb0df3d1ab 100644 --- a/actionpack/test/template/output_buffer_test.rb +++ b/actionpack/test/template/output_buffer_test.rb @@ -39,15 +39,13 @@ class OutputBufferTest < ActionController::TestCase assert_equal ['foo', 'bar'], body_parts end - if '1.9'.respond_to?(:force_encoding) - test 'flushing preserves output buffer encoding' do - original_buffer = ' '.force_encoding(Encoding::EUC_JP) - @vc.output_buffer = original_buffer - @vc.flush_output_buffer - assert_equal ['foo', original_buffer], body_parts - assert_not_equal original_buffer, output_buffer - assert_equal Encoding::EUC_JP, output_buffer.encoding - end + test 'flushing preserves output buffer encoding' do + original_buffer = ' '.force_encoding(Encoding::EUC_JP) + @vc.output_buffer = original_buffer + @vc.flush_output_buffer + assert_equal ['foo', original_buffer], body_parts + assert_not_equal original_buffer, output_buffer + assert_equal Encoding::EUC_JP, output_buffer.encoding end protected diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 761bcf61f2..5d3dc73ed2 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -410,51 +410,49 @@ class LazyViewRenderTest < ActiveSupport::TestCase GC.start end - if '1.9'.respond_to?(:force_encoding) - def test_render_utf8_template_with_magic_comment - with_external_encoding Encoding::ASCII_8BIT do - result = @view.render(:file => "test/utf8_magic", :formats => [:html], :layouts => "layouts/yield") - assert_equal Encoding::UTF_8, result.encoding - assert_equal "\nРусский \nтекст\n\nUTF-8\nUTF-8\nUTF-8\n", result - end + def test_render_utf8_template_with_magic_comment + with_external_encoding Encoding::ASCII_8BIT do + result = @view.render(:file => "test/utf8_magic", :formats => [:html], :layouts => "layouts/yield") + assert_equal Encoding::UTF_8, result.encoding + assert_equal "\nРусский \nтекст\n\nUTF-8\nUTF-8\nUTF-8\n", result end + end - def test_render_utf8_template_with_default_external_encoding - with_external_encoding Encoding::UTF_8 do - result = @view.render(:file => "test/utf8", :formats => [:html], :layouts => "layouts/yield") - assert_equal Encoding::UTF_8, result.encoding - assert_equal "Русский текст\n\nUTF-8\nUTF-8\nUTF-8\n", result - end + def test_render_utf8_template_with_default_external_encoding + with_external_encoding Encoding::UTF_8 do + result = @view.render(:file => "test/utf8", :formats => [:html], :layouts => "layouts/yield") + assert_equal Encoding::UTF_8, result.encoding + assert_equal "Русский текст\n\nUTF-8\nUTF-8\nUTF-8\n", result end + end - def test_render_utf8_template_with_incompatible_external_encoding - with_external_encoding Encoding::SHIFT_JIS do - begin - @view.render(:file => "test/utf8", :formats => [:html], :layouts => "layouts/yield") - flunk 'Should have raised incompatible encoding error' - rescue ActionView::Template::Error => error - assert_match 'Your template was not saved as valid Shift_JIS', error.original_exception.message - end + def test_render_utf8_template_with_incompatible_external_encoding + with_external_encoding Encoding::SHIFT_JIS do + begin + @view.render(:file => "test/utf8", :formats => [:html], :layouts => "layouts/yield") + flunk 'Should have raised incompatible encoding error' + rescue ActionView::Template::Error => error + assert_match 'Your template was not saved as valid Shift_JIS', error.original_exception.message end end + end - def test_render_utf8_template_with_partial_with_incompatible_encoding - with_external_encoding Encoding::SHIFT_JIS do - begin - @view.render(:file => "test/utf8_magic_with_bare_partial", :formats => [:html], :layouts => "layouts/yield") - flunk 'Should have raised incompatible encoding error' - rescue ActionView::Template::Error => error - assert_match 'Your template was not saved as valid Shift_JIS', error.original_exception.message - end + def test_render_utf8_template_with_partial_with_incompatible_encoding + with_external_encoding Encoding::SHIFT_JIS do + begin + @view.render(:file => "test/utf8_magic_with_bare_partial", :formats => [:html], :layouts => "layouts/yield") + flunk 'Should have raised incompatible encoding error' + rescue ActionView::Template::Error => error + assert_match 'Your template was not saved as valid Shift_JIS', error.original_exception.message end end + end - def with_external_encoding(encoding) - old = Encoding.default_external - silence_warnings { Encoding.default_external = encoding } - yield - ensure - silence_warnings { Encoding.default_external = old } - end + def with_external_encoding(encoding) + old = Encoding.default_external + silence_warnings { Encoding.default_external = encoding } + yield + ensure + silence_warnings { Encoding.default_external = old } end end -- cgit v1.2.3 From 719ba0b6bb0653da3f35ed55557d7c3f034c092a Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 26 Dec 2011 13:56:47 +0100 Subject: Revert "Merge pull request #4154 from nashby/include-blank-date-helper" This reverts commit 76f0fa6066b78cd8f0e139dff4a7b65c96db5778, reversing changes made to 28cd098d99c52486aecb72aab39105d8abcd52ad. --- actionpack/test/template/date_helper_test.rb | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 21c9083386..fadfb59572 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1581,26 +1581,6 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, date_select("post", "written_on", :include_blank => true) end - def test_date_select_with_stringified_blank - @post = Post.new - - start_year = Time.now.year-5 - end_year = Time.now.year+5 - - expected = '' + "\n" - expected << %{\n" - - expected << %{\n" - - assert_dom_equal expected, date_select("post", "written_on", :order=>[:year, :month], :include_blank=> 'blank') - end - def test_date_select_with_nil_and_blank_and_order @post = Post.new -- cgit v1.2.3 From ffad4927b1803765fca78241d2f368c33888c048 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 28 Dec 2011 18:21:35 -0800 Subject: mutations can't be done without the consent of our proxy object. This is one benefit of choosing composition over inheritance. --- actionpack/test/controller/flash_hash_test.rb | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/flash_hash_test.rb b/actionpack/test/controller/flash_hash_test.rb index 9b69a2648e..e7ae7ce5f5 100644 --- a/actionpack/test/controller/flash_hash_test.rb +++ b/actionpack/test/controller/flash_hash_test.rb @@ -75,6 +75,7 @@ module ActionDispatch def test_discard_no_args @hash['hello'] = 'world' @hash.discard + @hash.sweep assert_equal({}, @hash.to_hash) end @@ -83,8 +84,69 @@ module ActionDispatch @hash['hello'] = 'world' @hash['omg'] = 'world' @hash.discard 'hello' + @hash.sweep assert_equal({'omg' => 'world'}, @hash.to_hash) end + + def test_keep_sweep + @hash['hello'] = 'world' + + @hash.sweep + assert_equal({'hello' => 'world'}, @hash.to_hash) + end + + def test_update_sweep + @hash['hello'] = 'world' + @hash.update({'hi' => 'mom'}) + + @hash.sweep + assert_equal({'hello' => 'world', 'hi' => 'mom'}, @hash.to_hash) + end + + def test_delete_sweep + @hash['hello'] = 'world' + @hash['hi'] = 'mom' + @hash.delete 'hi' + + @hash.sweep + assert_equal({'hello' => 'world'}, @hash.to_hash) + end + + def test_clear_sweep + @hash['hello'] = 'world' + @hash.clear + + @hash.sweep + assert_equal({}, @hash.to_hash) + end + + def test_replace_sweep + @hash['hello'] = 'world' + @hash.replace({'hi' => 'mom'}) + + @hash.sweep + assert_equal({'hi' => 'mom'}, @hash.to_hash) + end + + def test_discard_then_add + @hash['hello'] = 'world' + @hash['omg'] = 'world' + @hash.discard 'hello' + @hash['hello'] = 'world' + + @hash.sweep + assert_equal({'omg' => 'world', 'hello' => 'world'}, @hash.to_hash) + end + + def test_keep_all_sweep + @hash['hello'] = 'world' + @hash['omg'] = 'world' + @hash.discard 'hello' + @hash.keep + + @hash.sweep + assert_equal({'omg' => 'world', 'hello' => 'world'}, @hash.to_hash) + end end end -- cgit v1.2.3 From bdfd11e6dafb1fac175fa0e7283be31e8849ec67 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 28 Dec 2011 18:33:44 -0800 Subject: mutations on the underlying hash should also mutate the discard set --- actionpack/test/controller/flash_hash_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/flash_hash_test.rb b/actionpack/test/controller/flash_hash_test.rb index e7ae7ce5f5..ccca0dac17 100644 --- a/actionpack/test/controller/flash_hash_test.rb +++ b/actionpack/test/controller/flash_hash_test.rb @@ -104,6 +104,15 @@ module ActionDispatch assert_equal({'hello' => 'world', 'hi' => 'mom'}, @hash.to_hash) end + def test_update_delete_sweep + @hash['hello'] = 'world' + @hash.delete 'hello' + @hash.update({'hello' => 'mom'}) + + @hash.sweep + assert_equal({'hello' => 'mom'}, @hash.to_hash) + end + def test_delete_sweep @hash['hello'] = 'world' @hash['hi'] = 'mom' @@ -148,5 +157,15 @@ module ActionDispatch @hash.sweep assert_equal({'omg' => 'world', 'hello' => 'world'}, @hash.to_hash) end + + def test_double_sweep + @hash['hello'] = 'world' + @hash.sweep + + assert_equal({'hello' => 'world'}, @hash.to_hash) + + @hash.sweep + assert_equal({}, @hash.to_hash) + end end end -- cgit v1.2.3 From 8a130edb0f7b3aacf74d080d3da3b2d871f650d6 Mon Sep 17 00:00:00 2001 From: grentis Date: Thu, 29 Dec 2011 21:58:55 +0100 Subject: content_for with flush parameter --- actionpack/test/template/capture_helper_test.rb | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/capture_helper_test.rb b/actionpack/test/template/capture_helper_test.rb index a37e3a8d6a..17469f8c3e 100644 --- a/actionpack/test/template/capture_helper_test.rb +++ b/actionpack/test/template/capture_helper_test.rb @@ -53,6 +53,13 @@ class CaptureHelperTest < ActionView::TestCase assert_equal 'foobar', content_for(:title) end + def test_content_for_with_multiple_calls_and_flush + assert ! content_for?(:title) + content_for :title, 'foo' + content_for :title, 'bar', true + assert_equal 'bar', content_for(:title) + end + def test_content_for_with_block assert ! content_for?(:title) content_for :title do @@ -63,6 +70,39 @@ class CaptureHelperTest < ActionView::TestCase assert_equal 'foobar', content_for(:title) end + def test_content_for_with_block_and_multiple_calls_with_flush + assert ! content_for?(:title) + content_for :title do + 'foo' + end + content_for :title, true do + 'bar' + end + assert_equal 'bar', content_for(:title) + end + + def test_content_for_with_block_and_multiple_calls_with_flush_nil_content + assert ! content_for?(:title) + content_for :title do + 'foo' + end + content_for :title, nil, true do + 'bar' + end + assert_equal 'bar', content_for(:title) + end + + def test_content_for_with_block_and_multiple_calls_without_flush + assert ! content_for?(:title) + content_for :title do + 'foo' + end + content_for :title, false do + 'bar' + end + assert_equal 'foobar', content_for(:title) + end + def test_content_for_with_whitespace_block assert ! content_for?(:title) content_for :title, 'foo' @@ -74,12 +114,27 @@ class CaptureHelperTest < ActionView::TestCase assert_equal 'foobar', content_for(:title) end + def test_content_for_with_whitespace_block_and_flush + assert ! content_for?(:title) + content_for :title, 'foo' + content_for :title, true do + output_buffer << " \n " + nil + end + content_for :title, 'bar', true + assert_equal 'bar', content_for(:title) + end + def test_content_for_returns_nil_when_writing assert ! content_for?(:title) assert_equal nil, content_for(:title, 'foo') assert_equal nil, content_for(:title) { output_buffer << 'bar'; nil } assert_equal nil, content_for(:title) { output_buffer << " \n "; nil } assert_equal 'foobar', content_for(:title) + assert_equal nil, content_for(:title, 'foo', true) + assert_equal nil, content_for(:title, true) { output_buffer << 'bar'; nil } + assert_equal nil, content_for(:title, true) { output_buffer << " \n "; nil } + assert_equal 'bar', content_for(:title) end def test_content_for_question_mark -- cgit v1.2.3 From 5681f79f642c57397bf18d239a9aa1dbf71b0f24 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 29 Dec 2011 17:27:10 -0800 Subject: be explicit about where helpers are installed --- actionpack/test/controller/action_pack_assertions_test.rb | 2 +- 1 file changed, 1 insertion(+), 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 5252e43c25..fab70c71d6 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -165,7 +165,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase match 'route_one', :to => 'action_pack_assertions#nothing', :as => :route_one match ':controller/:action' end - set.install_helpers + set.install_helpers([ActionController::Base, ActionView::Base]) process :redirect_to_named_route assert_redirected_to 'http://test.host/route_one' -- cgit v1.2.3