1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Modernize flash tests

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3583 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2006-02-12 16:29:21 +00:00
parent 431edf7793
commit 93cba1207a

View file

@ -41,60 +41,45 @@ class FlashTest < Test::Unit::TestCase
end end
def setup def setup
initialize_request_and_response @request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@controller = TestController.new
end end
def test_flash def test_flash
@request.action = "set_flash" get :set_flash
response = process_request
@request.action = "use_flash" get :use_flash
first_response = process_request assert_equal "hello", @response.template.assigns["flash_copy"]["that"]
assert_equal "hello", first_response.template.assigns["flash_copy"]["that"] assert_equal "hello", @response.template.assigns["flashy"]
assert_equal "hello", first_response.template.assigns["flashy"]
second_response = process_request get :use_flash
assert_nil second_response.template.assigns["flash_copy"]["that"], "On second flash" assert_nil @response.template.assigns["flash_copy"]["that"], "On second flash"
end end
def test_keep_flash def test_keep_flash
@request.action = "set_flash" get :set_flash
response = process_request
@request.action = "use_flash_and_keep_it" get :use_flash_and_keep_it
first_response = process_request assert_equal "hello", @response.template.assigns["flash_copy"]["that"]
assert_equal "hello", first_response.template.assigns["flash_copy"]["that"] assert_equal "hello", @response.template.assigns["flashy"]
assert_equal "hello", first_response.template.assigns["flashy"]
@request.action = "use_flash" get :use_flash
second_response = process_request assert_equal "hello", @response.template.assigns["flash_copy"]["that"], "On second flash"
assert_equal "hello", second_response.template.assigns["flash_copy"]["that"], "On second flash"
third_response = process_request get :use_flash
assert_nil third_response.template.assigns["flash_copy"]["that"], "On third flash" assert_nil @response.template.assigns["flash_copy"]["that"], "On third flash"
end end
def test_flash_now def test_flash_now
@request.action = "set_flash_now" get :set_flash_now
response = process_request assert_equal "hello", @response.template.assigns["flash_copy"]["that"]
assert_equal "hello", response.template.assigns["flash_copy"]["that"] assert_equal "bar" , @response.template.assigns["flash_copy"]["foo"]
assert_equal "bar" , response.template.assigns["flash_copy"]["foo"] assert_equal "hello", @response.template.assigns["flashy"]
assert_equal "hello", response.template.assigns["flashy"]
@request.action = "attempt_to_use_flash_now" get :attempt_to_use_flash_now
first_response = process_request assert_nil @response.template.assigns["flash_copy"]["that"]
assert_nil first_response.template.assigns["flash_copy"]["that"] assert_nil @response.template.assigns["flash_copy"]["foo"]
assert_nil first_response.template.assigns["flash_copy"]["foo"] assert_nil @response.template.assigns["flashy"]
assert_nil first_response.template.assigns["flashy"]
end end
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