Skip to content

Instantly share code, notes, and snippets.

@javan
Created September 4, 2014 13:48
Show Gist options
  • Save javan/934aa107fcc08f72fce8 to your computer and use it in GitHub Desktop.
Save javan/934aa107fcc08f72fce8 to your computer and use it in GitHub Desktop.
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 4379255..58bdf2a 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -371,7 +371,7 @@ module ActionDispatch # :nodoc:
end
def to_ary
- nil
+ @response.body_parts
end
end
actionpack (comply_with_rack_content_length_middleware) $ ruby test/dispatch/response_test.rb
Run options: --seed 60449
# Running:
....E......................
Finished in 0.250497s, 107.7857 runs/s, 291.4207 assertions/s.
1) Error:
ResponseTest#test_[response].flatten_does_not_recurse_infinitely:
NoMethodError: undefined method `each' for nil:NilClass
test/dispatch/response_test.rb:239:in `block (2 levels) in <class:ResponseTest>'
/usr/local/var/rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/timeout.rb:66:in `timeout'
test/dispatch/response_test.rb:235:in `block in <class:ResponseTest>'
27 runs, 73 assertions, 0 failures, 1 errors, 0 skips
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 4379255..58bdf2a 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -371,7 +371,7 @@ module ActionDispatch # :nodoc:
end
def to_ary
- nil
+ @response.body_parts
end
end
diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb
index 3a51a9d..9609264 100644
--- a/actionpack/test/dispatch/response_test.rb
+++ b/actionpack/test/dispatch/response_test.rb
@@ -233,6 +233,7 @@ class ResponseTest < ActiveSupport::TestCase
test "[response].flatten does not recurse infinitely" do
Timeout.timeout(1) do # use a timeout to prevent it stalling indefinitely
+ @response.body = 'Hello'
status, headers, body = [@response].flatten
assert_equal @response.status, status
assert_equal @response.headers, headers
actionpack (comply_with_rack_content_length_middleware) $ ruby test/dispatch/response_test.rb
Run options: --seed 53010
# Running:
.....E.....................
Finished in 0.250172s, 107.9257 runs/s, 291.7992 assertions/s.
1) Error:
ResponseTest#test_[response].flatten_does_not_recurse_infinitely:
NoMethodError: undefined method `each' for "Hello":String
test/dispatch/response_test.rb:240:in `block (2 levels) in <class:ResponseTest>'
/usr/local/var/rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/timeout.rb:66:in `timeout'
test/dispatch/response_test.rb:235:in `block in <class:ResponseTest>'
27 runs, 73 assertions, 0 failures, 1 errors, 0 skips
diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb
index 3a51a9d..9baa83c 100644
--- a/actionpack/test/dispatch/response_test.rb
+++ b/actionpack/test/dispatch/response_test.rb
@@ -237,6 +237,7 @@ class ResponseTest < ActiveSupport::TestCase
assert_equal @response.status, status
assert_equal @response.headers, headers
assert_equal @response.body, body.each.to_a.join
+ assert_kind_of ActionDispatch::Response::RackBody, body
end
end
actionpack (comply_with_rack_content_length_middleware) $ ruby test/dispatch/response_test.rb
Run options: --seed 28273
# Running:
...........................
Finished in 0.248611s, 108.6034 runs/s, 301.6761 assertions/s.
27 runs, 75 assertions, 0 failures, 0 errors, 0 skips
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 4379255..bbf763a 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -371,7 +371,7 @@ module ActionDispatch # :nodoc:
end
def to_ary
- nil
+ [@response.stream]
end
end
actionpack (comply_with_rack_content_length_middleware) $ ruby test/dispatch/response_test.rb
Run options: --seed 60802
# Running:
...........................
Finished in 0.243904s, 110.6993 runs/s, 303.3981 assertions/s.
27 runs, 74 assertions, 0 failures, 0 errors, 0 skips
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 4379255..bbf763a 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -371,7 +371,7 @@ module ActionDispatch # :nodoc:
end
def to_ary
- nil
+ [@response.stream]
end
end
diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb
index 3a51a9d..9baa83c 100644
--- a/actionpack/test/dispatch/response_test.rb
+++ b/actionpack/test/dispatch/response_test.rb
@@ -237,6 +237,7 @@ class ResponseTest < ActiveSupport::TestCase
assert_equal @response.status, status
assert_equal @response.headers, headers
assert_equal @response.body, body.each.to_a.join
+ assert_kind_of ActionDispatch::Response::RackBody, body
end
end
actionpack (comply_with_rack_content_length_middleware) $ ruby test/dispatch/response_test.rb
Run options: --seed 52581
# Running:
...F.......................
Finished in 0.244162s, 110.5823 runs/s, 307.1731 assertions/s.
1) Failure:
ResponseTest#test_[response].flatten_does_not_recurse_infinitely [test/dispatch/response_test.rb:240]:
Expected #<ActionDispatch::Response::Buffer:0x007fdf9b0b1058 @response=#<ActionDispatch::Response:0x007fdf9b0b1170 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x007fdf9b0b10a8>, @stream=#<ActionDispatch::Response::Buffer:0x007fdf9b0b1058 ...>, @header={"Content-Type"=>"text/html; charset=utf-8"}, @status=200, @sending_file=false, @blank=false, @cv=#<MonitorMixin::ConditionVariable:0x007fdf9b0b1030 @monitor=#<ActionDispatch::Response:0x007fdf9b0b1170 ...>, @cond=#<ConditionVariable:0x007fdf9b0b0c48 @waiters={}, @waiters_mutex=#<Mutex:0x007fdf9b0bbdc8>>>, @committed=false, @sending=true, @sent=true, @content_type=#<Mime::Type:0x007fdf9d829c48 @synonyms=["application/xhtml+xml"], @symbol=:html, @string="text/html">, @charset="utf-8", @cache_control={}, @etag=nil>, @buf=[], @closed=false> to be a kind of ActionDispatch::Response::RackBody, not ActionDispatch::Response::Buffer.
27 runs, 75 assertions, 1 failures, 0 errors, 0 skips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment