2004-11-24 01:04:44 +00:00
|
|
|
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
|
|
|
|
|
2005-03-20 19:12:53 +00:00
|
|
|
def set_flash_now
|
|
|
|
flash.now["that"] = "hello"
|
|
|
|
@flash_copy = {}.update flash
|
|
|
|
render_text "hello"
|
|
|
|
end
|
|
|
|
|
|
|
|
def attempt_to_use_flash_now
|
|
|
|
@flash_copy = {}.update flash
|
|
|
|
@flashy = flash["that"]
|
|
|
|
render_text "hello"
|
|
|
|
end
|
|
|
|
|
2004-11-24 01:04:44 +00:00
|
|
|
def use_flash
|
2005-03-20 19:12:53 +00:00
|
|
|
@flash_copy = {}.update flash
|
2004-11-24 01:04:44 +00:00
|
|
|
@flashy = flash["that"]
|
|
|
|
render_text "hello"
|
|
|
|
end
|
|
|
|
|
|
|
|
def use_flash_and_keep_it
|
2005-03-20 19:12:53 +00:00
|
|
|
@flash_copy = {}.update flash
|
2004-11-24 01:04:44 +00:00
|
|
|
@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
|
2005-03-20 19:12:53 +00:00
|
|
|
assert_equal "hello", first_response.template.assigns["flash_copy"]["that"]
|
2004-11-24 01:04:44 +00:00
|
|
|
assert_equal "hello", first_response.template.assigns["flashy"]
|
|
|
|
|
|
|
|
second_response = process_request
|
2005-03-20 19:12:53 +00:00
|
|
|
assert_nil second_response.template.assigns["flash_copy"]["that"], "On second flash"
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_keep_flash
|
|
|
|
@request.action = "set_flash"
|
|
|
|
response = process_request
|
|
|
|
|
|
|
|
@request.action = "use_flash_and_keep_it"
|
|
|
|
first_response = process_request
|
2005-03-20 19:12:53 +00:00
|
|
|
assert_equal "hello", first_response.template.assigns["flash_copy"]["that"]
|
2004-11-24 01:04:44 +00:00
|
|
|
assert_equal "hello", first_response.template.assigns["flashy"]
|
|
|
|
|
|
|
|
@request.action = "use_flash"
|
|
|
|
second_response = process_request
|
2005-03-20 19:12:53 +00:00
|
|
|
assert_equal "hello", second_response.template.assigns["flash_copy"]["that"], "On second flash"
|
2004-11-24 01:04:44 +00:00
|
|
|
|
|
|
|
third_response = process_request
|
2005-03-20 19:12:53 +00:00
|
|
|
assert_nil third_response.template.assigns["flash_copy"]["that"], "On third flash"
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
|
|
|
|
2005-03-20 19:12:53 +00:00
|
|
|
def test_flash_now
|
|
|
|
@request.action = "set_flash_now"
|
|
|
|
response = process_request
|
|
|
|
assert_equal "hello", response.template.assigns["flash_copy"]["that"]
|
|
|
|
|
|
|
|
@request.action = "attempt_to_use_flash_now"
|
|
|
|
first_response = process_request
|
|
|
|
assert_nil first_response.template.assigns["flash_copy"]["that"]
|
|
|
|
assert_nil first_response.template.assigns["flashy"]
|
|
|
|
end
|
|
|
|
|
2004-11-24 01:04:44 +00:00
|
|
|
private
|
|
|
|
def initialize_request_and_response
|
|
|
|
@request = ActionController::TestRequest.new
|
|
|
|
@response = ActionController::TestResponse.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def process_request
|
|
|
|
TestController.process(@request, @response)
|
|
|
|
end
|
|
|
|
end
|