Skip to content

Commit

Permalink
Remove deprecated ActionDispatch::Response#to_ary
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Jan 4, 2015
1 parent 7676659 commit 4b19d5b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Remove deprecated `ActionDispatch::Response#to_ary`.

*Rafael Mendonça França*

* Remove deprecated `ActionDispatch::Request#deep_munge`.

*Rafael Mendonça França*
Expand Down
15 changes: 0 additions & 15 deletions actionpack/lib/action_dispatch/http/response.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/string/filters'
require 'active_support/deprecation'
require 'action_dispatch/http/filter_redirect'
require 'monitor'

Expand Down Expand Up @@ -284,20 +283,6 @@ def to_a
end
alias prepare! 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(<<-MSG.squish)
`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`.
MSG

to_a
end

# Returns the response cookies, converted to a Hash of (name => value) pairs
#
# assert_equal 'AuthorOfNewPage', r.cookies['author']
Expand Down
18 changes: 2 additions & 16 deletions actionpack/test/dispatch/response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ def test_response_body_encoding
assert_equal ['Not Found'], body.each.to_a
end

test "[response].flatten does not recurse infinitely" do
test "[response.to_a].flatten does not recurse infinitely" do
Timeout.timeout(1) do # use a timeout to prevent it stalling indefinitely
status, headers, body = assert_deprecated { [@response].flatten }
status, headers, body = [@response.to_a].flatten
assert_equal @response.status, status
assert_equal @response.headers, headers
assert_equal @response.body, body.each.to_a.join
Expand All @@ -251,20 +251,6 @@ def test_response_body_encoding
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'])

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
Expand Down

0 comments on commit 4b19d5b

Please sign in to comment.