1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/test/controller/flash_test.rb
David Heinemeier Hansson db045dbbf6 Initial
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2004-11-24 01:04:44 +00:00

69 lines
No EOL
1.8 KiB
Ruby

require File.dirname(__FILE__) + '/../abstract_unit'
class FlashTest < Test::Unit::TestCase
class TestController < ActionController::Base
def set_flash
flash["that"] = "hello"
render_text "hello"
end
def use_flash
@flashy = flash["that"]
render_text "hello"
end
def use_flash_and_keep_it
@flashy = flash["that"]
keep_flash
render_text "hello"
end
def rescue_action(e)
raise unless ActionController::MissingTemplate === e
end
end
def setup
initialize_request_and_response
end
def test_flash
@request.action = "set_flash"
response = process_request
@request.action = "use_flash"
first_response = process_request
assert_equal "hello", first_response.template.assigns["flash"]["that"]
assert_equal "hello", first_response.template.assigns["flashy"]
second_response = process_request
assert_nil second_response.template.assigns["flash"]["that"], "On second flash"
end
def test_keep_flash
@request.action = "set_flash"
response = process_request
@request.action = "use_flash_and_keep_it"
first_response = process_request
assert_equal "hello", first_response.template.assigns["flash"]["that"]
assert_equal "hello", first_response.template.assigns["flashy"]
@request.action = "use_flash"
second_response = process_request
assert_equal "hello", second_response.template.assigns["flash"]["that"], "On second flash"
third_response = process_request
assert_nil third_response.template.assigns["flash"]["that"], "On third flash"
end
private
def initialize_request_and_response
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def process_request
TestController.process(@request, @response)
end
end