Skip to content

Commit

Permalink
Improved test coverage for integration test's api
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Jun 18, 2008
1 parent bec4b69 commit 40557e1
Showing 1 changed file with 88 additions and 5 deletions.
93 changes: 88 additions & 5 deletions 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

Expand All @@ -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!
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand All @@ -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.