Skip to content
Browse files

Improved test coverage for integration test's api

  • Loading branch information...
1 parent bec4b69 commit 40557e17dda0525d5d26c09b3279b83695df3f4d @josh josh committed Jun 16, 2008
Showing with 88 additions and 5 deletions.
  1. +88 −5 actionpack/test/controller/integration_test.rb
View
93 actionpack/test/controller/integration_test.rb
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'action_controller/integration'
+require 'action_controller/routing'
uses_mocha 'integration' do
@@ -12,12 +13,12 @@ def stub_integration_session(session)
class SessionTest < Test::Unit::TestCase
include IntegrationSessionStubbing
-
+
def setup
@session = ActionController::Integration::Session.new
stub_integration_session(@session)
end
-
+
def test_https_bang_works_and_sets_truth_by_default
assert !@session.https?
@session.https!
@@ -196,7 +197,7 @@ def test_xml_http_request_head
@session.expects(:process).with(:head,path,params,headers_after_xhr)
@session.xml_http_request(:head,path,params,headers)
end
-
+
def test_xml_http_request_override_accept
path = "/index"; params = "blah"; headers = {:location => 'blah', "Accept" => "application/xml"}
headers_after_xhr = headers.merge(
@@ -227,7 +228,6 @@ def test_opens_new_session
assert_equal ::ActionController::Integration::Session, session2.class
assert_not_equal session1, session2
end
-
end
# Tests that integration tests don't call Controller test methods for processing.
@@ -246,7 +246,90 @@ def test_integration_methods_called
assert_nothing_raised("'#{verb}' should use integration test methods") { send!(verb, '/') }
end
end
+end
+
+class IntegrationProcessTest < ActionController::IntegrationTest
+ class IntegrationController < ActionController::Base
+ session :off
+
+ def get
+ render :text => "OK", :status => 200
+ end
+
+ def post
+ render :text => "Created", :status => 201
+ end
+
+ def cookie_monster
+ cookies["cookie_1"] = nil
+ cookies["cookie_3"] = "chocolate"
+ render :text => "Gone", :status => 410
+ end
+ end
+ def test_get
+ with_test_route_set do
+ get '/get'
+ assert_equal 200, status
+ assert_equal "OK", status_message
+ assert_equal "200 OK", response.headers["Status"]
+ assert_equal ["200 OK"], headers["status"]
+ assert_equal [], response.headers["cookie"]
+ assert_equal [], headers["cookie"]
+ assert_equal({}, cookies)
+ assert_equal "OK", response.body
+ assert_kind_of HTML::Document, html_document
+ assert_equal 1, request_count
+ end
+ end
+
+ def test_post
+ with_test_route_set do
+ post '/post'
+ assert_equal 201, status
+ assert_equal "Created", status_message
+ assert_equal "201 Created", response.headers["Status"]
+ assert_equal ["201 Created"], headers["status"]
+ assert_equal [], response.headers["cookie"]
+ assert_equal [], headers["cookie"]
+ assert_equal({}, cookies)
+ assert_equal "Created", response.body
+ assert_kind_of HTML::Document, html_document
+ assert_equal 1, request_count
+ end
+ end
+
+ def test_cookie_monster
+ with_test_route_set do
+ self.cookies['cookie_1'] = "sugar"
+ self.cookies['cookie_2'] = "oatmeal"
+ get '/cookie_monster'
+ assert_equal 410, status
+ assert_equal "Gone", status_message
+ assert_equal "410 Gone", response.headers["Status"]
+ assert_equal ["410 Gone"], headers["status"]
+ assert_equal nil, response.headers["Set-Cookie"]
+ assert_equal ["cookie_1=; path=/", "cookie_3=chocolate; path=/"], headers['set-cookie']
+ assert_equal [[], ["chocolate"]], response.headers["cookie"]
+ assert_equal [], headers["cookie"]
+ assert_equal({"cookie_1"=>"", "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies)
+ assert_equal "Gone", response.body
+ end
+ end
+
+ private
+ def with_test_route_set
+ with_routing do |set|
+ set.draw do |map|
+ map.with_options :controller => "IntegrationProcessTest::Integration" do |c|
+ c.connect '/get', :action => "get"
+ c.connect '/post', :action => "post"
+ c.connect '/cookie_monster', :action => "cookie_monster"
+ end
+ end
+ yield
+ end
+ end
end
-end # uses_mocha
+end

0 comments on commit 40557e1

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