From 31c3eec05d2ad50f93f3e7a7bc30ec33f2a5c768 Mon Sep 17 00:00:00 2001 From: Earl St Sauver Date: Tue, 29 Apr 2014 18:26:16 -0700 Subject: Propagate test messages through assert_routing helper, Fixes #14908 assert_routing was not raising the message passed into the assertion violation that it raised. This change propagates messages through the on_fail error. This fixes this error: https://github.com/rails/rails/issues/14908 A test case for this issue is located here. https://github.com/estsauver/test14908 To see that test case fail in the example app, just run ruby -Itest test/controllers/guests_controller_test.rb --- .../lib/action_dispatch/testing/assertions/routing.rb | 14 +++++++------- actionpack/test/dispatch/routing_assertions_test.rb | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index f1f998d932..dfba01b931 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -38,7 +38,7 @@ module ActionDispatch # # Test a custom route # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1') def assert_recognizes(expected_options, path, extras={}, msg=nil) - request = recognized_request_for(path, extras) + request = recognized_request_for(path, extras, msg) expected_options = expected_options.clone @@ -71,7 +71,7 @@ module ActionDispatch # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" } def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil) if expected_path =~ %r{://} - fail_on(URI::InvalidURIError) do + fail_on(URI::InvalidURIError, message) do uri = URI.parse(expected_path) expected_path = uri.path.to_s.empty? ? "/" : uri.path end @@ -174,7 +174,7 @@ module ActionDispatch private # Recognizes the route for a given path. - def recognized_request_for(path, extras = {}) + def recognized_request_for(path, extras = {}, msg) if path.is_a?(Hash) method = path[:method] path = path[:path] @@ -186,7 +186,7 @@ module ActionDispatch request = ActionController::TestRequest.new if path =~ %r{://} - fail_on(URI::InvalidURIError) do + fail_on(URI::InvalidURIError, msg) do uri = URI.parse(path) request.env["rack.url_scheme"] = uri.scheme || "http" request.host = uri.host if uri.host @@ -200,7 +200,7 @@ module ActionDispatch request.request_method = method if method - params = fail_on(ActionController::RoutingError) do + params = fail_on(ActionController::RoutingError, msg) do @routes.recognize_path(path, { :method => method, :extras => extras }) end request.path_parameters = params.with_indifferent_access @@ -208,10 +208,10 @@ module ActionDispatch request end - def fail_on(exception_class) + def fail_on(exception_class, msg=nil) yield rescue exception_class => e - raise Minitest::Assertion, e.message + raise Minitest::Assertion, msg || e.message end end end diff --git a/actionpack/test/dispatch/routing_assertions_test.rb b/actionpack/test/dispatch/routing_assertions_test.rb index aea4489852..2116aa2746 100644 --- a/actionpack/test/dispatch/routing_assertions_test.rb +++ b/actionpack/test/dispatch/routing_assertions_test.rb @@ -78,6 +78,14 @@ class RoutingAssertionsTest < ActionController::TestCase assert_routing('/articles', :controller => 'articles', :action => 'index') end + def test_assert_routing_raises_message + err = assert_raise(Assertion) do + assert_routing('/thisIsNotARoute', { :controller => 'articles', :action => 'edit', :id => '1' }, { :id => '1' }, {}, "This is a really bad msg") + end + + assert_match err.message, "This is a really bad msg" + end + def test_assert_routing_with_defaults assert_routing('/articles/1/edit', { :controller => 'articles', :action => 'edit', :id => '1' }, { :id => '1' }) end -- cgit v1.2.3 From 6a23bf0f4c33151e0cec0648e271dc6f5ab3f686 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 19 Aug 2014 19:32:51 -0700 Subject: Preparing for 4.2.0.beta1 release --- actionpack/lib/action_pack/gem_version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_pack/gem_version.rb b/actionpack/lib/action_pack/gem_version.rb index beaf35d3da..8658069c86 100644 --- a/actionpack/lib/action_pack/gem_version.rb +++ b/actionpack/lib/action_pack/gem_version.rb @@ -8,7 +8,7 @@ module ActionPack MAJOR = 4 MINOR = 2 TINY = 0 - PRE = "alpha" + PRE = "beta1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end -- cgit v1.2.3 From b7ab73a4e21b022cf3415f6eee8018979796e466 Mon Sep 17 00:00:00 2001 From: Agis- Date: Fri, 22 Aug 2014 21:55:50 +0300 Subject: Use system /tmp when testing actionpack https://github.com/rails/rails/commit/c64bff2c87ebf363703c63ecd4a96d56a1a78364 added support and enabled parallel execution of the actionpack tests. However it introduced https://github.com/rails/rails/commit/c64bff2c87ebf363703c63ecd4a96d56a1a78364 since one cannot connect to a socket file that's inside a Vagrant synced folder due to security restrictions, and DRb tries to. Also rename the temporary files to make it obvious that they're rails-related, since now they're placed outside the project's directory. Fixes https://github.com/rails/rails/commit/c64bff2c87ebf363703c63ecd4a96d56a1a78364 --- actionpack/test/abstract_unit.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 674fb253f4..e14940d632 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -4,8 +4,6 @@ $:.unshift(File.dirname(__FILE__) + '/lib') $:.unshift(File.dirname(__FILE__) + '/fixtures/helpers') $:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers') -ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') - require 'active_support/core_ext/kernel/reporting' # These are the normal settings that will be set up by Railties @@ -466,7 +464,7 @@ class ForkingExecutor def initialize size @size = size @queue = Server.new - file = File.join Dir.tmpdir, Dir::Tmpname.make_tmpname('tests', 'fd') + file = File.join Dir.tmpdir, Dir::Tmpname.make_tmpname('rails-tests', 'fd') @url = "drbunix://#{file}" @pool = nil DRb.start_service @url, @queue -- cgit v1.2.3 From a59a9b7f729870de6c9282bd8e2a7ed7f86fc868 Mon Sep 17 00:00:00 2001 From: Peter Suschlik Date: Thu, 28 Aug 2014 09:09:04 +0200 Subject: Don't rescue IPAddr::InvalidAddressError IPAddr::InvalidAddressError does not exist in Ruby 1.9.3 and fails for JRuby in 1.9 mode. As IPAddr::InvalidAddressError is a subclass of ArgumentError (via IPAddr::Error) just rescuing ArgumentError is fine. --- actionpack/CHANGELOG.md | 7 +++++++ actionpack/lib/action_dispatch/middleware/remote_ip.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 4e8e0f41b4..e250450a76 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,10 @@ +* Don't rescue `IPAddr::InvalidAddressError`. + + `IPAddr::InvalidAddressError` does not exist in Ruby 1.9.3 + and fails for JRuby in 1.9 mode. + + *Peter Suschlik* + * Fix bug where the router would ignore any constraints added to redirect routes. diff --git a/actionpack/lib/action_dispatch/middleware/remote_ip.rb b/actionpack/lib/action_dispatch/middleware/remote_ip.rb index b022fea001..7c4236518d 100644 --- a/actionpack/lib/action_dispatch/middleware/remote_ip.rb +++ b/actionpack/lib/action_dispatch/middleware/remote_ip.rb @@ -155,7 +155,7 @@ module ActionDispatch range = IPAddr.new(ip).to_range # we want to make sure nobody is sneaking a netmask in range.begin == range.end - rescue ArgumentError, IPAddr::InvalidAddressError + rescue ArgumentError nil end end -- cgit v1.2.3 From 84c0f73c8daf50fa98d1c4a0c1bab8708e49d0e4 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Sat, 30 Aug 2014 11:58:23 +0200 Subject: Refer to the library name instead of the constant When we are loading a component and we want to know its version, we are actually not speaking about the constant but the library itself. [ci skip] [Godfrey Chan & Xavier Noria] --- actionpack/lib/action_pack/gem_version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_pack/gem_version.rb b/actionpack/lib/action_pack/gem_version.rb index 8658069c86..280d35adcb 100644 --- a/actionpack/lib/action_pack/gem_version.rb +++ b/actionpack/lib/action_pack/gem_version.rb @@ -1,5 +1,5 @@ module ActionPack - # Returns the version of the currently loaded ActionPack as a Gem::Version + # Returns the version of the currently loaded Action Pack as a Gem::Version def self.gem_version Gem::Version.new VERSION::STRING end -- cgit v1.2.3 From 2fae37f0acbb4154fe75c22a892f79e158016866 Mon Sep 17 00:00:00 2001 From: Sammy Larbi Date: Sat, 30 Aug 2014 17:19:16 -0500 Subject: Allow polymorphic routes with nil when a route can still be drawn Suppose you have two resources routed in the following manner: ```ruby resources :blogs do resources :posts end resources :posts ``` When using polymorphic resource routing like `url_for([@blog, @post])`, and `@blog` is `nil` Rails should still try to match the route to the top-level posts resource. Fixes #16754 --- actionpack/lib/action_dispatch/routing/polymorphic_routes.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 427a5674bd..f15868d37e 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -197,7 +197,8 @@ module ActionDispatch case record_or_hash_or_array when Array - if record_or_hash_or_array.empty? || record_or_hash_or_array.include?(nil) + record_or_hash_or_array = record_or_hash_or_array.compact + if record_or_hash_or_array.empty? raise ArgumentError, "Nil location provided. Can't build URI." end if record_or_hash_or_array.first.is_a?(ActionDispatch::Routing::RoutesProxy) -- cgit v1.2.3 From 2f52f969885b2834198de0045748436a4651a94e Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Tue, 2 Sep 2014 23:48:23 +0930 Subject: Leave all our tests as order_dependent! for now We're seeing too many failures to believe otherwise. This reverts commits bc116a55ca3dd9f63a1f1ca7ade3623885adcc57, cbde413df3839e06dd14e3c220e9800af91e83ab, bf0a67931dd8e58f6f878b9510ae818ae1f29a3a, and 2440933fe2c27b27bcafcd9019717800db2641aa. --- actionpack/test/abstract_unit.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index e14940d632..799c17119d 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -512,3 +512,8 @@ if ActiveSupport::Testing::Isolation.forking_env? && PROCESS_COUNT > 0 # Use N processes (N defaults to 4) Minitest.parallel_executor = ForkingExecutor.new(PROCESS_COUNT) end + +# FIXME: we have tests that depend on run order, we should fix that and +# remove this method call. +require 'active_support/test_case' +ActiveSupport::TestCase.my_tests_are_order_dependent! -- cgit v1.2.3 From 28eecd934b91618b1334acce859c26c1a380f51a Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Tue, 2 Sep 2014 21:07:41 +0200 Subject: Ship with rails-html-sanitizer instead. --- actionpack/actionpack.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec index a39b3e86d4..c752388e28 100644 --- a/actionpack/actionpack.gemspec +++ b/actionpack/actionpack.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.add_dependency 'rack', '~> 1.6.0.beta' s.add_dependency 'rack-test', '~> 0.6.2' - s.add_dependency 'rails-deprecated_sanitizer', '~> 1.0', '>= 1.0.2' + s.add_dependency 'rails-html-sanitizer', '~> 1.0' s.add_dependency 'rails-dom-testing', '~> 1.0', '>= 1.0.2' s.add_dependency 'actionview', version -- cgit v1.2.3 From 4dfe140ef3fbed34e6ae8af3b32402630a4690a1 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 4 Sep 2014 00:18:39 +0200 Subject: code gardening in ActionController::Renderers * Renames _handle_render_options to _render_to_body_with_renderer, which is more intention-revealing. * The name of the dynamically generated method for a renderer with key :js was "_render_option_js". That name is too weak. :js is an option if you see the render argument as just a generic options hash, but in the context of renderers that's the renderer key, is what identifies the renderer. Now "_render_with_renderer_js" is generated instead, which is crystal clear. * The name of the dynamically generated method for the renderer was constructed using string literals in a few places. That is now encapsulated in a method. * Since we were on it, also removed a couple of redundant selfs. --- actionpack/lib/action_controller/metal/renderers.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index 02c4e563f5..bc94536c8c 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -34,14 +34,15 @@ module ActionController end def render_to_body(options) - _handle_render_options(options) || super + _render_to_body_with_renderer(options) || super end - def _handle_render_options(options) + def _render_to_body_with_renderer(options) _renderers.each do |name| if options.key?(name) _process_options(options) - return send("_render_option_#{name}", options.delete(name), options) + method_name = Renderers._render_with_renderer_method_name(name) + return send(method_name, options.delete(name), options) end end nil @@ -51,6 +52,10 @@ module ActionController # Default values are :json, :js, :xml. RENDERERS = Set.new + def self._render_with_renderer_method_name(key) + "_render_with_renderer_#{key}" + end + # Adds a new renderer to call within controller actions. # A renderer is invoked by passing its name as an option to # AbstractController::Rendering#render. To create a renderer @@ -84,7 +89,7 @@ module ActionController # ActionController::MimeResponds::ClassMethods.respond_to and # ActionController::MimeResponds#respond_with def self.add(key, &block) - define_method("_render_option_#{key}", &block) + define_method(_render_with_renderer_method_name(key), &block) RENDERERS << key.to_sym end @@ -95,8 +100,8 @@ module ActionController # ActionController::Renderers.remove(:csv) def self.remove(key) RENDERERS.delete(key.to_sym) - method = "_render_option_#{key}" - remove_method(method) if method_defined?(method) + method_name = _render_with_renderer_method_name(key) + remove_method(method_name) if method_defined?(method_name) end module All @@ -112,7 +117,7 @@ module ActionController json = json.to_json(options) unless json.kind_of?(String) if options[:callback].present? - if self.content_type.nil? || self.content_type == Mime::JSON + if content_type.nil? || content_type == Mime::JSON self.content_type = Mime::JS end -- cgit v1.2.3 From 7025d7769dc53f0a3ffab8b537727ef3fee367fc Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Fri, 5 Sep 2014 23:32:48 +0930 Subject: For now, we will keep sorting the tests. This reverts commits e969c928463e329fd6529ac59cad96385c538ffb and bd2b3fbe54e750ba97469a7896e8d143d6dfd465. --- actionpack/Rakefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/Rakefile b/actionpack/Rakefile index cf20751687..af075f82ad 100644 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -9,7 +9,10 @@ task :default => :test # Run the unit tests Rake::TestTask.new do |t| t.libs << 'test' - t.test_files = test_files + + # make sure we include the tests in alphabetical order as on some systems + # this will not happen automatically and the tests (as a whole) will error + t.test_files = test_files.sort t.warning = true t.verbose = true -- cgit v1.2.3 From 2bb19fa7392fd572beb6c0a9b19af70780c36e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 5 Sep 2014 16:46:52 -0300 Subject: Message doesn't need to be optional --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index a0b9c9e5ba..96864ab3c5 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -208,10 +208,10 @@ module ActionDispatch request end - def fail_on(exception_class, msg=nil) + def fail_on(exception_class, message) yield rescue exception_class => e - raise Minitest::Assertion, msg || e.message + raise Minitest::Assertion, message || e.message end end end -- cgit v1.2.3 From 67117f7c5d2ece5494191e937de91d353609e963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 5 Sep 2014 16:47:00 -0300 Subject: Add test to assert_recognizes with custom message --- actionpack/test/dispatch/routing_assertions_test.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/dispatch/routing_assertions_test.rb b/actionpack/test/dispatch/routing_assertions_test.rb index 2116aa2746..56ea644f22 100644 --- a/actionpack/test/dispatch/routing_assertions_test.rb +++ b/actionpack/test/dispatch/routing_assertions_test.rb @@ -74,13 +74,21 @@ class RoutingAssertionsTest < ActionController::TestCase assert_recognizes({ :controller => 'query_articles', :action => 'index', :use_query => 'true' }, '/query/articles', { :use_query => 'true' }) end + def test_assert_recognizes_raises_message + err = assert_raise(Assertion) do + assert_recognizes({ :controller => 'secure_articles', :action => 'index' }, 'http://test.host/secure/articles', {}, "This is a really bad msg") + end + + assert_match err.message, "This is a really bad msg" + end + def test_assert_routing assert_routing('/articles', :controller => 'articles', :action => 'index') end def test_assert_routing_raises_message err = assert_raise(Assertion) do - assert_routing('/thisIsNotARoute', { :controller => 'articles', :action => 'edit', :id => '1' }, { :id => '1' }, {}, "This is a really bad msg") + assert_routing('/thisIsNotARoute', { :controller => 'articles', :action => 'edit', :id => '1' }, { :id => '1' }, {}, "This is a really bad msg") end assert_match err.message, "This is a really bad msg" -- cgit v1.2.3 From 31bfcdc77ca0d8cec9b5fe513bdc6f05814dd4f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 5 Sep 2014 16:47:57 -0300 Subject: :scissors: --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 96864ab3c5..e06f7037c6 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -69,7 +69,7 @@ module ActionDispatch # # # Asserts that the generated route gives us our custom route # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" } - def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil) + def assert_generates(expected_path, options, defaults={}, extras={}, message=nil) if expected_path =~ %r{://} fail_on(URI::InvalidURIError, message) do uri = URI.parse(expected_path) -- cgit v1.2.3 From 2a78d6f561e98684a4988cdc616c6096cd4302d1 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 5 Sep 2014 13:33:20 -0700 Subject: Deprecate implicit AD::Response splatting and Array conversion --- actionpack/CHANGELOG.md | 13 +++++++++++++ actionpack/lib/action_dispatch/http/response.rb | 15 +++++++++++++-- actionpack/test/dispatch/response_test.rb | 20 +++++++++++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index e250450a76..de9722c392 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,16 @@ +* Deprecate implicit Array conversion for Response objects. It was added + (using `#to_ary`) so we could conveniently use implicit splatting: + + status, headers, body = response + + But it also means `response + response` works and `[response].flatten` + cascades down to the Rack body. Nonsense behavior. Instead, rely on + explicit conversion and splatting with `#to_a`: + + status, header, body = *response + + *Jeremy Kemper* + * Don't rescue `IPAddr::InvalidAddressError`. `IPAddr::InvalidAddressError` does not exist in Ruby 1.9.3 diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 2fab6be1a5..a58e904c11 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/module/attribute_accessors' +require 'active_support/deprecation' require 'action_dispatch/http/filter_redirect' require 'monitor' @@ -274,12 +275,22 @@ module ActionDispatch # :nodoc: end # Turns the Response into a Rack-compatible array of the status, headers, - # and body. + # and body. Allows explict splatting: + # + # status, headers, body = *response def to_a rack_response @status, @header.to_hash end alias prepare! to_a - alias to_ary to_a + + # Be super clear that a response object is not an Array. Defining this + # would make implicit splatting work, but it also makes adding responses + # as arrays work, and "flattening" responses, cascading to the rack body! + # Not sensible behavior. + def to_ary + ActiveSupport::Deprecation.warn 'ActionDispatch::Response#to_ary no longer performs implicit conversion to an Array. Please use response.to_a instead, or a splat like `status, headers, body = *response`' + to_a + end # Returns the response cookies, converted to a Hash of (name => value) pairs # diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 187b9a2420..af188191e3 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -220,9 +220,9 @@ class ResponseTest < ActiveSupport::TestCase assert @response.respond_to?(:method_missing, true) end - test "can be destructured into status, headers and an enumerable body" do + test "can be explicitly destructured into status, headers and an enumerable body" do response = ActionDispatch::Response.new(404, { 'Content-Type' => 'text/plain' }, ['Not Found']) - status, headers, body = response + status, headers, body = *response assert_equal 404, status assert_equal({ 'Content-Type' => 'text/plain' }, headers) @@ -231,12 +231,26 @@ class ResponseTest < ActiveSupport::TestCase test "[response].flatten does not recurse infinitely" do Timeout.timeout(1) do # use a timeout to prevent it stalling indefinitely - status, headers, body = [@response].flatten + status, headers, body = assert_deprecated { [@response].flatten } assert_equal @response.status, status assert_equal @response.headers, headers assert_equal @response.body, body.each.to_a.join end end + + test "implicit destructuring and Array conversion is deprecated" do + response = ActionDispatch::Response.new(404, { 'Content-Type' => 'text/plain' }, ['Not Found']) + + assert_deprecated do + status, headers, body = response + + assert_equal 404, status + assert_equal({ 'Content-Type' => 'text/plain' }, headers) + assert_equal ['Not Found'], body.each.to_a + end + + assert_deprecated { response.to_ary } + end end class ResponseIntegrationTest < ActionDispatch::IntegrationTest -- cgit v1.2.3 From 66f8997671c41278a4045ca6c3e3a19c8175a7ed Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Wed, 3 Sep 2014 11:16:37 -0400 Subject: Add support for Rack::ContentLength middelware --- actionpack/lib/action_dispatch/http/response.rb | 4 ++++ actionpack/test/dispatch/response_test.rb | 14 ++++++++++++++ 2 files changed, 18 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index a58e904c11..c5e18048da 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -380,6 +380,10 @@ module ActionDispatch # :nodoc: def to_path @response.stream.to_path end + + def to_ary + nil + end end def rack_response(status, header) diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index af188191e3..48342e252a 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -1,4 +1,6 @@ require 'abstract_unit' +require 'timeout' +require 'rack/content_length' class ResponseTest < ActiveSupport::TestCase def setup @@ -238,6 +240,18 @@ class ResponseTest < ActiveSupport::TestCase end end + test "compatibility with Rack::ContentLength" do + @response.body = 'Hello' + app = lambda { |env| @response.to_a } + env = Rack::MockRequest.env_for("/") + + status, headers, body = app.call(env) + assert_nil headers['Content-Length'] + + status, headers, body = Rack::ContentLength.new(app).call(env) + assert_equal '5', headers['Content-Length'] + end + test "implicit destructuring and Array conversion is deprecated" do response = ActionDispatch::Response.new(404, { 'Content-Type' => 'text/plain' }, ['Not Found']) -- cgit v1.2.3 From 90c06717bc675b602f281a29286871236f21d13e Mon Sep 17 00:00:00 2001 From: Thiago Pradi Date: Sun, 7 Sep 2014 22:51:14 -0300 Subject: Removing unused fake models --- actionpack/test/lib/controller/fake_models.rb | 45 --------------------------- 1 file changed, 45 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb index b8b51d86c2..ce9522d12a 100644 --- a/actionpack/test/lib/controller/fake_models.rb +++ b/actionpack/test/lib/controller/fake_models.rb @@ -28,30 +28,6 @@ class Customer < Struct.new(:name, :id) end end -class ValidatedCustomer < Customer - def errors - if name =~ /Sikachu/i - [] - else - [{:name => "is invalid"}] - end - end -end - -module Quiz - class Question < Struct.new(:name, :id) - extend ActiveModel::Naming - include ActiveModel::Conversion - - def persisted? - id.present? - end - end - - class Store < Question - end -end - class Post < Struct.new(:title, :author_name, :body, :secret, :persisted, :written_on, :cost) extend ActiveModel::Naming include ActiveModel::Conversion @@ -95,24 +71,3 @@ class Comment attr_accessor :body end - -module Blog - def self.use_relative_model_naming? - true - end - - class Post < Struct.new(:title, :id) - extend ActiveModel::Naming - include ActiveModel::Conversion - - def persisted? - id.present? - end - end -end - -class RenderJsonTestException < Exception - def as_json(options = nil) - { :error => self.class.name, :message => self.to_s } - end -end -- cgit v1.2.3 From 2b41343c34bcbe809537590152506690b84832df Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Mon, 8 Sep 2014 05:32:16 -0700 Subject: Default to sorting user's test cases for now Goals: 1. Default to :random for newly generated applications 2. Default to :sorted for existing applications with a warning 3. Only show the warning once 4. Only show the warning if the app actually uses AS::TestCase Fixes #16769 --- actionpack/test/abstract_unit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 799c17119d..69312e4c22 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -516,4 +516,4 @@ end # FIXME: we have tests that depend on run order, we should fix that and # remove this method call. require 'active_support/test_case' -ActiveSupport::TestCase.my_tests_are_order_dependent! +ActiveSupport::TestCase.test_order = :sorted -- cgit v1.2.3 From ceb9ca2193180c5d825bc2c57a2823ff9b164dbb Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Tue, 9 Sep 2014 10:47:40 +0530 Subject: Remove extra 'has been' from the deprecation message - [ci skip] --- actionpack/lib/action_dispatch/testing/assertions/tag.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/tag.rb b/actionpack/lib/action_dispatch/testing/assertions/tag.rb index d5348d80e1..5c2905d1ac 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/tag.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/tag.rb @@ -1,3 +1,3 @@ require 'active_support/deprecation' -ActiveSupport::Deprecation.warn("ActionDispatch::Assertions::TagAssertions has been has been extracted to the rails-dom-testing gem.") +ActiveSupport::Deprecation.warn("ActionDispatch::Assertions::TagAssertions has been extracted to the rails-dom-testing gem.") -- cgit v1.2.3 From 29a10173e235ea495634de39f3dadd2da2e28fd4 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Tue, 9 Sep 2014 11:07:30 +0530 Subject: Remove extra 'has been' from deprecation warning about asserting selectors [ci skip] --- actionpack/lib/action_dispatch/testing/assertions/selector.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 19eca60f70..7361e6c44b 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -1,3 +1,3 @@ require 'active_support/deprecation' -ActiveSupport::Deprecation.warn("ActionDispatch::Assertions::SelectorAssertions has been has been extracted to the rails-dom-testing gem.") \ No newline at end of file +ActiveSupport::Deprecation.warn("ActionDispatch::Assertions::SelectorAssertions has been extracted to the rails-dom-testing gem.") -- cgit v1.2.3 From 4f6f43338f7e4d3a3fe5ad86d024007ee95a7389 Mon Sep 17 00:00:00 2001 From: suginoy Date: Wed, 10 Sep 2014 11:28:17 +0900 Subject: [ci skip]Correct variables in the sample code --- actionpack/lib/action_dispatch/http/mime_type.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index 9450be838c..b9d5009683 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -45,8 +45,8 @@ module Mime # # respond_to do |format| # format.html - # format.ics { render text: post.to_ics, mime_type: Mime::Type["text/calendar"] } - # format.xml { render xml: @people } + # format.ics { render text: @post.to_ics, mime_type: Mime::Type["text/calendar"] } + # format.xml { render xml: @post } # end # end # end -- cgit v1.2.3