Skip to content
This repository
Browse code

Create a new file for response tests

  • Loading branch information...
commit dbbe2e74ff5b6363da74fe63045b043c24041b1a 1 parent d0ace15
Joshua Peek authored April 26, 2009
90  actionpack/test/dispatch/rack_test.rb
@@ -201,93 +201,3 @@ class RackRequestNeedsRewoundTest < BaseRackTest
201 201
     assert_equal 0, request.body.pos
202 202
   end
203 203
 end
204  
-
205  
-class RackResponseTest < BaseRackTest
206  
-  def setup
207  
-    super
208  
-    @response = ActionDispatch::Response.new
209  
-  end
210  
-
211  
-  test "simple output" do
212  
-    @response.body = "Hello, World!"
213  
-    @response.prepare!
214  
-
215  
-    status, headers, body = @response.to_a
216  
-    assert_equal 200, status
217  
-    assert_equal({
218  
-      "Content-Type" => "text/html; charset=utf-8",
219  
-      "Cache-Control" => "private, max-age=0, must-revalidate",
220  
-      "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"',
221  
-      "Set-Cookie" => "",
222  
-      "Content-Length" => "13"
223  
-    }, headers)
224  
-
225  
-    parts = []
226  
-    body.each { |part| parts << part }
227  
-    assert_equal ["Hello, World!"], parts
228  
-  end
229  
-
230  
-  def test_utf8_output
231  
-    @response.body = [1090, 1077, 1089, 1090].pack("U*")
232  
-    @response.prepare!
233  
-
234  
-    status, headers, body = @response.to_a
235  
-    assert_equal 200, status
236  
-    assert_equal({
237  
-      "Content-Type" => "text/html; charset=utf-8",
238  
-      "Cache-Control" => "private, max-age=0, must-revalidate",
239  
-      "ETag" => '"ebb5e89e8a94e9dd22abf5d915d112b2"',
240  
-      "Set-Cookie" => "",
241  
-      "Content-Length" => "8"
242  
-    }, headers)
243  
-  end
244  
-
245  
-  def test_streaming_block
246  
-    @response.body = Proc.new do |response, output|
247  
-      5.times { |n| output.write(n) }
248  
-    end
249  
-    @response.prepare!
250  
-
251  
-    status, headers, body = @response.to_a
252  
-    assert_equal 200, status
253  
-    assert_equal({
254  
-      "Content-Type" => "text/html; charset=utf-8",
255  
-      "Cache-Control" => "no-cache",
256  
-      "Set-Cookie" => ""
257  
-    }, headers)
258  
-
259  
-    parts = []
260  
-    body.each { |part| parts << part.to_s }
261  
-    assert_equal ["0", "1", "2", "3", "4"], parts
262  
-  end
263  
-end
264  
-
265  
-class RackResponseHeadersTest < BaseRackTest
266  
-  def setup
267  
-    super
268  
-    @response = ActionDispatch::Response.new
269  
-    @response.status = "200 OK"
270  
-  end
271  
-
272  
-  test "content type" do
273  
-    [204, 304].each do |c|
274  
-      @response.status = c.to_s
275  
-      assert !response_headers.has_key?("Content-Type"), "#{c} should not have Content-Type header"
276  
-    end
277  
-
278  
-    [200, 302, 404, 500].each do |c|
279  
-      @response.status = c.to_s
280  
-      assert response_headers.has_key?("Content-Type"), "#{c} did not have Content-Type header"
281  
-    end
282  
-  end
283  
-
284  
-  test "status" do
285  
-    assert !response_headers.has_key?('Status')
286  
-  end
287  
-
288  
-  private
289  
-    def response_headers
290  
-      @response.prepare!
291  
-      @response.to_a[1]
292  
-    end
293  
-end
83  actionpack/test/dispatch/response_test.rb
... ...
@@ -0,0 +1,83 @@
  1
+require 'abstract_unit'
  2
+
  3
+class ResponseTest < ActiveSupport::TestCase
  4
+  def setup
  5
+    @response = ActionDispatch::Response.new
  6
+  end
  7
+
  8
+  test "simple output" do
  9
+    @response.body = "Hello, World!"
  10
+    @response.prepare!
  11
+
  12
+    status, headers, body = @response.to_a
  13
+    assert_equal 200, status
  14
+    assert_equal({
  15
+      "Content-Type" => "text/html; charset=utf-8",
  16
+      "Cache-Control" => "private, max-age=0, must-revalidate",
  17
+      "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"',
  18
+      "Set-Cookie" => "",
  19
+      "Content-Length" => "13"
  20
+    }, headers)
  21
+
  22
+    parts = []
  23
+    body.each { |part| parts << part }
  24
+    assert_equal ["Hello, World!"], parts
  25
+  end
  26
+
  27
+  test "utf8 output" do
  28
+    @response.body = [1090, 1077, 1089, 1090].pack("U*")
  29
+    @response.prepare!
  30
+
  31
+    status, headers, body = @response.to_a
  32
+    assert_equal 200, status
  33
+    assert_equal({
  34
+      "Content-Type" => "text/html; charset=utf-8",
  35
+      "Cache-Control" => "private, max-age=0, must-revalidate",
  36
+      "ETag" => '"ebb5e89e8a94e9dd22abf5d915d112b2"',
  37
+      "Set-Cookie" => "",
  38
+      "Content-Length" => "8"
  39
+    }, headers)
  40
+  end
  41
+
  42
+  test "streaming block" do
  43
+    @response.body = Proc.new do |response, output|
  44
+      5.times { |n| output.write(n) }
  45
+    end
  46
+    @response.prepare!
  47
+
  48
+    status, headers, body = @response.to_a
  49
+    assert_equal 200, status
  50
+    assert_equal({
  51
+      "Content-Type" => "text/html; charset=utf-8",
  52
+      "Cache-Control" => "no-cache",
  53
+      "Set-Cookie" => ""
  54
+    }, headers)
  55
+
  56
+    parts = []
  57
+    body.each { |part| parts << part.to_s }
  58
+    assert_equal ["0", "1", "2", "3", "4"], parts
  59
+  end
  60
+
  61
+  test "content type" do
  62
+    [204, 304].each do |c|
  63
+      @response.status = c.to_s
  64
+      @response.prepare!
  65
+      status, headers, body = @response.to_a
  66
+      assert !headers.has_key?("Content-Type"), "#{c} should not have Content-Type header"
  67
+    end
  68
+
  69
+    [200, 302, 404, 500].each do |c|
  70
+      @response.status = c.to_s
  71
+      @response.prepare!
  72
+      status, headers, body = @response.to_a
  73
+      assert headers.has_key?("Content-Type"), "#{c} did not have Content-Type header"
  74
+    end
  75
+  end
  76
+
  77
+  test "does not include Status header" do
  78
+    @response.status = "200 OK"
  79
+    @response.prepare!
  80
+    status, headers, body = @response.to_a
  81
+    assert !headers.has_key?('Status')
  82
+  end
  83
+end

0 notes on commit dbbe2e7

Please sign in to comment.
Something went wrong with that request. Please try again.